aboutsummaryrefslogtreecommitdiffstats
path: root/doc/api-documentation/html/jfbgen_8cpp-source.html
blob: dfff10bb6d2a5de2e17592d650bca79c65739593 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
<title>jfbgen.cpp Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.2.15 -->
<center>
<a class="qindex" href="index.html">Main Page</a> &nbsp; <a class="qindex" href="namespaces.html">Namespace List</a> &nbsp; <a class="qindex" href="hierarchy.html">Class Hierarchy</a> &nbsp; <a class="qindex" href="classes.html">Alphabetical List</a> &nbsp; <a class="qindex" href="annotated.html">Compound List</a> &nbsp; <a class="qindex" href="files.html">File List</a> &nbsp; <a class="qindex" href="functions.html">Compound Members</a> &nbsp; </center>
<hr><h1>jfbgen.cpp</h1><div class="fragment"><pre>00001 <font class="comment">/*****************************************************************************</font>
00002 <font class="comment"> *</font>
00003 <font class="comment"> */</font>
00004 
00005 <font class="preprocessor">#include &lt;stdio.h&gt;</font>
00006 <font class="preprocessor">#include &lt;stdlib.h&gt;</font>
00007 <font class="preprocessor">#include &lt;string.h&gt;</font>
00008 <font class="preprocessor">#include &lt;ctype.h&gt;</font>
00009 
00010 <font class="preprocessor">#ifndef __GNUC__</font>
00011 <font class="preprocessor"></font><font class="preprocessor">#include &lt;io.h&gt;</font>
00012 <font class="preprocessor">#else</font>
00013 <font class="preprocessor"></font><font class="preprocessor">#include &lt;unistd.h&gt;</font>
00014 <font class="preprocessor">#endif</font>
00015 <font class="preprocessor"></font>
00016 <font class="preprocessor">#include &lt;fcntl.h&gt;</font>
00017 <font class="preprocessor">#include &lt;versekey.h&gt;</font>
00018 
00019 <font class="preprocessor">#ifndef O_BINARY</font>
00020 <font class="preprocessor"></font><font class="preprocessor">        #define O_BINARY 0</font>
00021 <font class="preprocessor"></font><font class="preprocessor">#endif</font>
00022 <font class="preprocessor"></font>
00023 <font class="keywordtype">void</font> writeidx(<a class="code" href="class_verse_key.html">VerseKey</a> &amp;key1, <a class="code" href="class_verse_key.html">VerseKey</a> &amp;key2, <a class="code" href="class_verse_key.html">VerseKey</a> &amp;key3, <font class="keywordtype">long</font> offset, <font class="keywordtype">short</font> size);
00024 <font class="keywordtype">char</font> findbreak(<font class="keywordtype">int</font> fp, <font class="keywordtype">long</font> *offset, <font class="keywordtype">int</font> *num1, <font class="keywordtype">int</font> *num2, <font class="keywordtype">int</font> *rangemax, <font class="keywordtype">short</font> *size);
00025 <font class="keywordtype">void</font> openfiles();
00026 <font class="keywordtype">void</font> checkparams(<font class="keywordtype">int</font> argc, <font class="keywordtype">char</font> **argv);
00027 <font class="keywordtype">void</font> charsetconvert(<font class="keywordtype">char</font> *data);
00028 
00029 
00030 <a class="code" href="class_verse_key.html">VerseKey</a> key1, key2, key3;
00031 <font class="keywordtype">int</font> fp, vfp, cfp, bfp;
00032 <font class="keywordtype">long</font> chapoffset;
00033 <font class="keywordtype">short</font> chapsize;
00034 <font class="keywordtype">char</font> testmnt;
00035 <font class="keywordtype">char</font> startflag = 0;
00036 
00037 
00038 main(<font class="keywordtype">int</font> argc, <font class="keywordtype">char</font> **argv)
00039 {
00040         <font class="keywordtype">long</font> pos, offset;
00041         <font class="keywordtype">int</font> num1, num2, rangemax, curbook = 0, curchap = 0, curverse = 0;
00042         <font class="keywordtype">char</font> buf[127];
00043         <font class="keywordtype">short</font> size, tmp;
00044         <font class="keyword">extern</font> <font class="keyword">struct </font>zonline online;
00045 
00046         checkparams(argc, argv);
00047 
00048         key1 = key2 = key3 = <font class="stringliteral">"Genesis 1:1"</font>;
00049 
00050         openfiles();
00051 
00052         num1    = key1.<a class="code" href="class_verse_key.html#a24">Chapter</a>();
00053         num2    = key1.<a class="code" href="class_verse_key.html#a25">Verse</a>();
00054 
00055         <font class="keywordflow">while</font>(!findbreak(fp, &amp;offset, &amp;num1, &amp;num2, &amp;rangemax, &amp;size)) {
00056                 <font class="keywordflow">if</font> (!startflag) {
00057                         startflag = 1;
00058                 }
00059                 <font class="keywordflow">else</font> {
00060                         <font class="keywordflow">if</font> (num2 &lt; key2.<a class="code" href="class_verse_key.html#a25">Verse</a>()) {            <font class="comment">// new chapter</font>
00061                                 <font class="keywordflow">if</font> (num1 &lt;= key2.<a class="code" href="class_verse_key.html#a24">Chapter</a>()) { <font class="comment">// new book</font>
00062                                         key2.<a class="code" href="class_verse_key.html#a25">Verse</a>(1);
00063                                         key2.<a class="code" href="class_verse_key.html#a24">Chapter</a>(1);
00064                                         key2.<a class="code" href="class_verse_key.html#a23">Book</a>(key2.<a class="code" href="class_verse_key.html#a23">Book</a>()+1);
00065                                 }
00066                                 printf(<font class="stringliteral">"Found Chapter Break: %d ('%s')\n"</font>, num1, (<font class="keyword">const</font> <font class="keywordtype">char</font> *)key2);
00067                                 chapoffset = offset;
00068                                 chapsize = size;
00069 <font class="comment">//                              continue;</font>
00070                         }
00071                 }
00072                 key2.<a class="code" href="class_verse_key.html#a25">Verse</a>(1);
00073                 key2.<a class="code" href="class_verse_key.html#a24">Chapter</a>(num1);
00074                 key2.<a class="code" href="class_verse_key.html#a25">Verse</a>(num2);
00075 
00076                 key3 = key2;
00077 <font class="comment">//              key3 += (rangemax - key3.Verse());</font>
00078 
00079                 writeidx(key1, key2, key3, offset, size);
00080         }
00081         close(vfp);
00082         close(cfp);
00083         close(bfp);
00084         close(fp);
00085 }
00086 
00087 
00088 <font class="comment">/**************************************************************************</font>
00089 <font class="comment"> * ENT: key1    - current location of index</font>
00090 <font class="comment"> *      key2    - minimum keyval for which this offset is valid</font>
00091 <font class="comment"> *      key3    - maximum keyval for which this offset is valid</font>
00092 <font class="comment"> */</font>
00093 
00094 <font class="keywordtype">void</font> writeidx(<a class="code" href="class_verse_key.html">VerseKey</a> &amp;key1, <a class="code" href="class_verse_key.html">VerseKey</a> &amp;key2, <a class="code" href="class_verse_key.html">VerseKey</a> &amp;key3, <font class="keywordtype">long</font> offset, <font class="keywordtype">short</font> size)
00095 {
00096         <font class="keywordtype">long</font> pos;
00097         <font class="keywordtype">short</font> tmp;
00098 
00099                 <font class="keywordflow">if</font> (key1.<a class="code" href="class_verse_key.html#a25">Verse</a>() == 1) {        <font class="comment">// new chapter</font>
00100                         <font class="keywordflow">if</font> (key1.<a class="code" href="class_verse_key.html#a24">Chapter</a>() == 1) {      <font class="comment">// new book</font>
00101                                 pos = lseek(cfp, 0, SEEK_CUR);
00102                                 write(bfp, &amp;pos, 4);
00103                                 pos = lseek(vfp, 0, SEEK_CUR); <font class="comment">/* Book intro (cps) */</font>
00104                                 write(cfp, &amp;pos, 4);
00105                                 write(vfp, &amp;chapoffset, 4);  <font class="comment">/* Book intro (vss)  set to same as chap for now(it should be chap 1 which usually contains the book into anyway)*/</font>
00106                                 write(vfp, &amp;chapsize, 2);
00107                         }
00108                         pos = lseek(vfp, 0, SEEK_CUR);
00109                         write(cfp, &amp;pos, 4);
00110                         write(vfp, &amp;chapoffset, 4);  <font class="comment">/* Chapter intro */</font>
00111                         write(vfp, &amp;chapsize, 2);
00112                 }
00113                 <font class="keywordflow">if</font> (key1 &gt;= key2) {
00114                         write(vfp, &amp;offset, 4);
00115                         write(vfp, &amp;size, 2);
00116                 }
00117                 <font class="keywordflow">else</font>    {
00118                         pos = 0;
00119                         tmp = 0;
00120                         write(vfp, &amp;pos, 4);
00121                         write(vfp, &amp;tmp, 2);
00122                 }
00123                 key1++;
00124 }
00125 
00126 
00127 <font class="keyword">static</font> <a class="code" href="class_verse_key.html">VerseKey</a> inckey = <font class="stringliteral">"Genesis 1:1"</font>;
00128 
00129 <font class="keywordtype">char</font> findbreak(<font class="keywordtype">int</font> fp, <font class="keywordtype">long</font> *offset, <font class="keywordtype">int</font> *num1, <font class="keywordtype">int</font> *num2, <font class="keywordtype">int</font> *rangemax, <font class="keywordtype">short</font> *size)
00130 {
00131         <font class="keywordtype">char</font> buf[7];
00132         <font class="keywordtype">char</font> buf2[20];
00133         <font class="keywordtype">char</font> ch;
00134         <font class="keywordtype">char</font> loop;
00135         <font class="keywordtype">long</font> offset2;
00136         <font class="keywordtype">int</font> ch2, vs2, rm2;
00137         <font class="keywordtype">bool</font> flag;
00138         <font class="keywordtype">long</font> chapstart = 0; 
00139         <font class="keyword">static</font> <font class="keywordtype">int</font> olbvnum = 0;
00140         <font class="keywordtype">char</font> data[256];
00141         <font class="keywordtype">char</font> *bookabrev[66] = {<font class="stringliteral">"Ge"</font>, <font class="stringliteral">"Ex"</font>, <font class="stringliteral">"Le"</font>, <font class="stringliteral">"Nu"</font>, <font class="stringliteral">"De"</font>, <font class="stringliteral">"Jos"</font>, <font class="stringliteral">"Jud"</font>, <font class="stringliteral">"Ru"</font>,
00142                 <font class="stringliteral">"1Sa"</font>, <font class="stringliteral">"2Sa"</font>, <font class="stringliteral">"1Ki"</font>, <font class="stringliteral">"2Ki"</font>, <font class="stringliteral">"1Ch"</font>, <font class="stringliteral">"2Ch"</font>, <font class="stringliteral">"Ezr"</font>, <font class="stringliteral">"Ne"</font>, <font class="stringliteral">"Es"</font>,
00143                 <font class="stringliteral">"Job"</font>, <font class="stringliteral">"Ps"</font>, <font class="stringliteral">"Pr"</font>, <font class="stringliteral">"Ec"</font>, <font class="stringliteral">"So"</font>, <font class="stringliteral">"Isa"</font>, <font class="stringliteral">"Jer"</font>, <font class="stringliteral">"La"</font>, <font class="stringliteral">"Eze"</font>, <font class="stringliteral">"Da"</font>,
00144                 <font class="stringliteral">"Ho"</font>, <font class="stringliteral">"Joe"</font>, <font class="stringliteral">"Am"</font>, <font class="stringliteral">"Ob"</font>, <font class="stringliteral">"Jon"</font>, <font class="stringliteral">"Mic"</font>, <font class="stringliteral">"Na"</font>, <font class="stringliteral">"Heb"</font>, <font class="stringliteral">"Zep"</font>,
00145                 <font class="stringliteral">"Hag"</font>, <font class="stringliteral">"Zec"</font>, <font class="stringliteral">"Mal"</font>,
00146                 <font class="stringliteral">"Mt"</font>, <font class="stringliteral">"Mr"</font>, <font class="stringliteral">"Lu"</font>, <font class="stringliteral">"Joh"</font>, <font class="stringliteral">"Ac"</font>, <font class="stringliteral">"Ro"</font>, <font class="stringliteral">"1Co"</font>, <font class="stringliteral">"2Co"</font>, <font class="stringliteral">"Ga"</font>,
00147                 <font class="stringliteral">"Eph"</font>, <font class="stringliteral">"Php"</font>, <font class="stringliteral">"Col"</font>, <font class="stringliteral">"1Th"</font>, <font class="stringliteral">"2Th"</font>, <font class="stringliteral">"1Ti"</font>, <font class="stringliteral">"2Ti"</font>, <font class="stringliteral">"Tit"</font>, <font class="stringliteral">"Phm"</font>,
00148                 <font class="stringliteral">"Heb"</font>, <font class="stringliteral">"Jas"</font>, <font class="stringliteral">"1Pe"</font>, <font class="stringliteral">"2Pe"</font>, <font class="stringliteral">"1Jo"</font>, <font class="stringliteral">"2Jo"</font>, <font class="stringliteral">"3Jo"</font>, <font class="stringliteral">"Jude"</font>, <font class="stringliteral">"Re"</font> };
00149 
00150         <font class="keywordflow">if</font> (++olbvnum &lt;= 31102) {
00151 
00152                 <font class="keywordflow">if</font> (olbvnum == 23146) { <font class="comment">// "Matthew 1:1"        </font>
00153                         close(vfp);
00154                         close(cfp);
00155                         close(bfp);
00156                         close(fp);
00157                         key1 = key2 = key3 = inckey = <font class="stringliteral">"Matthew 1:1"</font>;
00158                         openfiles();
00159                         startflag = 0;
00160                 }
00161 
00162 
00163                 *offset = lseek(fp, 0, SEEK_CUR);
00164 
00165                 <font class="keywordflow">if</font> ((olbvnum!=1) &amp;&amp; (olbvnum != 23146))
00166                         inckey++;
00167                         
00168                 *num1 = inckey.<a class="code" href="class_verse_key.html#a24">Chapter</a>();
00169                 *num2 = inckey.<a class="code" href="class_verse_key.html#a25">Verse</a>();
00170         
00171                 sprintf(data, <font class="stringliteral">"JFB%.2d.htm#%s%d_%d"</font>, inckey.<a class="code" href="class_verse_key.html#a23">Book</a>() + ((inckey.<a class="code" href="class_verse_key.html#a22">Testament</a>()&gt;1)?39:0), bookabrev[inckey.<a class="code" href="class_verse_key.html#a23">Book</a>() + ((inckey.<a class="code" href="class_verse_key.html#a22">Testament</a>()&gt;1)?39:0)-1], inckey.<a class="code" href="class_verse_key.html#a24">Chapter</a>(), inckey.<a class="code" href="class_verse_key.html#a25">Verse</a>());
00172                 write(fp, data, strlen(data));
00173 
00174                 *size = lseek(fp, 0, SEEK_CUR) - *offset;
00175                 write(fp, <font class="stringliteral">"\n"</font>, 1);
00176                 <font class="keywordflow">return</font> 0;
00177         }
00178         <font class="keywordflow">return</font> 1;
00179 }
00180 
00181 
00182 <font class="keywordtype">void</font> openfiles()
00183 {
00184         <font class="keywordtype">char</font> buf[255];
00185         <font class="keywordtype">char</font> fname[5];
00186         <font class="keywordtype">long</font> pos;
00187         <font class="keywordtype">short</font> size;
00188         
00189         testmnt = key1.<a class="code" href="class_verse_key.html#a22">Testament</a>();
00190 
00191         strcpy(fname, (testmnt==2) ? <font class="stringliteral">"nt"</font> : <font class="stringliteral">"ot"</font>);
00192         unlink(fname);
00193         <font class="keywordflow">if</font> ((fp = open(fname, O_CREAT|O_RDWR|O_BINARY)) == -1) {
00194                 fprintf(stderr, <font class="stringliteral">"Couldn't open file: %s\n"</font>, fname);
00195                 exit(1);
00196         }
00197 
00198         sprintf(buf, <font class="stringliteral">"%s.vss"</font>, fname);
00199         unlink(buf);
00200         <font class="keywordflow">if</font> ((vfp = open(buf, O_CREAT|O_WRONLY|O_BINARY)) == -1) {
00201                 fprintf(stderr, <font class="stringliteral">"Couldn't open file: %s\n"</font>, buf);
00202                 exit(1);
00203         }
00204 
00205         sprintf(buf, <font class="stringliteral">"%s.cps"</font>, fname);
00206         unlink(buf);
00207         <font class="keywordflow">if</font> ((cfp = open(buf, O_CREAT|O_WRONLY|O_BINARY)) == -1) {
00208                 fprintf(stderr, <font class="stringliteral">"Couldn't open file: %s\n"</font>, buf);
00209                 exit(1);
00210         }
00211 
00212         sprintf(buf, <font class="stringliteral">"%s.bks"</font>, fname);
00213         unlink(buf);
00214         <font class="keywordflow">if</font> ((bfp = open(buf, O_CREAT|O_WRONLY|O_BINARY)) == -1) {
00215                 fprintf(stderr, <font class="stringliteral">"Couldn't open file: %s\n"</font>, buf);
00216                 exit(1);
00217         }
00218 
00219         pos  = 0;
00220         write(bfp, &amp;pos, 4);  <font class="comment">/* Book    offset for testament intros */</font>
00221         pos = 4;
00222         write(cfp, &amp;pos, 4);  <font class="comment">/* Chapter offset for testament intro */</font>
00223 
00224 
00225 <font class="comment">/*      Right now just zero out intros until parsing correctly */</font>
00226         pos = 0;
00227         size = 0;
00228         write(vfp, &amp;pos, 4);  <font class="comment">/* Module intro */</font>
00229         write(vfp, &amp;size, 2);
00230         write(vfp, &amp;pos, 4);  <font class="comment">/* Testament intro */</font>
00231         write(vfp, &amp;size, 2);
00232 
00233 }
00234 
00235 
00236 <font class="keywordtype">void</font> checkparams(<font class="keywordtype">int</font> argc, <font class="keywordtype">char</font> **argv)
00237 {
00238         <font class="keywordflow">if</font> (argc !=1) {
00239                 fprintf(stderr, <font class="stringliteral">"usage: %s\n"</font>, argv[0]);
00240                 exit(1);
00241         }
00242 }
</pre></div><hr><address align="right"><small>Generated on Thu Jun 20 22:12:59 2002 for The Sword Project by
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border=0 
width=110 height=53></a>1.2.15 </small></address>
</body>
</html>