Sophie

Sophie

distrib > Mandriva > 9.1 > ppc > by-pkgid > a74ec78bdb789d910d054e3918f3f007 > files > 516

libsword1-devel-1.5.5-2mdk.ppc.rpm

<!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>rtfidx.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>rtfidx.cpp</h1><div class="fragment"><pre>00001 <font class="preprocessor">#include &lt;stdio.h&gt;</font>
00002 <font class="preprocessor">#include &lt;fcntl.h&gt;</font>
00003 <font class="preprocessor">#include &lt;versekey.h&gt;</font>
00004 
00005 
00006 <font class="keywordtype">char</font> findbreak(<font class="keywordtype">int</font> fp, <font class="keywordtype">int</font> *offset, <font class="keywordtype">int</font> *num1, <font class="keywordtype">int</font> *num2, <font class="keywordtype">short</font> *size);
00007 
00008 
00009 main(<font class="keywordtype">int</font> argc, <font class="keywordtype">char</font> **argv)
00010 {
00011         <font class="keywordtype">int</font> fp, vfp, cfp, bfp;
00012         <font class="keywordtype">long</font> pos;
00013         <font class="keywordtype">short</font> size, tmp;
00014         <font class="keywordtype">int</font> num1, num2, offset, curbook = 0, curchap = 0, curverse = 0;
00015         <font class="keywordtype">char</font> buf[127];
00016         <a class="code" href="class_verse_key.html">VerseKey</a> mykey;
00017 
00018         <font class="keywordflow">if</font> ((argc &lt; 2) || (argc &gt; 3)) {
00019                 fprintf(stderr, <font class="stringliteral">"usage: %s &lt;file to process&gt; [nt]\n"</font>, argv[0]);
00020                 exit(1);
00021         }
00022 
00023         <font class="keywordflow">if</font> ((fp = open(argv[1], O_RDONLY)) == -1) {
00024                 fprintf(stderr, <font class="stringliteral">"Couldn't open file: %s\n"</font>, argv[1]);
00025                 exit(1);
00026         }
00027 
00028         sprintf(buf, <font class="stringliteral">"%s.vss"</font>, argv[1]);
00029         <font class="keywordflow">if</font> ((vfp = open(buf, O_CREAT|O_WRONLY)) == -1) {
00030                 fprintf(stderr, <font class="stringliteral">"Couldn't open file: %s\n"</font>, buf);
00031                 exit(1);
00032         }
00033 
00034         sprintf(buf, <font class="stringliteral">"%s.cps"</font>, argv[1]);
00035         <font class="keywordflow">if</font> ((cfp = open(buf, O_CREAT|O_WRONLY)) == -1) {
00036                 fprintf(stderr, <font class="stringliteral">"Couldn't open file: %s\n"</font>, buf);
00037                 exit(1);
00038         }
00039 
00040         sprintf(buf, <font class="stringliteral">"%s.bks"</font>, argv[1]);
00041         <font class="keywordflow">if</font> ((bfp = open(buf, O_CREAT|O_WRONLY)) == -1) {
00042                 fprintf(stderr, <font class="stringliteral">"Couldn't open file: %s\n"</font>, buf);
00043                 exit(1);
00044         }
00045 
00046         pos  = 0;
00047         write(bfp, &amp;pos, 4);  <font class="comment">/* Book    offset for testament intros */</font>
00048         pos = 4;
00049         write(cfp, &amp;pos, 4);  <font class="comment">/* Chapter offset for testament intro */</font>
00050 
00051 
00052 <font class="comment">/*      Right now just zero out intros until parsing correctly */</font>
00053         pos = 0;
00054         size = 0;
00055         write(vfp, &amp;pos, 4);  <font class="comment">/* Module intro */</font>
00056         write(vfp, &amp;size, 2);
00057         write(vfp, &amp;pos, 4);  <font class="comment">/* Testament intro */</font>
00058         write(vfp, &amp;size, 2);
00059 
00060         mykey = (argc == 3) ? <font class="stringliteral">"Matthew 1:1"</font> : <font class="stringliteral">"Genesis 1:1"</font>;
00061 
00062         <font class="keywordflow">while</font> (!findbreak(fp, &amp;offset, &amp;num1, &amp;num2, &amp;size)) {
00063                 num1 = mykey.<a class="code" href="class_verse_key.html#a24">Chapter</a>();
00064                 num2 = mykey.<a class="code" href="class_verse_key.html#a25">Verse</a>();
00065                 <font class="keywordflow">if</font> (num2 == 1) {                <font class="comment">/* if we're at a new chapter */</font>
00066                         <font class="keywordflow">if</font> (num1 == 1) {        <font class="comment">/* if we're at a new book */</font>
00067                                 pos = lseek(cfp, 0, SEEK_CUR);
00068                                 write(bfp, &amp;pos, 4);
00069                                 pos = lseek(vfp, 0, SEEK_CUR); <font class="comment">/* Book intro (cps) */</font>
00070                                 write(cfp, &amp;pos, 4);
00071                                 pos  = 0;
00072                                 tmp = 0;
00073                                 write(vfp, &amp;pos, 4);  <font class="comment">/* Book intro (vss) */</font>
00074                                 write(vfp, &amp;tmp, 2);
00075                                 curbook++;
00076                                 curchap = 0;
00077                         }
00078                         pos = lseek(vfp, 0, SEEK_CUR);
00079                         write(cfp, &amp;pos, 4);
00080                         curverse = 1;
00081                         pos  = 0;
00082                         tmp = 0;
00083                         write(vfp, &amp;pos, 4);  <font class="comment">/* Chapter intro */</font>
00084                         write(vfp, &amp;tmp, 2);
00085                         curchap++;
00086                 }
00087                 <font class="keywordflow">else</font> curverse++;
00088         
00089                 printf(<font class="stringliteral">"%2d:%3d:%3d found at offset: %7d\n"</font>, curbook, num1, num2, offset);
00090 
00091                 <font class="keywordflow">if</font> (num1 != curchap) {
00092                         fprintf(stderr, <font class="stringliteral">"Error: Found chaptures out of sequence\n"</font>);
00093                         <font class="keywordflow">break</font>;
00094                 }
00095                 <font class="keywordflow">if</font> (num2 != curverse) {
00096                         fprintf(stderr, <font class="stringliteral">"Error: Found verses out of sequence\n"</font>);
00097                         <font class="keywordflow">break</font>;
00098                 }
00099                 write(vfp, &amp;offset, 4);
00100                 write(vfp, &amp;size, 2);
00101                 mykey++;
00102         }
00103         
00104         close(vfp);
00105         close(cfp);
00106         close(bfp);
00107         close(fp);
00108 }
00109 
00110 
00111 <font class="keywordtype">char</font> findbreak(<font class="keywordtype">int</font> fp, <font class="keywordtype">int</font> *offset, <font class="keywordtype">int</font> *num1, <font class="keywordtype">int</font> *num2, <font class="keywordtype">short</font> *size)
00112 {
00113         <font class="keywordtype">char</font> buf[17];
00114         <font class="keywordtype">char</font> buf2[7];
00115         <font class="keywordtype">char</font> loop;
00116         <font class="keywordtype">char</font> offadj, inquotes, sizeadj;
00117         <font class="keywordtype">int</font> offset2, ch2, vs2;
00118         
00119         memset(buf, <font class="charliteral">' '</font>, 17);
00120 
00121         <font class="keywordflow">while</font> (1) {
00122                 offadj = -10;
00123                 inquotes = 0;
00124                 sizeadj = 0;
00125                 <font class="keywordflow">if</font> (!memcmp(&amp;buf[1], <font class="stringliteral">"\\f0\\fs16\\cf2\\up6"</font>, 15)) {
00126                         offadj = 0;
00127                         inquotes = 1;
00128                         sizeadj = (*buf == 10) ? -19:-17;
00129                 }
00130                 <font class="keywordflow">if</font> (!memcmp(buf, <font class="stringliteral">"\\fi200\\widctlpar"</font>, 16)) {
00131                         offadj = -1;
00132 <font class="comment">//                      inquotes = 1;</font>
00133                         sizeadj = -18;
00134                 }
00135                 <font class="keywordflow">if</font> (offadj &gt; -10) {
00136                         *offset = lseek(fp, 0, SEEK_CUR) + offadj;
00137                         <font class="keywordflow">if</font> (size) {
00138                                 (*offset)++;
00139                                 <font class="keywordflow">while</font> (inquotes) {
00140                                         <font class="keywordflow">while</font> (read(fp, buf2, 1) == 1) {
00141                                                 <font class="keywordflow">if</font> (*buf2 == <font class="charliteral">'}'</font>)
00142                                                         <font class="keywordflow">break</font>;
00143                                                 (*offset)++;
00144                                         }
00145                                         inquotes--;
00146                                 }
00147                                 <font class="keywordflow">if</font> (findbreak(fp, &amp;offset2, &amp;ch2, &amp;vs2, 0)) {
00148                                         *size = (short) (lseek(fp, 0, SEEK_END) - (*offset));
00149                                 }
00150                                 <font class="keywordflow">else</font> {
00151                                         sprintf(buf2, <font class="stringliteral">"%d:%d"</font>, ch2, vs2);
00152                                         *size = (offset2 - (*offset));
00153                                 }
00154                                 lseek(fp, *offset+17, SEEK_SET);
00155                         }
00156                         <font class="keywordflow">else</font> (*offset) += sizeadj;
00157                         <font class="keywordflow">return</font> 0;
00158                 }
00159                 memmove(buf, &amp;buf[1], 16);
00160                 <font class="keywordflow">if</font> (read(fp, &amp;buf[16], 1) != 1)
00161                         <font class="keywordflow">return</font> 1;
00162         }
00163 }
00164 
</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>