The SWORD Project  1.9.0.svnversion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
osisosis.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  *
3  * osisosis.cpp - internal OSIS to public OSIS filter
4  *
5  * $Id: osisosis.cpp 3808 2020-10-02 13:23:34Z scribe $
6  *
7  * Copyright 2004-2013 CrossWire Bible Society (http://www.crosswire.org)
8  * CrossWire Bible Society
9  * P. O. Box 2528
10  * Tempe, AZ 85280-2528
11  *
12  * This program is free software; you can redistribute it and/or modify it
13  * under the terms of the GNU General Public License as published by the
14  * Free Software Foundation version 2.
15  *
16  * This program is distributed in the hope that it will be useful, but
17  * WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * General Public License for more details.
20  *
21  */
22 
23 #include <stdlib.h>
24 #include <osisosis.h>
25 #include <utilxml.h>
26 #include <versekey.h>
27 #include <swmodule.h>
28 
30 
31 
33  osisQToTick = ((!module->getConfigEntry("OSISqToTick")) || (strcmp(module->getConfigEntry("OSISqToTick"), "false")));
34 }
35 
36 
38  setTokenStart("<");
39  setTokenEnd(">");
40 
41  setEscapeStart("&");
42  setEscapeEnd(";");
43 
46 
47  addAllowedEscapeString("quot");
48  addAllowedEscapeString("apos");
52 
54 }
55 
56 
57 char OSISOSIS::processText(SWBuf &text, const SWKey *key, const SWModule *module) {
58  char status = SWBasicFilter::processText(text, key, module);
59  const VerseKey *vkey = SWDYNAMIC_CAST(const VerseKey, key);
60  if (vkey) {
61  if (vkey->getVerse()) {
62  VerseKey *tmp = (VerseKey *)vkey->clone();
63  *tmp = *vkey;
64  tmp->setAutoNormalize(false);
65  tmp->setIntros(true);
66 
67  *tmp = MAXVERSE;
68  if (*vkey == *tmp) {
69  tmp->setVerse(0);
70 // sprintf(ref, "\t</div>");
71 // pushString(&to, ref);
72  *tmp = MAXCHAPTER;
73  *tmp = MAXVERSE;
74  if (*vkey == *tmp) {
75  tmp->setChapter(0);
76  tmp->setVerse(0);
77 // sprintf(ref, "\t</div>");
78 // pushString(&to, ref);
79  }
80  }
81  delete tmp;
82  }
83 
84 //
85 // else if (vkey->Chapter()) {
86 // sprintf(ref, "\t<div type=\"chapter\" osisID=\"%s\">", vkey->getOSISRef());
87 // }
88 // else sprintf(ref, "\t<div type=\"book\" osisID=\"%s\">", vkey->getOSISRef());
89 //
90 
91  }
92  return status;
93 }
94 
95 bool OSISOSIS::handleToken(SWBuf &buf, const char *token, BasicFilterUserData *userData) {
96  // manually process if it wasn't a simple substitution
97  if (!substituteToken(buf, token)) {
98  MyUserData *u = (MyUserData *)userData;
99  XMLTag tag(token);
100 
101  if (!tag.isEmpty() && (!tag.isEndTag()))
102  u->startTag = tag;
103 
104  // <w> tag
105  if (!strcmp(tag.getName(), "w")) {
106 
107  // start <w> tag
108  if ((!tag.isEmpty()) && (!tag.isEndTag())) {
109  SWBuf attr = tag.getAttribute("lemma");
110  if (attr.length()) {
111  if (!strncmp(attr.c_str(), "x-Strongs:", 10)) {
112  memcpy(attr.getRawData()+3, "strong", 6);
113  attr << 3;
114  tag.setAttribute("lemma", attr);
115  }
116  }
117  attr = tag.getAttribute("morph");
118  if (attr.length()) {
119  if (!strncmp(attr.c_str(), "x-StrongsMorph:", 15)) {
120  memcpy(attr.getRawData()+3, "strong", 6);
121  attr << 3;
122  tag.setAttribute("lemma", attr);
123  }
124  if (!strncmp(attr.c_str(), "x-Robinson:", 11)) {
125  attr[2] = 'r';
126  attr << 2;
127  tag.setAttribute("lemma", attr);
128  }
129  }
130  tag.setAttribute("wn", 0);
131  tag.setAttribute("savlm", 0);
132  tag.setAttribute("splitID", 0);
133  }
134  buf += tag;
135  }
136 
137  // <note> tag
138  else if (!strcmp(tag.getName(), "note")) {
139  if (!tag.isEndTag()) {
140  SWBuf type = tag.getAttribute("type");
141 
142  bool strongsMarkup = (type == "x-strongsMarkup" || type == "strongsMarkup"); // the latter is deprecated
143  if (strongsMarkup) {
144  tag.setEmpty(false); // handle bug in KJV2003 module where some note open tags were <note ... />
145  }
146 
147  if (!tag.isEmpty()) {
148  tag.setAttribute("swordFootnote", 0);
149 
150  if (!strongsMarkup) {
151  buf += tag;
152  }
153  else u->suspendTextPassThru = true;
154  }
155 
156  if (u->module) {
157  XMLTag tag = token;
158  SWBuf swordFootnote = tag.getAttribute("swordFootnote");
159  SWBuf footnoteBody = u->module->getEntryAttributes()["Footnote"][swordFootnote]["body"];
160  buf.append(u->module->renderText(footnoteBody));
161  }
162  }
163  if (tag.isEndTag()) {
164  if (u->suspendTextPassThru == false)
165  buf+=tag;
166  else u->suspendTextPassThru = false;
167  }
168  }
169 
170  else {
171  return false; // we still didn't handle token
172  }
173  }
174  return true;
175 }
176 
177 
#define SWORD_NAMESPACE_START
Definition: defs.h:39
void setTokenEnd(const char *tokenEnd)
virtual SWKey * clone() const
Definition: versekey.cpp:278
void addAllowedEscapeString(const char *findString)
Definition: swbuf.h:47
unsigned long length() const
Definition: swbuf.h:197
virtual char processText(SWBuf &text, const SWKey *key=0, const SWModule *module=0)
OSISOSIS()
Definition: osisosis.cpp:37
#define MAXVERSE
Definition: versekey.h:43
void setEmpty(bool value)
Definition: utilxml.h:66
const char * setAttribute(const char *attribName, const char *attribValue, int partNum=-1, char partSplit= '|')
Definition: utilxml.cpp:248
virtual const char * getConfigEntry(const char *key) const
Definition: swmodule.cpp:1159
const SWModule * module
Definition: swbasicfilter.h:42
const char * getName() const
Definition: utilxml.h:58
virtual void setChapter(int ichapter)
Definition: versekey.cpp:1603
SWText * module
Definition: osis2mod.cpp:105
Definition: utilxml.h:38
void setTokenCaseSensitive(bool val)
void setEscapeStart(const char *escStart)
SWBuf renderText(const char *buf, int len=-1, bool render=true) const
Definition: swmodule.cpp:1038
bool isEmpty() const
Definition: utilxml.h:60
bool substituteToken(SWBuf &buf, const char *token)
virtual bool handleToken(SWBuf &buf, const char *token, BasicFilterUserData *userData)
Definition: osisosis.cpp:95
void setTokenStart(const char *tokenStart)
virtual void setIntros(bool val)
Definition: versekey.cpp:1663
MyUserData(const SWModule *module, const SWKey *key)
Definition: osisosis.cpp:32
char * getRawData()
Definition: swbuf.h:379
const char * c_str() const
Definition: swbuf.h:158
SWBuf & append(const char *str, long max=-1)
Definition: swbuf.h:274
void setPassThruNumericEscapeString(bool val)
virtual void setVerse(int iverse)
Definition: versekey.cpp:1622
virtual int getVerse() const
Definition: versekey.cpp:1534
#define SWDYNAMIC_CAST(className, object)
Definition: defs.h:47
virtual AttributeTypeList & getEntryAttributes() const
Definition: swmodule.h:817
const char * getAttribute(const char *attribName, int partNum=-1, char partSplit= '|') const
Definition: utilxml.cpp:230
virtual char processText(SWBuf &text, const SWKey *key, const SWModule *module)
Definition: osisosis.cpp:57
void setEscapeStringCaseSensitive(bool val)
bool isEndTag(const char *eID=0) const
Definition: utilxml.cpp:323
void setEscapeEnd(const char *escEnd)
#define SWORD_NAMESPACE_END
Definition: defs.h:40
Definition: swkey.h:77
#define MAXCHAPTER
Definition: versekey.h:44
virtual void setAutoNormalize(bool iautonorm)
Definition: versekey.cpp:1648