The SWORD Project  1.9.0.svnversion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
diatheke.cpp File Reference
#include "corediatheke.h"
#include "diathekemgr.h"
#include "diafiltmgr.h"
#include <utilstr.h>
#include <swversion.h>
+ Include dependency graph for diatheke.cpp:

Go to the source code of this file.

Macros

#define RQ_BOOK   2
 
#define RQ_REF   1
 

Functions

int main (int argc, char **argv)
 
void printsyntax ()
 

Macro Definition Documentation

#define RQ_BOOK   2

Definition at line 37 of file diatheke.cpp.

#define RQ_REF   1

Definition at line 36 of file diatheke.cpp.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 82 of file diatheke.cpp.

83 {
84  int maxverses = -1;
85  unsigned char outputformat = FMT_INTERNAL, searchtype = ST_NONE, outputencoding = ENC_UTF8;
86  unsigned long optionfilters = OP_NONE;
87  char *text = 0, *locale = 0, *ref = 0, *range = 0;
88  char script[] = "Latin"; // for the moment, only this target script is supported
89  signed short variants = 0;
90 
91  char runquery = 0; // used to check that we have enough arguments to perform a legal query
92  // (a querytype & text = 1 and a ref = 2)
93 
94  for (int i = 1; i < argc; ++i) {
95  if (!::stricmp("-b", argv[i])) {
96  if (i+1 <= argc) {
97  ++i;
98  text = argv[i];
99  runquery |= RQ_BOOK;
100  }
101  }
102  else if (!::stricmp("-s", argv[i])) {
103  if (i+1 <= argc) {
104  ++i;
105  if (!::stricmp("phrase", argv[i])) {
106  searchtype = ST_PHRASE;
107  }
108  else if (!::stricmp("regex", argv[i])) {
109  searchtype = ST_REGEX;
110  }
111  else if (!::stricmp("multiword", argv[i])) {
112  searchtype = ST_MULTIWORD;
113  }
114  else if (!::stricmp("lucene", argv[i])) {
115  searchtype = ST_CLUCENE;
116  }
117  else if (!::stricmp("attribute", argv[i])) {
118  searchtype = ST_ENTRYATTRIB;
119  }
120  else if (!::stricmp("multilemma", argv[i])) {
121  searchtype = ST_MULTILEMMA;
122  }
123  else {
124  fprintf (stderr, "Unknown search_type: %s\n", argv[i]);
125  fprintf (stderr, "Try diatheke --help\n");
126  return 0;
127  }
128  }
129  }
130  else if (!::stricmp("-r", argv[i])) {
131  if (i+1 <= argc) {
132  ++i;
133  range = argv[i];
134  }
135  }
136  else if (!::stricmp("-l", argv[i])) {
137  if (i+1 <= argc) {
138  ++i;
139  locale = argv[i];
140  }
141  }
142  else if (!::stricmp("-m", argv[i])) {
143  if (i+1 <= argc) {
144  ++i;
145  maxverses = atoi(argv[i]);
146  }
147  }
148  else if (!::stricmp("-o", argv[i])) {
149  if (i+1 <= argc) {
150  ++i;
151  if (strchr(argv[i], 'f'))
152  optionfilters |= OP_FOOTNOTES;
153  if (strchr(argv[i], 'n'))
154  optionfilters |= OP_STRONGS;
155  if (strchr(argv[i], 'h'))
156  optionfilters |= OP_HEADINGS;
157  if (strchr(argv[i], 'm'))
158  optionfilters |= OP_MORPH;
159  if (strchr(argv[i], 'c'))
160  optionfilters |= OP_CANTILLATION;
161  if (strchr(argv[i], 'v'))
162  optionfilters |= OP_HEBREWPOINTS;
163  if (strchr(argv[i], 'a'))
164  optionfilters |= OP_GREEKACCENTS;
165  if (strchr(argv[i], 'l'))
166  optionfilters |= OP_LEMMAS;
167  if (strchr(argv[i], 's'))
168  optionfilters |= OP_SCRIPREF;
169  if (strchr(argv[i], 'r'))
170  optionfilters |= OP_ARSHAPE;
171  if (strchr(argv[i], 'b'))
172  optionfilters |= OP_BIDI;
173  if (strchr(argv[i], 'w'))
174  optionfilters |= OP_REDLETTERWORDS;
175  if (strchr(argv[i], 'p'))
176  optionfilters |= OP_ARABICPOINTS;
177  if (strchr(argv[i], 'g'))
178  optionfilters |= OP_GLOSSES;
179  if (strchr(argv[i], 'x'))
180  optionfilters |= OP_XLIT;
181  if (strchr(argv[i], 'e'))
182  optionfilters |= OP_ENUM;
183  if (strchr(argv[i], 'i'))
184  optionfilters |= OP_INTROS;
185  if (strchr(argv[i], 't'))
186  optionfilters |= OP_TRANSLITERATOR;
187  if (strchr(argv[i], 'M'))
188  optionfilters |= OP_MORPHSEG;
189  }
190  }
191  else if (!::stricmp("-f", argv[i])) {
192  if (i+1 <= argc) {
193  ++i;
194  if (!::stricmp("thml", argv[i])) {
195  outputformat = FMT_THML;
196  }
197  else if (!::stricmp("cgi", argv[i])) {
198  outputformat = FMT_CGI;
199  }
200  else if (!::stricmp("gbf", argv[i])) {
201  outputformat = FMT_GBF;
202  }
203  else if (!::stricmp("htmlhref", argv[i])) {
204  outputformat = FMT_HTMLHREF;
205  }
206  else if (!::stricmp("html", argv[i])) {
207  outputformat = FMT_HTML;
208  }
209  else if (!::stricmp("xhtml", argv[i])) {
210  outputformat = FMT_XHTML;
211  }
212  else if (!::stricmp("rtf", argv[i])) {
213  outputformat = FMT_RTF;
214  }
215  else if (!::stricmp("osis", argv[i])) {
216  outputformat = FMT_OSIS;
217  }
218  else if (!::stricmp("latex", argv[i])) {
219  outputformat = FMT_LATEX;
220  }
221  else if (!::stricmp("plain", argv[i])) {
222  outputformat = FMT_PLAIN;
223  }
224  else if (!::stricmp("webif", argv[i])) {
225  outputformat = FMT_WEBIF;
226  }
227  else if (!::stricmp("internal", argv[i])) {
228  outputformat = FMT_INTERNAL;
229  }
230  }
231  }
232  else if (!::stricmp("-e", argv[i])) {
233  if (i+1 <= argc) {
234  ++i;
235  if (!::stricmp("utf8", argv[i])) {
236  outputencoding = ENC_UTF8;
237  }
238  else if (!::stricmp("rtf", argv[i])) {
239  outputencoding = ENC_RTF;
240  }
241  else if (!::stricmp("html", argv[i])) {
242  outputencoding = ENC_HTML;
243  }
244  else if (!::stricmp("latin1", argv[i])) {
245  outputencoding = ENC_LATIN1;
246  }
247  else if (!::stricmp("utf16", argv[i])) {
248  outputencoding = ENC_UTF16;
249  }
250  else if (!::stricmp("scsu", argv[i])) {
251  outputencoding = ENC_SCSU;
252  }
253  }
254  }
255  else if (!::stricmp("-k", argv[i])) {
256  ++i;
257  if (i < argc) {
258  SWBuf key = argv[i];
259  ++i;
260  for (; i < argc; ++i) {
261  if (!::stricmp("-h", argv[i]) || !::stricmp("--help", argv[i]))
262  printsyntax();
263  key = key + " " + argv[i];
264  }
265  ref = new char[key.length() + 1];
266  strcpy (ref, key.c_str());
267  if (strlen(ref))
268  runquery |= RQ_REF;
269  }
270  }
271  else if (!::stricmp("-v", argv[i])) {
272  if (i+1 <= argc) {
273  ++i;
274  variants = atoi(argv[i]);
275  optionfilters |= OP_VARIANTS;
276  }
277  }
278  /*
279  else if (!::stricmp("-t", argv[i])) {
280  if (i+1 <= argc) {
281  ++i;
282  script = argv[i];
283  optionfilters |= OP_TRANSLITERATOR;
284  }
285  }
286  */
287  else {
288  // unexpected argument, so print the syntax
289  // -h, --help, /?, etc. will trigger this
290  printsyntax();
291  }
292  }
293 
294 
295  if (runquery == (RQ_BOOK | RQ_REF)) {
296  doquery(maxverses, outputformat, outputencoding, optionfilters, searchtype, range, text, locale, ref, &cout, script, variants);
297  }
298  //if we got this far without exiting, something went wrong, so print syntax
299  else printsyntax();
300 
301  return 0;
302 }
void printsyntax()
Definition: diatheke.cpp:39
#define ST_MULTIWORD
Definition: corediatheke.h:67
#define RQ_REF
Definition: diatheke.cpp:36
#define OP_ARSHAPE
Definition: corediatheke.h:53
#define FMT_INTERNAL
Definition: diafiltmgr.h:27
#define OP_VARIANTS
Definition: corediatheke.h:55
#define OP_MORPH
Definition: corediatheke.h:46
#define OP_STRONGS
Definition: corediatheke.h:43
#define ST_REGEX
Definition: corediatheke.h:65
#define RQ_BOOK
Definition: diatheke.cpp:37
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
#define FMT_CGI
Definition: diafiltmgr.h:26
#define OP_XLIT
Definition: corediatheke.h:59
#define ST_PHRASE
Definition: corediatheke.h:66
#define OP_INTROS
Definition: corediatheke.h:62
#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
#define OP_GREEKACCENTS
Definition: corediatheke.h:49
#define OP_MORPHSEG
Definition: corediatheke.h:61
#define ST_NONE
Definition: corediatheke.h:64
#define ST_CLUCENE
Definition: corediatheke.h:69
void doquery(unsigned long maxverses=-1, unsigned char outputformat=FMT_PLAIN, unsigned char outputencoding=ENC_UTF8, unsigned long optionfilters=0, unsigned char searchtype=ST_NONE, const char *range=0, const char *text=0, const char *locale=0, const char *ref=0, ostream *output=&cout, const char *script=0, signed char variants=0)
#define OP_TRANSLITERATOR
Definition: corediatheke.h:50
#define ST_ENTRYATTRIB
Definition: corediatheke.h:68
#define OP_NONE
Definition: corediatheke.h:42
#define OP_ENUM
Definition: corediatheke.h:60
#define ST_MULTILEMMA
Definition: corediatheke.h:70
void printsyntax ( )

Definition at line 39 of file diatheke.cpp.

39  {
40  //if we got this far without exiting, something went wrong, so print syntax
41  fprintf (stderr, "Diatheke command-line SWORD frontend Version 4.8 (SWORD: %s)\n", SWVersion::currentVersion.getText());
42  fprintf (stderr, "Copyright 1999-2018 by the CrossWire Bible Society\n");
43  fprintf (stderr, "http://www.crosswire.org/sword/diatheke/\n");
44  fprintf (stderr, "\n");
45  fprintf (stderr, "usage: diatheke <-b module_name> [-s search_type] [-r search_range]\n");
46  fprintf (stderr, " [-o option_filters] [-m maximum_verses] [-f output_format]\n");
47  fprintf (stderr, " [-e output_encoding] [-v variant#(-1=all|0|1)]\n");
48  fprintf (stderr, " [-l locale] <-k query_key>\n");
49  fprintf (stderr, "\n");
50  fprintf (stderr, "If <book> is \"system\" you may use these system keys: \"modulelist\",\n");
51  fprintf (stderr, "\"modulelistnames\", \"bibliography\", and \"localelist\".");
52  fprintf (stderr, "\n");
53  fprintf (stderr, "Valid search_type values are: phrase , regex, multiword, attribute,\n");
54  fprintf (stderr, " lucene, multilemma.\n");
55  fprintf (stderr, "Valid (output) option_filters values are: n (Strong's numbers),\n");
56  fprintf (stderr, " f (Footnotes), m (Morphology), h (Section Headings),\n");
57  fprintf (stderr, " c (Cantillation), v (Hebrew Vowels), a (Greek Accents), p (Arabic Vowels)\n");
58  fprintf (stderr, " l (Lemmas), s (Scripture Crossrefs), r (Arabic Shaping),\n");
59  fprintf (stderr, " b (Bi-Directional Reordering), w (Red Words of Christ),\n");
60  fprintf (stderr, " g (Glosses/Ruby), e (Word Enumerations), i (Intros)\n");
61  fprintf (stderr, " x (Encoded Transliterations), t (Algorithmic Transliterations via ICU),\n");
62  fprintf (stderr, " M (morpheme segmentation)\n");
63 
64  fprintf (stderr, "Maximum verses may be any integer value\n");
65  fprintf (stderr, "Valid output_format values are: CGI, GBF, HTML, HTMLHREF, LaTeX, OSIS, RTF,\n");
66  fprintf (stderr, " ThML, WEBIF, XHTML, plain, and internal (def)\n");
67  fprintf (stderr, "The option LaTeX will produce a compilable document, but may well require\n");
68  fprintf (stderr, " tweaking to be usable.\n");
69  fprintf (stderr, "Valid output_encoding values are: Latin1, UTF8 (def), UTF16, HTML, RTF, and SCSU\n");
70  fprintf (stderr, "Valid locale values depend on installed locales. en is default.\n");
71  fprintf (stderr, "The query_key must be the last argument because all following\n");
72  fprintf (stderr, " arguments are added to the key.\n");
73  fprintf (stderr, "\n");
74  fprintf (stderr, "Example usage:\n");
75  fprintf (stderr, " diatheke -b KJV -o fmnx -k Jn 3:16\n");
76  fprintf (stderr, " diatheke -b WHNU -t Latin -o mn -k Mt 24\n");
77  fprintf (stderr, " diatheke -b KJV -s phrase -r Mt -k love\n");
78 
79  exit(EXIT_FAILURE);
80 }
static SWVersion currentVersion
Definition: swversion.h:69