<!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>rawstr.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> <a class="qindex" href="namespaces.html">Namespace List</a> <a class="qindex" href="hierarchy.html">Class Hierarchy</a> <a class="qindex" href="classes.html">Alphabetical List</a> <a class="qindex" href="annotated.html">Compound List</a> <a class="qindex" href="files.html">File List</a> <a class="qindex" href="functions.html">Compound Members</a> </center>
<hr><h1>rawstr.cpp</h1><div class="fragment"><pre>00001 <font class="comment">/******************************************************************************</font>
00002 <font class="comment"> * rawstr.cpp - code for class 'RawStr'- a module that reads raw text</font>
00003 <font class="comment"> * files: ot and nt using indexs ??.bks ??.cps ??.vss</font>
00004 <font class="comment"> * and provides lookup and parsing functions based on</font>
00005 <font class="comment"> * class StrKey</font>
00006 <font class="comment"> */</font>
00007
00008
00009 <font class="preprocessor">#include <stdio.h></font>
00010 <font class="preprocessor">#include <fcntl.h></font>
00011 <font class="preprocessor">#include <errno.h></font>
00012
00013 <font class="preprocessor">#ifndef __GNUC__</font>
00014 <font class="preprocessor"></font><font class="preprocessor">#include <io.h></font>
00015 <font class="preprocessor">#else</font>
00016 <font class="preprocessor"></font><font class="preprocessor">#include <unistd.h></font>
00017 <font class="preprocessor">#endif</font>
00018 <font class="preprocessor"></font>
00019 <font class="preprocessor">#include <string.h></font>
00020 <font class="preprocessor">#include <stdlib.h></font>
00021 <font class="preprocessor">#include <utilfuns.h></font>
00022 <font class="preprocessor">#include <rawstr.h></font>
00023 <font class="preprocessor">#include <sysdata.h></font>
00024 <font class="comment">/******************************************************************************</font>
00025 <font class="comment"> * RawStr Statics</font>
00026 <font class="comment"> */</font>
00027
00028 <font class="keywordtype">int</font> RawStr::instance = 0;
00029 <font class="keywordtype">char</font> RawStr::nl = <font class="charliteral">'\n'</font>;
00030
00031
00032 <font class="comment">/******************************************************************************</font>
00033 <font class="comment"> * RawStr Constructor - Initializes data for instance of RawStr</font>
00034 <font class="comment"> *</font>
00035 <font class="comment"> * ENT: ipath - path of the directory where data and index files are located.</font>
00036 <font class="comment"> * be sure to include the trailing separator (e.g. '/' or '\')</font>
00037 <font class="comment"> * (e.g. 'modules/texts/rawtext/webster/')</font>
00038 <font class="comment"> */</font>
00039
00040 RawStr::RawStr(<font class="keyword">const</font> <font class="keywordtype">char</font> *ipath, <font class="keywordtype">int</font> fileMode)
00041 {
00042 <font class="keywordtype">char</font> buf[127];
00043
00044 lastoff = -1;
00045 path = 0;
00046 stdstr(&path, ipath);
00047
00048 <font class="preprocessor">#ifndef O_BINARY // O_BINARY is needed in Borland C++ 4.53</font>
00049 <font class="preprocessor"></font><font class="preprocessor">#define O_BINARY 0 // If it hasn't been defined than we probably</font>
00050 <font class="preprocessor"></font><font class="preprocessor">#endif // don't need it.</font>
00051 <font class="preprocessor"></font>
00052 <font class="keywordflow">if</font> (fileMode == -1) { <font class="comment">// try read/write if possible</font>
00053 fileMode = O_RDWR;
00054 }
00055
00056 sprintf(buf, <font class="stringliteral">"%s.idx"</font>, path);
00057 idxfd = FileMgr::systemFileMgr.open(buf, fileMode|O_BINARY, <font class="keyword">true</font>);
00058
00059 sprintf(buf, <font class="stringliteral">"%s.dat"</font>, path);
00060 datfd = FileMgr::systemFileMgr.open(buf, fileMode|O_BINARY, <font class="keyword">true</font>);
00061
00062 <font class="keywordflow">if</font> (datfd < 0) {
00063 sprintf(buf, <font class="stringliteral">"Error: %d"</font>, errno);
00064 perror(buf);
00065 }
00066
00067 instance++;
00068 }
00069
00070
00071 <font class="comment">/******************************************************************************</font>
00072 <font class="comment"> * RawStr Destructor - Cleans up instance of RawStr</font>
00073 <font class="comment"> */</font>
00074
00075 RawStr::~RawStr()
00076 {
00077 <font class="keywordflow">if</font> (path)
00078 <font class="keyword">delete</font> [] path;
00079
00080 --instance;
00081
00082 FileMgr::systemFileMgr.close(idxfd);
00083 FileMgr::systemFileMgr.close(datfd);
00084 }
00085
00086
00087 <font class="comment">/******************************************************************************</font>
00088 <font class="comment"> * RawStr::getidxbufdat - Gets the index string at the given idx offset</font>
00089 <font class="comment"> * NOTE: buf is allocated and must be freed by</font>
00090 <font class="comment"> * calling function</font>
00091 <font class="comment"> *</font>
00092 <font class="comment"> * ENT: ioffset - offset in dat file to lookup</font>
00093 <font class="comment"> * buf - address of pointer to allocate for storage of string</font>
00094 <font class="comment"> */</font>
00095
00096 <font class="keywordtype">void</font> RawStr::getidxbufdat(<font class="keywordtype">long</font> ioffset, <font class="keywordtype">char</font> **buf)
00097 {
00098 <font class="keywordtype">int</font> size;
00099 <font class="keywordtype">char</font> ch;
00100 <font class="keywordflow">if</font> (datfd > 0) {
00101 lseek(datfd->getFd(), ioffset, SEEK_SET);
00102 <font class="keywordflow">for</font> (size = 0; read(datfd->getFd(), &ch, 1) == 1; size++) {
00103 <font class="keywordflow">if</font> ((ch == <font class="charliteral">'\\'</font>) || (ch == 10) || (ch == 13))
00104 <font class="keywordflow">break</font>;
00105 }
00106 *buf = (*buf) ? (<font class="keywordtype">char</font> *)realloc(*buf, size + 1) : (char *)malloc(size + 1);
00107 <font class="keywordflow">if</font> (size) {
00108 lseek(datfd->getFd(), ioffset, SEEK_SET);
00109 read(datfd->getFd(), *buf, size);
00110 }
00111 (*buf)[size] = 0;
00112 <font class="keywordflow">for</font> (size--; size > 0; size--)
00113 (*buf)[size] = SW_toupper((*buf)[size]);
00114 }
00115 <font class="keywordflow">else</font> {
00116 *buf = (*buf) ? (<font class="keywordtype">char</font> *)realloc(*buf, 1) : (char *)malloc(1);
00117 **buf = 0;
00118 }
00119 }
00120
00121
00122 <font class="comment">/******************************************************************************</font>
00123 <font class="comment"> * RawStr::getidxbuf - Gets the index string at the given idx offset</font>
00124 <font class="comment"> * NOTE: buf is allocated and must be freed by</font>
00125 <font class="comment"> * calling function</font>
00126 <font class="comment"> *</font>
00127 <font class="comment"> * ENT: ioffset - offset in idx file to lookup</font>
00128 <font class="comment"> * buf - address of pointer to allocate for storage of string</font>
00129 <font class="comment"> */</font>
00130
00131 <font class="keywordtype">void</font> RawStr::getidxbuf(<font class="keywordtype">long</font> ioffset, <font class="keywordtype">char</font> **buf)
00132 {
00133 <font class="keywordtype">char</font> *trybuf, *targetbuf;
00134 <font class="keywordtype">long</font> offset;
00135
00136 <font class="keywordflow">if</font> (idxfd > 0) {
00137 lseek(idxfd->getFd(), ioffset, SEEK_SET);
00138 read(idxfd->getFd(), &offset, 4);
00139
00140 offset = swordtoarch32(offset);
00141
00142 getidxbufdat(offset, buf);
00143 <font class="keywordflow">for</font> (trybuf = targetbuf = *buf; *trybuf; trybuf++, targetbuf++) {
00144 <font class="comment">/*</font>
00145 <font class="comment"> if (*trybuf == '-') { // ignore '-' because alphabetized silly in file</font>
00146 <font class="comment"> targetbuf--;</font>
00147 <font class="comment"> continue;</font>
00148 <font class="comment"> }</font>
00149 <font class="comment">*/</font>
00150 *targetbuf = SW_toupper(*trybuf);
00151 }
00152 *targetbuf = 0;
00153 trybuf = 0;
00154 }
00155 }
00156
00157
00158 <font class="comment">/******************************************************************************</font>
00159 <font class="comment"> * RawStr::findoffset - Finds the offset of the key string from the indexes</font>
00160 <font class="comment"> *</font>
00161 <font class="comment"> * ENT: key - key string to lookup</font>
00162 <font class="comment"> * start - address to store the starting offset</font>
00163 <font class="comment"> * size - address to store the size of the entry</font>
00164 <font class="comment"> * away - number of entries before of after to jump</font>
00165 <font class="comment"> * (default = 0)</font>
00166 <font class="comment"> *</font>
00167 <font class="comment"> * RET: error status</font>
00168 <font class="comment"> */</font>
00169
00170 <font class="keywordtype">signed</font> <font class="keywordtype">char</font> RawStr::findoffset(<font class="keyword">const</font> <font class="keywordtype">char</font> *ikey, <font class="keywordtype">long</font> *start, <font class="keywordtype">unsigned</font> <font class="keywordtype">short</font> *size, <font class="keywordtype">long</font> away, <font class="keywordtype">long</font> *idxoff)
00171 {
00172 <font class="keywordtype">char</font> *trybuf, *targetbuf, *key, quitflag = 0;
00173 <font class="keywordtype">signed</font> <font class="keywordtype">char</font> retval = 0;
00174 <font class="keywordtype">long</font> headoff, tailoff, tryoff = 0, maxoff = 0;
00175
00176 <font class="keywordflow">if</font> (idxfd->getFd() >=0) {
00177 tailoff = maxoff = lseek(idxfd->getFd(), 0, SEEK_END) - 6;
00178 <font class="keywordflow">if</font> (*ikey) {
00179 headoff = 0;
00180
00181 key = <font class="keyword">new</font> <font class="keywordtype">char</font> [ strlen(ikey) + 1 ];
00182 strcpy(key, ikey);
00183
00184 <font class="keywordflow">for</font> (trybuf = targetbuf = key; *trybuf; trybuf++, targetbuf++) {
00185 <font class="comment">/*</font>
00186 <font class="comment"> if (*trybuf == '-') { // ignore '-' because alphabetized silly in file</font>
00187 <font class="comment"> targetbuf--;</font>
00188 <font class="comment"> continue;</font>
00189 <font class="comment"> }</font>
00190 <font class="comment"> */</font>
00191 *targetbuf = SW_toupper(*trybuf);
00192 }
00193 *targetbuf = 0;
00194 trybuf = 0;
00195
00196 <font class="keywordflow">while</font> (headoff < tailoff) {
00197 tryoff = (lastoff == -1) ? headoff + ((((tailoff / 6) - (headoff / 6))) / 2) * 6 : lastoff;
00198 lastoff = -1;
00199 getidxbuf(tryoff, &trybuf);
00200
00201 <font class="keywordflow">if</font> (!*trybuf && tryoff) { <font class="comment">// In case of extra entry at end of idx (not first entry)</font>
00202 tryoff += (tryoff > (maxoff / 2))?-6:6;
00203 retval = -1;
00204 <font class="keywordflow">break</font>;
00205 }
00206
00207 <font class="keywordflow">if</font> (!strcmp(key, trybuf))
00208 <font class="keywordflow">break</font>;
00209
00210 <font class="keywordtype">int</font> diff = strcmp(key, trybuf);
00211 <font class="keywordflow">if</font> (diff < 0)
00212 tailoff = (tryoff == headoff) ? headoff : tryoff;
00213 <font class="keywordflow">else</font> headoff = tryoff;
00214 <font class="keywordflow">if</font> (tailoff == headoff + 6) {
00215 <font class="keywordflow">if</font> (quitflag++)
00216 headoff = tailoff;
00217 }
00218 }
00219 <font class="keywordflow">if</font> (headoff >= tailoff)
00220 tryoff = headoff;
00221 <font class="keywordflow">if</font> (trybuf)
00222 free(trybuf);
00223 <font class="keyword">delete</font> [] key;
00224 }
00225 <font class="keywordflow">else</font> tryoff = 0;
00226
00227 lseek(idxfd->getFd(), tryoff, SEEK_SET);
00228
00229 *start = *size = 0;
00230 read(idxfd->getFd(), start, 4);
00231 read(idxfd->getFd(), size, 2);
00232 <font class="keywordflow">if</font> (idxoff)
00233 *idxoff = tryoff;
00234
00235 *start = swordtoarch32(*start);
00236 *size = swordtoarch16(*size);
00237
00238 <font class="keywordflow">while</font> (away) {
00239 <font class="keywordtype">long</font> laststart = *start;
00240 <font class="keywordtype">unsigned</font> <font class="keywordtype">short</font> lastsize = *size;
00241 <font class="keywordtype">long</font> lasttry = tryoff;
00242 tryoff += (away > 0) ? 6 : -6;
00243
00244 <font class="keywordtype">bool</font> bad = <font class="keyword">false</font>;
00245 <font class="keywordflow">if</font> (((tryoff + (away*6)) < -6) || (tryoff + (away*6) > (maxoff+6)))
00246 bad = <font class="keyword">true</font>;
00247 <font class="keywordflow">else</font> <font class="keywordflow">if</font> (lseek(idxfd->getFd(), tryoff, SEEK_SET) < 0)
00248 bad = <font class="keyword">true</font>;
00249 <font class="keywordflow">if</font> (bad) {
00250 retval = -1;
00251 *start = laststart;
00252 *size = lastsize;
00253 tryoff = lasttry;
00254 <font class="keywordflow">if</font> (idxoff)
00255 *idxoff = tryoff;
00256 <font class="keywordflow">break</font>;
00257 }
00258 read(idxfd->getFd(), start, 4);
00259 read(idxfd->getFd(), size, 2);
00260 <font class="keywordflow">if</font> (idxoff)
00261 *idxoff = tryoff;
00262
00263 *start = swordtoarch32(*start);
00264 *size = swordtoarch16(*size);
00265
00266 <font class="keywordflow">if</font> (((laststart != *start) || (lastsize != *size)) && (*start >= 0) && (*size))
00267 away += (away < 0) ? 1 : -1;
00268 }
00269
00270 lastoff = tryoff;
00271 }
00272 <font class="keywordflow">else</font> {
00273 *start = 0;
00274 *size = 0;
00275 <font class="keywordflow">if</font> (idxoff)
00276 *idxoff = 0;
00277 retval = -1;
00278 }
00279 <font class="keywordflow">return</font> retval;
00280 }
00281
00282
00283 <font class="comment">/******************************************************************************</font>
00284 <font class="comment"> * RawStr::preptext - Prepares the text before returning it to external</font>
00285 <font class="comment"> * objects</font>
00286 <font class="comment"> *</font>
00287 <font class="comment"> * ENT: buf - buffer where text is stored and where to store the prep'd</font>
00288 <font class="comment"> * text.</font>
00289 <font class="comment"> */</font>
00290
00291 <font class="keywordtype">void</font> RawStr::preptext(<font class="keywordtype">char</font> *buf) {
00292 <font class="keywordtype">char</font> *to, *from, space = 0, cr = 0, realdata = 0, nlcnt = 0;
00293
00294 <font class="keywordflow">for</font> (to = from = buf; *from; from++) {
00295 <font class="keywordflow">switch</font> (*from) {
00296 <font class="keywordflow">case</font> 10:
00297 <font class="keywordflow">if</font> (!realdata)
00298 <font class="keywordflow">continue</font>;
00299 space = (cr) ? 0 : 1;
00300 cr = 0;
00301 nlcnt++;
00302 <font class="keywordflow">if</font> (nlcnt > 1) {
00303 <font class="comment">// *to++ = nl;</font>
00304 *to++ = nl;
00305 <font class="comment">// nlcnt = 0;</font>
00306 }
00307 <font class="keywordflow">continue</font>;
00308 <font class="keywordflow">case</font> 13:
00309 <font class="keywordflow">if</font> (!realdata)
00310 <font class="keywordflow">continue</font>;
00311 *to++ = nl;
00312 space = 0;
00313 cr = 1;
00314 <font class="keywordflow">continue</font>;
00315 }
00316 realdata = 1;
00317 nlcnt = 0;
00318 <font class="keywordflow">if</font> (space) {
00319 space = 0;
00320 <font class="keywordflow">if</font> (*from != <font class="charliteral">' '</font>) {
00321 *to++ = <font class="charliteral">' '</font>;
00322 from--;
00323 <font class="keywordflow">continue</font>;
00324 }
00325 }
00326 *to++ = *from;
00327 }
00328 *to = 0;
00329
00330 <font class="keywordflow">while</font> (to > (buf+1)) { <font class="comment">// remove trailing excess</font>
00331 to--;
00332 <font class="keywordflow">if</font> ((*to == 10) || (*to == <font class="charliteral">' '</font>))
00333 *to = 0;
00334 <font class="keywordflow">else</font> <font class="keywordflow">break</font>;
00335 }
00336 }
00337
00338
00339 <font class="comment">/******************************************************************************</font>
00340 <font class="comment"> * RawStr::gettext - gets text at a given offset</font>
00341 <font class="comment"> *</font>
00342 <font class="comment"> * ENT:</font>
00343 <font class="comment"> * start - starting offset where the text is located in the file</font>
00344 <font class="comment"> * size - size of text entry</font>
00345 <font class="comment"> * buf - buffer to store text</font>
00346 <font class="comment"> *</font>
00347 <font class="comment"> */</font>
00348
00349 <font class="keywordtype">void</font> RawStr::gettext(<font class="keywordtype">long</font> istart, <font class="keywordtype">unsigned</font> <font class="keywordtype">short</font> isize, <font class="keywordtype">char</font> *idxbuf, <font class="keywordtype">char</font> *buf)
00350 {
00351 <font class="keywordtype">char</font> *ch;
00352 <font class="keywordtype">char</font> *idxbuflocal = 0;
00353 getidxbufdat(istart, &idxbuflocal);
00354 <font class="keywordtype">long</font> start = istart;
00355 <font class="keywordtype">unsigned</font> <font class="keywordtype">short</font> size = isize;
00356
00357 <font class="keywordflow">do</font> {
00358 memset(buf, 0, size);
00359 lseek(datfd->getFd(), start, SEEK_SET);
00360 read(datfd->getFd(), buf, (int)(size - 2));
00361
00362 <font class="keywordflow">for</font> (ch = buf; *ch; ch++) { <font class="comment">// skip over index string</font>
00363 <font class="keywordflow">if</font> (*ch == 10) {
00364 ch++;
00365 <font class="keywordflow">break</font>;
00366 }
00367 }
00368 size -= (<font class="keywordtype">unsigned</font> <font class="keywordtype">short</font>)(ch-buf);
00369 memmove(buf, ch, size);
00370 buf[size] = 0;
00371 buf[size+1] = 0;
00372
00373 <font class="comment">// resolve link</font>
00374 <font class="keywordflow">if</font> (!strncmp(buf, <font class="stringliteral">"@LINK"</font>, 5)) {
00375 <font class="keywordflow">for</font> (ch = buf; *ch; ch++) { <font class="comment">// null before nl</font>
00376 <font class="keywordflow">if</font> (*ch == 10) {
00377 *ch = 0;
00378 <font class="keywordflow">break</font>;
00379 }
00380 }
00381 findoffset(buf + 6, &start, &size);
00382 <font class="comment">// TODO: FIX! THIS IS WRONG!!! buf is not reallocated for the appropriate size!</font>
00383 }
00384 <font class="keywordflow">else</font> <font class="keywordflow">break</font>;
00385 }
00386 <font class="keywordflow">while</font> (true); <font class="comment">// while we're resolving links</font>
00387
00388 <font class="keywordflow">if</font> (idxbuflocal) {
00389 <font class="keywordtype">int</font> localsize = strlen(idxbuflocal);
00390 localsize = (localsize < (size - 1)) ? localsize : (size - 1);
00391 strncpy(idxbuf, idxbuflocal, localsize);
00392 idxbuf[localsize] = 0;
00393 free(idxbuflocal);
00394 }
00395 }
00396
00397
00398 <font class="comment">/******************************************************************************</font>
00399 <font class="comment"> * RawLD::settext - Sets text for current offset</font>
00400 <font class="comment"> *</font>
00401 <font class="comment"> * ENT: key - key for this entry</font>
00402 <font class="comment"> * buf - buffer to store</font>
00403 <font class="comment"> * len - length of buffer (0 - null terminated)</font>
00404 <font class="comment"> */</font>
00405
00406 <font class="keywordtype">void</font> RawStr::settext(<font class="keyword">const</font> <font class="keywordtype">char</font> *ikey, <font class="keyword">const</font> <font class="keywordtype">char</font> *buf, <font class="keywordtype">long</font> len)
00407 {
00408
00409 <font class="keywordtype">long</font> start, outstart;
00410 <font class="keywordtype">long</font> idxoff;
00411 <font class="keywordtype">long</font> endoff;
00412 <font class="keywordtype">long</font> shiftSize;
00413 <font class="keywordtype">unsigned</font> <font class="keywordtype">short</font> size;
00414 <font class="keywordtype">unsigned</font> <font class="keywordtype">short</font> outsize;
00415 <font class="keyword">static</font> <font class="keyword">const</font> <font class="keywordtype">char</font> nl[] = {13, 10};
00416 <font class="keywordtype">char</font> *tmpbuf = 0;
00417 <font class="keywordtype">char</font> *key = 0;
00418 <font class="keywordtype">char</font> *dbKey = 0;
00419 <font class="keywordtype">char</font> *idxBytes = 0;
00420 <font class="keywordtype">char</font> *outbuf = 0;
00421 <font class="keywordtype">char</font> *ch = 0;
00422
00423 findoffset(ikey, &start, &size, 0, &idxoff);
00424 stdstr(&key, ikey);
00425 <font class="keywordflow">for</font> (ch = key; *ch; ch++)
00426 *ch = SW_toupper(*ch);
00427 ch = 0;
00428
00429 getidxbufdat(start, &dbKey);
00430
00431 <font class="keywordflow">if</font> (strcmp(key, dbKey) < 0) {
00432 }
00433 <font class="keywordflow">else</font> <font class="keywordflow">if</font> (strcmp(key, dbKey) > 0) {
00434 idxoff += 6;
00435 } <font class="keywordflow">else</font> <font class="keywordflow">if</font> ((!strcmp(key, dbKey)) && (len || strlen(buf) <font class="comment">/*we're not deleting*/</font>)) { <font class="comment">// got absolute entry</font>
00436 <font class="keywordflow">do</font> {
00437 tmpbuf = <font class="keyword">new</font> <font class="keywordtype">char</font> [ size + 2 ];
00438 memset(tmpbuf, 0, size + 2);
00439 lseek(datfd->getFd(), start, SEEK_SET);
00440 read(datfd->getFd(), tmpbuf, (int)(size - 1));
00441
00442 <font class="keywordflow">for</font> (ch = tmpbuf; *ch; ch++) { <font class="comment">// skip over index string</font>
00443 <font class="keywordflow">if</font> (*ch == 10) {
00444 ch++;
00445 <font class="keywordflow">break</font>;
00446 }
00447 }
00448 memmove(tmpbuf, ch, size - (<font class="keywordtype">unsigned</font> <font class="keywordtype">short</font>)(ch-tmpbuf));
00449
00450 <font class="comment">// resolve link</font>
00451 <font class="keywordflow">if</font> (!strncmp(tmpbuf, <font class="stringliteral">"@LINK"</font>, 5) && (len ? len : strlen(buf))) {
00452 <font class="keywordflow">for</font> (ch = tmpbuf; *ch; ch++) { <font class="comment">// null before nl</font>
00453 <font class="keywordflow">if</font> (*ch == 10) {
00454 *ch = 0;
00455 <font class="keywordflow">break</font>;
00456 }
00457 }
00458 findoffset(tmpbuf + 6, &start, &size, 0, &idxoff);
00459 }
00460 <font class="keywordflow">else</font> <font class="keywordflow">break</font>;
00461 }
00462 <font class="keywordflow">while</font> (true); <font class="comment">// while we're resolving links</font>
00463 }
00464
00465 endoff = lseek(idxfd->getFd(), 0, SEEK_END);
00466
00467 shiftSize = endoff - idxoff;
00468
00469 <font class="keywordflow">if</font> (shiftSize > 0) {
00470 idxBytes = <font class="keyword">new</font> <font class="keywordtype">char</font> [ shiftSize ];
00471 lseek(idxfd->getFd(), idxoff, SEEK_SET);
00472 read(idxfd->getFd(), idxBytes, shiftSize);
00473 }
00474
00475 outbuf = <font class="keyword">new</font> <font class="keywordtype">char</font> [ (len ? len : strlen(buf)) + strlen(key) + 5 ];
00476 sprintf(outbuf, <font class="stringliteral">"%s%c%c"</font>, key, 13, 10);
00477 size = strlen(outbuf);
00478 memcpy (outbuf + size, buf, len ? len : strlen(buf));
00479 size = outsize = size + (len ? len : strlen(buf));
00480
00481 start = outstart = lseek(datfd->getFd(), 0, SEEK_END);
00482
00483 outstart = archtosword32(start);
00484 outsize = archtosword16(size);
00485
00486 lseek(idxfd->getFd(), idxoff, SEEK_SET);
00487 <font class="keywordflow">if</font> (len ? len : strlen(buf)) {
00488 lseek(datfd->getFd(), start, SEEK_SET);
00489 write(datfd->getFd(), outbuf, (int)size);
00490
00491 <font class="comment">// add a new line to make data file easier to read in an editor</font>
00492 write(datfd->getFd(), &nl, 2);
00493
00494 write(idxfd->getFd(), &outstart, 4);
00495 write(idxfd->getFd(), &outsize, 2);
00496 <font class="keywordflow">if</font> (idxBytes) {
00497 write(idxfd->getFd(), idxBytes, shiftSize);
00498 <font class="keyword">delete</font> [] idxBytes;
00499 }
00500 }
00501 <font class="keywordflow">else</font> { <font class="comment">// delete entry</font>
00502 <font class="keywordflow">if</font> (idxBytes) {
00503 write(idxfd->getFd(), idxBytes+6, shiftSize-6);
00504 lseek(idxfd->getFd(), -1, SEEK_CUR); <font class="comment">// last valid byte</font>
00505 FileMgr::systemFileMgr.trunc(idxfd); <font class="comment">// truncate index</font>
00506 <font class="keyword">delete</font> [] idxBytes;
00507 }
00508 }
00509
00510 <font class="keyword">delete</font> [] key;
00511 <font class="keyword">delete</font> [] outbuf;
00512 free(dbKey);
00513 }
00514
00515
00516 <font class="comment">/******************************************************************************</font>
00517 <font class="comment"> * RawLD::linkentry - links one entry to another</font>
00518 <font class="comment"> *</font>
00519 <font class="comment"> * ENT: testmt - testament to find (0 - Bible/module introduction)</font>
00520 <font class="comment"> * destidxoff - dest offset into .vss</font>
00521 <font class="comment"> * srcidxoff - source offset into .vss</font>
00522 <font class="comment"> */</font>
00523
00524 <font class="keywordtype">void</font> RawStr::linkentry(<font class="keyword">const</font> <font class="keywordtype">char</font> *destkey, <font class="keyword">const</font> <font class="keywordtype">char</font> *srckey) {
00525 <font class="keywordtype">char</font> *text = <font class="keyword">new</font> <font class="keywordtype">char</font> [ strlen(destkey) + 7 ];
00526 sprintf(text, <font class="stringliteral">"@LINK %s"</font>, destkey);
00527 settext(srckey, text);
00528 <font class="keyword">delete</font> [] text;
00529 }
00530
00531
00532 <font class="comment">/******************************************************************************</font>
00533 <font class="comment"> * RawLD::CreateModule - Creates new module files</font>
00534 <font class="comment"> *</font>
00535 <font class="comment"> * ENT: path - directory to store module files</font>
00536 <font class="comment"> * RET: error status</font>
00537 <font class="comment"> */</font>
00538
00539 <font class="keywordtype">signed</font> <font class="keywordtype">char</font> RawStr::createModule(<font class="keyword">const</font> <font class="keywordtype">char</font> *ipath)
00540 {
00541 <font class="keywordtype">char</font> *path = 0;
00542 <font class="keywordtype">char</font> *buf = <font class="keyword">new</font> <font class="keywordtype">char</font> [ strlen (ipath) + 20 ];
00543 FileDesc *fd, *fd2;
00544
00545 stdstr(&path, ipath);
00546
00547 <font class="keywordflow">if</font> ((path[strlen(path)-1] == <font class="charliteral">'/'</font>) || (path[strlen(path)-1] == <font class="charliteral">'\\'</font>))
00548 path[strlen(path)-1] = 0;
00549
00550 sprintf(buf, <font class="stringliteral">"%s.dat"</font>, path);
00551 unlink(buf);
00552 fd = FileMgr::systemFileMgr.open(buf, O_CREAT|O_WRONLY|O_BINARY, S_IREAD|S_IWRITE);
00553 fd->getFd();
00554 FileMgr::systemFileMgr.close(fd);
00555
00556 sprintf(buf, <font class="stringliteral">"%s.idx"</font>, path);
00557 unlink(buf);
00558 fd2 = FileMgr::systemFileMgr.open(buf, O_CREAT|O_WRONLY|O_BINARY, S_IREAD|S_IWRITE);
00559 fd2->getFd();
00560 FileMgr::systemFileMgr.close(fd2);
00561
00562 <font class="keyword">delete</font> [] path;
00563
00564 <font class="keywordflow">return</font> 0;
00565 }
</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>