aboutsummaryrefslogtreecommitdiffstats
path: root/doc/api-documentation/html/rawfilesgen_8cpp-source.html
blob: 85badac0b98a5fdcac0749a3c7a612f3baf7f81c (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
<!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>rawfilesgen.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>rawfilesgen.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">"Created Empty Entry: %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                         size = 0;
00116                         write(vfp, &amp;size, 2);
00117                 }
00118                 <font class="keywordflow">else</font>    {
00119                         pos = 0;
00120                         tmp = 0;
00121                         write(vfp, &amp;pos, 4);
00122                         write(vfp, &amp;tmp, 2);
00123                 }
00124                 key1++;
00125 }
00126 
00127 
00128 <font class="keyword">static</font> <a class="code" href="class_verse_key.html">VerseKey</a> inckey = <font class="stringliteral">"Genesis 1:1"</font>;
00129 
00130 <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)
00131 {
00132         <font class="keywordtype">char</font> buf[7];
00133         <font class="keywordtype">char</font> buf2[20];
00134         <font class="keywordtype">char</font> ch;
00135         <font class="keywordtype">char</font> loop;
00136         <font class="keywordtype">long</font> offset2;
00137         <font class="keywordtype">int</font> ch2, vs2, rm2;
00138         <font class="keywordtype">bool</font> flag;
00139         <font class="keywordtype">long</font> chapstart = 0; 
00140         <font class="keyword">static</font> <font class="keywordtype">int</font> olbvnum = 0;
00141         <font class="keywordtype">char</font> data[16];
00142 
00143         memset (data,0,16);
00144 
00145         <font class="keywordflow">if</font> (++olbvnum &lt;= 31102) {
00146 
00147                 <font class="keywordflow">if</font> (olbvnum == 23146) { <font class="comment">// "Matthew 1:1"        </font>
00148                         close(vfp);
00149                         close(cfp);
00150                         close(bfp);
00151                         close(fp);
00152                         key1 = key2 = key3 = inckey = <font class="stringliteral">"Matthew 1:1"</font>;
00153                         openfiles();
00154                         startflag = 0;
00155                 }
00156 
00157 
00158                 *offset = lseek(fp, 0, SEEK_CUR);
00159 
00160                 <font class="keywordflow">if</font> ((olbvnum!=1) &amp;&amp; (olbvnum != 23146))
00161                         inckey++;
00162                         
00163                 *num1 = inckey.<a class="code" href="class_verse_key.html#a24">Chapter</a>();
00164                 *num2 = inckey.<a class="code" href="class_verse_key.html#a25">Verse</a>();
00165         
00166                 
00167                 write(fp, data, 16);
00168 
00169                 *size = lseek(fp, 0, SEEK_CUR) - *offset;
00170                 <font class="keywordflow">return</font> 0;
00171         }
00172         <font class="keywordflow">return</font> 1;
00173 }
00174 
00175 
00176 <font class="keywordtype">void</font> openfiles()
00177 {
00178         <font class="keywordtype">char</font> buf[255];
00179         <font class="keywordtype">char</font> fname[5];
00180         <font class="keywordtype">long</font> pos;
00181         <font class="keywordtype">short</font> size;
00182         
00183         testmnt = key1.<a class="code" href="class_verse_key.html#a22">Testament</a>();
00184 
00185         strcpy(fname, (testmnt==2) ? <font class="stringliteral">"nt"</font> : <font class="stringliteral">"ot"</font>);
00186         unlink(fname);
00187         <font class="keywordflow">if</font> ((fp = open(fname, O_CREAT|O_RDWR|O_BINARY)) == -1) {
00188                 fprintf(stderr, <font class="stringliteral">"Couldn't open file: %s\n"</font>, fname);
00189                 exit(1);
00190         }
00191 
00192         sprintf(buf, <font class="stringliteral">"%s.vss"</font>, fname);
00193         unlink(buf);
00194         <font class="keywordflow">if</font> ((vfp = open(buf, O_CREAT|O_WRONLY|O_BINARY)) == -1) {
00195                 fprintf(stderr, <font class="stringliteral">"Couldn't open file: %s\n"</font>, buf);
00196                 exit(1);
00197         }
00198 
00199         sprintf(buf, <font class="stringliteral">"%s.cps"</font>, fname);
00200         unlink(buf);
00201         <font class="keywordflow">if</font> ((cfp = open(buf, O_CREAT|O_WRONLY|O_BINARY)) == -1) {
00202                 fprintf(stderr, <font class="stringliteral">"Couldn't open file: %s\n"</font>, buf);
00203                 exit(1);
00204         }
00205 
00206         sprintf(buf, <font class="stringliteral">"%s.bks"</font>, fname);
00207         unlink(buf);
00208         <font class="keywordflow">if</font> ((bfp = open(buf, O_CREAT|O_WRONLY|O_BINARY)) == -1) {
00209                 fprintf(stderr, <font class="stringliteral">"Couldn't open file: %s\n"</font>, buf);
00210                 exit(1);
00211         }
00212 
00213         pos  = 0;
00214         write(bfp, &amp;pos, 4);  <font class="comment">/* Book    offset for testament intros */</font>
00215         pos = 4;
00216         write(cfp, &amp;pos, 4);  <font class="comment">/* Chapter offset for testament intro */</font>
00217 
00218 
00219 <font class="comment">/*      Right now just zero out intros until parsing correctly */</font>
00220         pos = 0;
00221         size = 0;
00222         write(vfp, &amp;pos, 4);  <font class="comment">/* Module intro */</font>
00223         write(vfp, &amp;size, 2);
00224         write(vfp, &amp;pos, 4);  <font class="comment">/* Testament intro */</font>
00225         write(vfp, &amp;size, 2);
00226 
00227 }
00228 
00229 
00230 <font class="keywordtype">void</font> checkparams(<font class="keywordtype">int</font> argc, <font class="keywordtype">char</font> **argv)
00231 {
00232         <font class="keywordflow">if</font> (argc !=1) {
00233                 fprintf(stderr, <font class="stringliteral">"usage: %s\n"</font>, argv[0]);
00234                 exit(1);
00235         }
00236 }
</pre></div><hr><address align="right"><small>Generated on Thu Jun 20 22:13:00 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>