~ubuntu-branches/debian/squeeze/sword/squeeze

« back to all changes in this revision

Viewing changes to utilities/diatheke/diatheke.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Glassey
  • Date: 2004-01-15 15:50:07 UTC
  • Revision ID: james.westby@ubuntu.com-20040115155007-n9mz4x0zxrs1isd3
Tags: upstream-1.5.7
ImportĀ upstreamĀ versionĀ 1.5.7

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Diatheke 4.2 by Chris Little <chrislit@crosswire.org>
 
2
// Copyright 1999-2002 by CrossWire Bible Society
 
3
// http://www.crosswire.org/sword/diatheke
 
4
// Licensed under GNU General Public License (GPL)
 
5
// see accompanying LICENSE file for license details
 
6
 
 
7
 
 
8
#include "corediatheke.h"
 
9
#include "diathekemgr.h"
 
10
#include "diafiltmgr.h"
 
11
#include <iostream>
 
12
 
 
13
using std::cout;
 
14
 
 
15
#define RQ_REF 1
 
16
#define RQ_BOOK 2
 
17
 
 
18
void printsyntax() { 
 
19
        //if we got this far without exiting, something went wrong, so print syntax
 
20
        fprintf (stderr, "Diatheke command-line SWORD frontend Version 4.2\n");
 
21
        fprintf (stderr, "Copyright 1999-2002 by the CrossWire Bible Society\n");
 
22
        fprintf (stderr, "http://www.crosswire.org/sword/diatheke/\n");
 
23
        fprintf (stderr, "usage: \n  ");
 
24
        fprintf (stderr, "diatheke <-b book> [-s search_type] [-r search_range] [-o option_filters]\n");
 
25
        fprintf (stderr, "[-m maximum_verses] [-f output_format] [-l locale]\n");
 
26
        fprintf (stderr, "[-e output_encoding] [-t script] [-v variant#(-1=all|0|1)]\n");
 
27
        fprintf (stderr, "<-k query_key>\n");
 
28
        fprintf (stderr, "\n");
 
29
        fprintf (stderr, "If <book> is \"system\" you may use these system keys: \"modulelist\",\n");
 
30
        fprintf (stderr, "\"modulelistnames\", and \"localelist\".");
 
31
        fprintf (stderr, "\n");
 
32
        fprintf (stderr, "Valid search_type values are: regex, multiword, and phrase(def).\n");
 
33
        fprintf (stderr, "Valid option_filters values are: n (Strong's numbers),\n");
 
34
        fprintf (stderr, "  f (Footnotes), m (Morphology), h (Section Headings),\n");
 
35
        fprintf (stderr, "  c (Cantillation), v (Hebrew Vowels), a (Greek Accents),\n");
 
36
        fprintf (stderr, "  l (Lemmas), s (Scripture Crossrefs), r (Arabic Shaping,\n");
 
37
        fprintf (stderr, "  b (Bi-Directional Reordering), x (Red Words of Christ)\n");
 
38
 
 
39
        fprintf (stderr, "Maximum verses may be any integer value\n");
 
40
        fprintf (stderr, "Valid output_format values are: GBF, ThML, RTF, HTML, OSIS, CGI, and plain (def)\n");
 
41
        fprintf (stderr, "Valid output_encoding values are: Latin1, UTF8 (def), UTF16, HTML, and RTF\n");
 
42
        fprintf (stderr, "Valid locale values depend on installed locales. en is default.\n");
 
43
        fprintf (stderr, "The query_key must be the last argument because all following\n");
 
44
        fprintf (stderr, "  arguments are added to the key.\n");
 
45
}
 
46
 
 
47
int main(int argc, char **argv)
 
48
{
 
49
        int maxverses = -1;
 
50
        unsigned char outputformat = FMT_PLAIN, searchtype = ST_NONE, outputencoding = ENC_UTF8;
 
51
        unsigned long optionfilters = OP_NONE;
 
52
        char *text = 0, *locale = 0, *ref = 0, *script = 0, *range = 0;
 
53
        signed short variants = 0;
 
54
        
 
55
        char runquery = 0; // used to check that we have enough arguments to perform a legal query
 
56
        // (a querytype & text = 1 and a ref = 2)
 
57
        
 
58
        for (int i = 1; i < argc; i++) {
 
59
                if (!stricmp("-b", argv[i])) {
 
60
                        if (i+1 <= argc) {
 
61
                                text = argv[i+1];
 
62
                                i++;
 
63
                                runquery |= RQ_BOOK;
 
64
                        }
 
65
                }
 
66
                else if (!stricmp("-s", argv[i])) {
 
67
                        if (i+1 <= argc) {
 
68
                                if (!stricmp("phrase", argv[i+1])) {
 
69
                                        searchtype = ST_PHRASE;
 
70
                                        i++;
 
71
                                }
 
72
                                else if (!stricmp("regex", argv[i+1])) {
 
73
                                        searchtype = ST_REGEX;
 
74
                                        i++;
 
75
                                }
 
76
                                else if (!stricmp("multiword", argv[i+1])) {
 
77
                                        searchtype = ST_MULTIWORD;
 
78
                                        i++;
 
79
                                }
 
80
                                else i++;
 
81
                        }
 
82
                }
 
83
                else if (!stricmp("-r", argv[i])) {
 
84
                        if (i+1 <= argc) {
 
85
                                range = argv[i+1];
 
86
                                i++;
 
87
                        }       
 
88
                }
 
89
                else if (!stricmp("-l", argv[i])) {
 
90
                        if (i+1 <= argc) {
 
91
                                locale = argv[i+1];
 
92
                                i++;
 
93
                        }
 
94
                }
 
95
                else if (!stricmp("-m", argv[i])) {
 
96
                        if (i+1 <= argc) {
 
97
                                maxverses = atoi(argv[i+1]);
 
98
                                i++;
 
99
                        }
 
100
                }
 
101
                else if (!stricmp("-o", argv[i])) {
 
102
                        if (i+1 <= argc) {
 
103
                                if (strchr(argv[i+1], 'f'))
 
104
                                        optionfilters |= OP_FOOTNOTES;
 
105
                                if (strchr(argv[i+1], 'n'))
 
106
                                        optionfilters |= OP_STRONGS;
 
107
                                if (strchr(argv[i+1], 'h'))
 
108
                                        optionfilters |= OP_HEADINGS;
 
109
                                if (strchr(argv[i+1], 'm'))
 
110
                                        optionfilters |= OP_MORPH;
 
111
                                if (strchr(argv[i+1], 'c'))
 
112
                                        optionfilters |= OP_CANTILLATION;
 
113
                                if (strchr(argv[i+1], 'v'))
 
114
                                        optionfilters |= OP_HEBREWPOINTS;
 
115
                                if (strchr(argv[i+1], 'a'))
 
116
                                        optionfilters |= OP_GREEKACCENTS;
 
117
                                if (strchr(argv[i+1], 'l'))
 
118
                                        optionfilters |= OP_LEMMAS;
 
119
                                if (strchr(argv[i+1], 's'))
 
120
                                        optionfilters |= OP_SCRIPREF;
 
121
                                if (strchr(argv[i+1], 'r'))
 
122
                                        optionfilters |= OP_ARSHAPE;
 
123
                                if (strchr(argv[i+1], 'b'))
 
124
                                        optionfilters |= OP_BIDI;
 
125
                                if (strchr(argv[i+1], 'x'))
 
126
                                        optionfilters |= OP_RED;
 
127
                                i++;
 
128
                        }
 
129
                }
 
130
                else if (!stricmp("-f", argv[i])) {
 
131
                        if (i+1 <= argc) {
 
132
                                if (!stricmp("thml", argv[i+1])) {
 
133
                                        outputformat = FMT_THML;
 
134
                                        i++;
 
135
                                }
 
136
                                else if (!stricmp("cgi", argv[i+1])) {
 
137
                                        outputformat = FMT_CGI;
 
138
                                        i++;
 
139
                                }
 
140
                                else if (!stricmp("gbf", argv[i+1])) {
 
141
                                        outputformat = FMT_GBF;
 
142
                                        i++;
 
143
                                }
 
144
                                else if (!stricmp("html", argv[i+1])) {
 
145
                                        outputformat = FMT_HTML;
 
146
                                        i++;
 
147
                                }
 
148
                                else if (!stricmp("rtf", argv[i+1])) {
 
149
                                        outputformat = FMT_RTF;
 
150
                                        i++;
 
151
                                }
 
152
                                else if (!stricmp("osis", argv[i+1])) {
 
153
                                        outputformat = FMT_OSIS;
 
154
                                        i++;
 
155
                                }
 
156
                                else i++;
 
157
                        }
 
158
                }
 
159
                else if (!stricmp("-e", argv[i])) {
 
160
                        if (i+1 <= argc) {
 
161
                                if (!stricmp("utf8", argv[i+1])) {
 
162
                                        outputencoding = ENC_UTF8;
 
163
                                        i++;
 
164
                                }
 
165
                                else if (!stricmp("rtf", argv[i+1])) {
 
166
                                        outputencoding = ENC_RTF;
 
167
                                        i++;
 
168
                                }
 
169
                                else if (!stricmp("html", argv[i+1])) {
 
170
                                        outputencoding = ENC_HTML;
 
171
                                        i++;
 
172
                                }
 
173
                                else if (!stricmp("latin1", argv[i+1])) {
 
174
                                        outputencoding = ENC_LATIN1;
 
175
                                        i++;
 
176
                                }
 
177
                                else if (!stricmp("utf16", argv[i+1])) {
 
178
                                        outputencoding = ENC_UTF16;
 
179
                                        i++;
 
180
                                }
 
181
                                else i++;
 
182
                        }
 
183
                }
 
184
                else if (!stricmp("-k", argv[i])) {
 
185
                        i++;    
 
186
                        if (i < argc) {
 
187
                                SWBuf key = argv[i];
 
188
                                i++;
 
189
                                for (; i < argc; i++)
 
190
                                        key = key + " " + argv[i];
 
191
                                ref = new char[key.length() + 1];
 
192
                                strcpy (ref, key.c_str());
 
193
                                if (strlen(ref))
 
194
                                        runquery |= RQ_REF;
 
195
                        }
 
196
                }
 
197
                else if (!stricmp("-v", argv[i])) {
 
198
                        if (i+1 <= argc) {
 
199
                                variants = atoi(argv[i+1]);
 
200
                                optionfilters |= OP_VARIANTS;
 
201
                                i++;
 
202
                        }
 
203
                }
 
204
#ifdef _ICU_
 
205
                else if (!stricmp("-t", argv[i])) {
 
206
                        if (i+1 <= argc) {
 
207
                                script = argv[i+1];
 
208
                                optionfilters |= OP_TRANSLITERATOR;
 
209
                                i++;
 
210
                        }
 
211
                }
 
212
#endif
 
213
        }
 
214
        
 
215
        
 
216
        if (runquery == (RQ_BOOK | RQ_REF)) {
 
217
            doquery(maxverses, outputformat, outputencoding, optionfilters, searchtype, range, text, locale, ref, &cout, script, variants);
 
218
        }
 
219
        else printsyntax();
 
220
 
 
221
        return 0;
 
222
}