The SWORD Project  1.9.0.svnversion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
corediatheke.h File Reference
#include <stdio.h>
#include <iostream>
#include "diathekemgr.h"
#include <localemgr.h>
#include <swlocale.h>
+ Include dependency graph for corediatheke.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define OP_ARABICPOINTS   (1<<14)
 
#define OP_ARSHAPE   (1<<10)
 
#define OP_BIDI   (1<<11)
 
#define OP_CANTILLATION   (1<<4)
 
#define OP_ENUM   (1<<17)
 
#define OP_FOOTNOTES   (1<<1)
 
#define OP_GLOSSES   (1<<15)
 
#define OP_GREEKACCENTS   (1<<6)
 
#define OP_HEADINGS   (1<<2)
 
#define OP_HEBREWPOINTS   (1<<5)
 
#define OP_INTROS   (1<<19)
 
#define OP_LEMMAS   (1<<8)
 
#define OP_MORPH   (1<<3)
 
#define OP_MORPHSEG   (1<<18)
 
#define OP_NONE   0
 
#define OP_REDLETTERWORDS   (1<<13)
 
#define OP_SCRIPREF   (1<<9)
 
#define OP_STRONGS   1
 
#define OP_TRANSLITERATOR   (1<<7)
 
#define OP_VARIANTS   (1<<12)
 
#define OP_XLIT   (1<<16)
 
#define QT_BIBLE   1
 
#define QT_COMM   2
 
#define QT_INFO   6
 
#define QT_LD   3
 
#define QT_SEARCH   4
 
#define QT_SYSTEM   5
 
#define ST_CLUCENE   5
 
#define ST_ENTRYATTRIB   4
 
#define ST_MULTILEMMA   6
 
#define ST_MULTIWORD   3
 
#define ST_NONE   0
 
#define ST_PHRASE   2
 
#define ST_REGEX   1
 

Functions

void doquery (unsigned long maxverses, unsigned char outputformat, unsigned char outputencoding, unsigned long optionfilters, unsigned char searchtype, const char *range, const char *text, const char *locale, const char *ref, ostream *output, const char *script, signed char variants)
 
int hasalpha (char *string)
 

Macro Definition Documentation

#define OP_ARABICPOINTS   (1<<14)

Definition at line 57 of file corediatheke.h.

#define OP_ARSHAPE   (1<<10)

Definition at line 53 of file corediatheke.h.

#define OP_BIDI   (1<<11)

Definition at line 54 of file corediatheke.h.

#define OP_CANTILLATION   (1<<4)

Definition at line 47 of file corediatheke.h.

#define OP_ENUM   (1<<17)

Definition at line 60 of file corediatheke.h.

#define OP_FOOTNOTES   (1<<1)

Definition at line 44 of file corediatheke.h.

#define OP_GLOSSES   (1<<15)

Definition at line 58 of file corediatheke.h.

#define OP_GREEKACCENTS   (1<<6)

Definition at line 49 of file corediatheke.h.

#define OP_HEADINGS   (1<<2)

Definition at line 45 of file corediatheke.h.

#define OP_HEBREWPOINTS   (1<<5)

Definition at line 48 of file corediatheke.h.

#define OP_INTROS   (1<<19)

Definition at line 62 of file corediatheke.h.

#define OP_LEMMAS   (1<<8)

Definition at line 51 of file corediatheke.h.

#define OP_MORPH   (1<<3)

Definition at line 46 of file corediatheke.h.

#define OP_MORPHSEG   (1<<18)

Definition at line 61 of file corediatheke.h.

#define OP_NONE   0

Definition at line 42 of file corediatheke.h.

#define OP_REDLETTERWORDS   (1<<13)

Definition at line 56 of file corediatheke.h.

#define OP_SCRIPREF   (1<<9)

Definition at line 52 of file corediatheke.h.

#define OP_STRONGS   1

Definition at line 43 of file corediatheke.h.

#define OP_TRANSLITERATOR   (1<<7)

Definition at line 50 of file corediatheke.h.

#define OP_VARIANTS   (1<<12)

Definition at line 55 of file corediatheke.h.

#define OP_XLIT   (1<<16)

Definition at line 59 of file corediatheke.h.

#define QT_BIBLE   1

Definition at line 35 of file corediatheke.h.

#define QT_COMM   2

Definition at line 36 of file corediatheke.h.

#define QT_INFO   6

Definition at line 40 of file corediatheke.h.

#define QT_LD   3

Definition at line 37 of file corediatheke.h.

#define QT_SEARCH   4

Definition at line 38 of file corediatheke.h.

#define QT_SYSTEM   5

Definition at line 39 of file corediatheke.h.

#define ST_CLUCENE   5

Definition at line 69 of file corediatheke.h.

#define ST_ENTRYATTRIB   4

Definition at line 68 of file corediatheke.h.

#define ST_MULTILEMMA   6

Definition at line 70 of file corediatheke.h.

#define ST_MULTIWORD   3

Definition at line 67 of file corediatheke.h.

#define ST_NONE   0

Definition at line 64 of file corediatheke.h.

#define ST_PHRASE   2

Definition at line 66 of file corediatheke.h.

#define ST_REGEX   1

Definition at line 65 of file corediatheke.h.

Function Documentation

void doquery ( unsigned long  maxverses,
unsigned char  outputformat,
unsigned char  outputencoding,
unsigned long  optionfilters,
unsigned char  searchtype,
const char *  range,
const char *  text,
const char *  locale,
const char *  ref,
ostream *  output,
const char *  script,
signed char  variants 
)

Definition at line 101 of file corediatheke.cpp.

101  {
102 
103  static DiathekeMgr manager(NULL, NULL, false, outputencoding, outputformat, ((OP_BIDI & optionfilters) == OP_BIDI), ((OP_ARSHAPE & optionfilters) == OP_ARSHAPE));
104 
105  ListKey listkey;
106  const char *DEFAULT_FONT = "Gentium";
107  SWModule *target;
108 
109  const char *font = 0;
110  SWBuf modlanguage;
111  SWBuf modlocale;
112  SWBuf syslanguage;
113  SWBuf syslocale;
114  SWBuf header;
115 
116  char inputformat = 0;
117  char querytype = 0;
118 
119  if (!locale) { locale = "en";
120  }
121 
122 
123  syslocale = SWBuf(locale);
124  syslocale.append(".en");
126  lom->setDefaultLocaleName(syslocale);
127  syslanguage = lom->translate(syslocale, "locales");
128 
129 
130  //deal with queries to "system"
131  if (!::stricmp(text, "system")) {
132  querytype = QT_SYSTEM;
133  systemquery(ref, output);
134  }
135  if (!strnicmp(text, "info", 4)) {
136  querytype = QT_INFO;
137  text = ref;
138  }
139  //otherwise, we have a real book
140  target = manager.getModule(text);
141  if (!target) return;
142 
143  if (target->getLanguage()) {
144  modlocale = target->getLanguage();
146  modlanguage = lm->translate(modlocale.append(".en"), "locales");
147  modlocale -= 3;
148  }
149  else {
150  modlocale = "en";
151  modlanguage = "English";
152  }
153 
154 
155  SWBuf sourceType = target->getConfigEntry("SourceType");
156  if (sourceType == "GBF") inputformat = FMT_GBF;
157  else if (sourceType == "ThML") inputformat = FMT_THML;
158  else if (sourceType == "OSIS") inputformat = FMT_OSIS;
159  else if (sourceType == "TEI") inputformat = FMT_TEI;
160 
161  SWBuf encoding = target->getConfigEntry("Encoding");
162 
163 
164  if (querytype == QT_INFO) {
165  switch (inputformat) {
166  case FMT_THML : *output << "ThML"; break;
167  case FMT_GBF : *output << "GBF" ; break;
168  case FMT_OSIS : *output << "OSIS"; break;
169  case FMT_TEI : *output << "TEI" ; break;
170  default: *output << "Other";
171  }
172  *output << ";";
173  *output << target->getType();
174  *output << ";";
175  return;
176  }
177 
178  if (searchtype) querytype = QT_SEARCH;
179 
180  manager.setGlobalOption("Footnotes", (optionfilters & OP_FOOTNOTES) ? "On": "Off");
181  manager.setGlobalOption("Headings", (optionfilters & OP_HEADINGS) ? "On": "Off");
182  manager.setGlobalOption("Strong's Numbers", (optionfilters & OP_STRONGS) ? "On": "Off");
183  manager.setGlobalOption("Morphological Tags", (optionfilters & OP_MORPH) ? "On": "Off");
184  manager.setGlobalOption("Hebrew Cantillation", (optionfilters & OP_CANTILLATION) ? "On": "Off");
185  manager.setGlobalOption("Hebrew Vowel Points", (optionfilters & OP_HEBREWPOINTS) ? "On": "Off");
186  manager.setGlobalOption("Greek Accents", (optionfilters & OP_GREEKACCENTS) ? "On": "Off");
187  manager.setGlobalOption("Lemmas", (optionfilters & OP_LEMMAS) ? "On": "Off");
188  manager.setGlobalOption("Cross-references", (optionfilters & OP_SCRIPREF) ? "On": "Off");
189  manager.setGlobalOption("Words of Christ in Red", (optionfilters & OP_REDLETTERWORDS) ? "On": "Off");
190  manager.setGlobalOption("Arabic Vowel Points", (optionfilters & OP_ARABICPOINTS) ? "On": "Off");
191  manager.setGlobalOption("Glosses", (optionfilters & OP_GLOSSES) ? "On": "Off");
192  manager.setGlobalOption("Transliterated Forms", (optionfilters & OP_XLIT) ? "On": "Off");
193  manager.setGlobalOption("Enumerations", (optionfilters & OP_ENUM) ? "On": "Off");
194  manager.setGlobalOption("Morpheme Segmentation", (optionfilters & OP_MORPHSEG) ? "On": "Off");
195  manager.setGlobalOption("Transliteration", (optionfilters & OP_TRANSLITERATOR && script) ? script : "Off");
196 
197  VerseKey *parser = (SWDYNAMIC_CAST(VerseKey, target->getKey())) ? (VerseKey *)target->createKey() : 0;
198  if (parser && (optionfilters & OP_INTROS)) { parser->setIntros(true); ((VerseKey *)target->getKey())->setIntros(true); }
199 
200 
201  if ((optionfilters & OP_VARIANTS) && variants) {
202  if (variants == -1)
203  manager.setGlobalOption("Textual Variants", "All Readings");
204  else if (variants == 1)
205  manager.setGlobalOption("Textual Variants", "Secondary Reading");
206  }
207  else manager.setGlobalOption("Textual Variants", "Primary Reading");
208 
209 
210  if (querytype == QT_SEARCH) {
211  //do search stuff
212  char st = 1 - searchtype;
213  if (querytype == QT_BIBLE) {
214  *output << "Verses containing \"";
215  }
216  else *output << "Entries containing \"";
217  *output << ref;
218  *output << "\"-- ";
219 
220  if (range && parser) {
221  ListKey scope = parser->parseVerseList(range, "Gen 1:1", true);
222  listkey = target->search(ref, st, REG_ICASE, &scope);
223  }
224  else listkey = target->search(ref, st, REG_ICASE);
225 
226  bool first = true;
227  if (listkey.getCount()) {
228  for (listkey = TOP; !listkey.popError(); listkey++) {
229  if (!listkey.popError()) {
230  if (outputformat == FMT_CGI) *output << "<entry>";
231  *output << listkey.getText();
232  if (outputformat == FMT_CGI) *output << "</entry>";
233  }
234  if (first) first = false;
235  else *output << " ; ";
236  }
237  *output << " -- ";
238 
239  *output << listkey.getCount() << " matches total (";
240  }
241  else {
242  *output << "none (";
243  }
244  *output << target->getName();
245  *output << ")\n";
246  }
247  else {
248 
249  if (parser) {
250  listkey = parser->parseVerseList(ref, "Gen1:1", true);
251  }
252  else listkey << ref;
253 
254  font = target->getConfigEntry("Font");
255  if (!font) font = DEFAULT_FONT;
256 
257  if (outputformat == FMT_RTF) {
258  *output << "{\\rtf1\\ansi{\\fonttbl{\\f0\\froman\\fcharset0\\fprq2 Times New Roman;}{\\f1\\fdecor\\fprq2 ";
259  *output << font;
260  *output << ";}{\\f7\\froman\\fcharset2\\fprq2 Symbol;}}";
261  }
262 
263  else if (outputformat == FMT_LATEX) {
264  *output << "\\documentclass{bibletext}\n"
265  "\\usepackage{sword}\n"
266  "\\title{" << target->getDescription() << " \\\\\\small " << ref << "}\n";
267 
268  if (syslanguage.size()) {
269  syslanguage[0] = tolower(syslanguage[0]);
270  *output << "\\setmainlanguage{" << syslanguage << "}\n";
271  }
272 
273  if (modlanguage.size()) {
274  modlanguage[0] = tolower(modlanguage[0]);
275  }
276  else {
277  modlanguage = "english";
278  }
279 
280  if (!(modlanguage == syslanguage)) {
281  *output << "\\setotherlanguage{" << modlanguage << "}\n";
282  }
283 
284 
285  *output << "\\date{}\n"
286  "\\begin{document}\n"
287  "\\maketitle\n";
288 
289  if (!(modlanguage == syslanguage)) {
290  *output << "\\begin{" << modlanguage << "}\n";
291  }
292  }
293 
294 
295  else if (outputformat == FMT_HTML || outputformat == FMT_HTMLHREF || outputformat == FMT_XHTML) {
296  *output << "<html><head><meta http-equiv=\"content-type\" content=\"text/html\" charset=\"UTF-8\""
297  " lang=\"" << locale << "\" xml:lang=\"" << locale << "\"/>\n"
298  "<style type=\"text/css\">" << target->getRenderHeader() << "</style></head><body>";
299 
300  }
301 
302  for (listkey = TOP; !listkey.popError() && maxverses; listkey++) {
303  target->setKey(listkey);
304  VerseKey *vk = SWDYNAMIC_CAST(VerseKey, target->getKey());
305  // Call this before all the pre-verse handling, as it needs to be
306  // executed before the preverse headers are populated
307  SWBuf text = target->renderText();
308 
309  // if we've got a VerseKey (Bible or Commentary)
310  if (vk) {
311  // let's do some special processing if we're at verse 1
312  if (vk->getVerse() == 1) {
313  if (vk->getChapter() == 1) {
314  if (vk->getBook() == 1) {
315  if (vk->getTestament() == 1) {
316  // MODULE START SPECIAL PROCESSING
317  if (outputformat == FMT_LATEX)
318  { *output << "\\swordmodule\n";
319  // put your latex module start stuff here
320  }
321  }
322  // TESTAMENT START SPECIAL PROCESSING
323  if (outputformat == FMT_LATEX) {
324  // put your latex testament start stuff here
325  *output << "\\swordtestament\n";
326  }
327  }
328  // BOOK START SPECIAL PROCESSING
329  if (outputformat == FMT_LATEX) {
330  // put your latex book start stuff here
331  *output << "\\swordbook\n";
332  }
333  }
334  // CHAPTER START SPECIAL PROCESSING
335  if (outputformat == FMT_LATEX) {
336  *output << "\n\\swordchapter{"
337  << vk->getOSISRef() << "}{"
338  << vk->getText() << "}{"
339  << vk->getChapter() << "}";
340  }
341  }
342 
343  // PREVERSE MATTER
344  header = target->getEntryAttributes()["Heading"]["Preverse"]["0"];
345  *output << target->renderText(header);
346 
347  // VERSE PROCESSING
348  if (outputformat == FMT_LATEX) {
349  *output << "\\swordverse{"
350  << vk->getOSISRef() << "}{"
351  << vk->getText() << "}{"
352  << vk->getVerse() << "} ";
353  }
354  // no special format processing default: just show the key
355  else {
356  *output << target->getKeyText();
357  }
358  }
359  // if we're not a VerseKey, then simply output the key
360  else {
361  *output << target->getKeyText();
362  }
363 
364  // OUTPUT RENDER ENTRY
365  if (outputformat == FMT_HTML || outputformat == FMT_HTMLHREF || outputformat == FMT_XHTML || outputformat == FMT_THML || outputformat == FMT_CGI) {
366  *output << ": <span ";
367  *output << "style=\"font:" << font << ";\" ";
368  if (strcmp(modlocale,locale) !=0 ) { *output << "lang=\"" << modlocale << "\"";}
369  *output << ">";
370  }
371  else if (outputformat == FMT_RTF) {
372  *output << ": {\\f1 ";
373  }
374  else if (outputformat == FMT_LATEX) {
375  *output << " ";
376  }
377  else {
378  *output << ": ";
379  }
380 
381  *output << text;
382 
383 
384  if (outputformat == FMT_HTML || outputformat == FMT_HTMLHREF || outputformat == FMT_XHTML || outputformat == FMT_THML || outputformat == FMT_CGI) {
385  *output << "</span>";
386  }
387  else if (outputformat == FMT_RTF) {
388  *output << "}";
389  }
390 
391  if (inputformat != FMT_THML && (outputformat == FMT_HTML || outputformat == FMT_HTMLHREF || outputformat == FMT_XHTML || outputformat == FMT_THML || outputformat == FMT_CGI))
392  *output << "<br />";
393  else if (outputformat == FMT_OSIS)
394  *output << "<milestone type=\"line\"/>";
395  else if (outputformat == FMT_RTF)
396  *output << "\\par ";
397  else if (outputformat == FMT_GBF)
398  *output << "<CM>";
399 
400  *output << "\n";
401 
402  maxverses--;
403  }
404 
405  if ((outputformat == FMT_LATEX) && (!(modlanguage == syslanguage))) {
406  *output << "\\end{" << modlanguage << "}\n";
407  }
408 
409 
410  *output << "(";
411  *output << target->getName();
412 
413  if (outputformat == FMT_LATEX) {
414  *output << ", ";
415  *output << target->getConfigEntry("DistributionLicense");
416 
417  }
418 
419  *output << ")\n";
420 
421  if (outputformat == FMT_RTF) {
422  *output << "}";
423  }
424  else if (outputformat == FMT_LATEX) {
425  *output << "\\end{document}\n";
426  }
427  else if (outputformat == FMT_HTML || outputformat == FMT_HTMLHREF || outputformat == FMT_XHTML || outputformat == FMT_THML || outputformat == FMT_CGI) {
428  *output << "</body></html>\n";
429  }
430  }
431  delete parser;
432 }
#define TOP
Definition: swkey.h:68
#define QT_BIBLE
Definition: corediatheke.h:35
virtual void setDefaultLocaleName(const char *name)
Definition: localemgr.cpp:251
#define OP_ARSHAPE
Definition: corediatheke.h:53
#define OP_VARIANTS
Definition: corediatheke.h:55
#define OP_MORPH
Definition: corediatheke.h:46
#define OP_STRONGS
Definition: corediatheke.h:43
#define REG_ICASE
Definition: regex.h:261
#define QT_SYSTEM
Definition: corediatheke.h:39
int stricmp(const char *s1, const char *s2)
Definition: utilstr.cpp:194
#define OP_GLOSSES
Definition: corediatheke.h:58
#define OP_LEMMAS
Definition: corediatheke.h:51
int range
Definition: regex.c:5043
#define OP_ARABICPOINTS
Definition: corediatheke.h:57
#define OP_CANTILLATION
Definition: corediatheke.h:47
#define OP_BIDI
Definition: corediatheke.h:54
return NULL
Definition: regex.c:7953
#define FMT_CGI
Definition: diafiltmgr.h:26
#define OP_XLIT
Definition: corediatheke.h:59
static LocaleMgr * getSystemLocaleMgr()
Definition: localemgr.cpp:54
#define OP_INTROS
Definition: corediatheke.h:62
void systemquery(const char *key, ostream *output)
#define QT_SEARCH
Definition: corediatheke.h:38
#define QT_INFO
Definition: corediatheke.h:40
virtual const char * translate(const char *text, const char *localeName=0)
Definition: localemgr.cpp:234
#define SWDYNAMIC_CAST(className, object)
Definition: defs.h:47
#define OP_SCRIPREF
Definition: corediatheke.h:52
#define OP_REDLETTERWORDS
Definition: corediatheke.h:56
#define OP_HEADINGS
Definition: corediatheke.h:45
#define OP_HEBREWPOINTS
Definition: corediatheke.h:48
#define OP_FOOTNOTES
Definition: corediatheke.h:44
int strnicmp(const char *s1, const char *s2, int len)
Definition: utilstr.cpp:180
#define OP_GREEKACCENTS
Definition: corediatheke.h:49
#define OP_MORPHSEG
Definition: corediatheke.h:61
#define OP_TRANSLITERATOR
Definition: corediatheke.h:50
#define OP_ENUM
Definition: corediatheke.h:60
int hasalpha ( char *  string)