[sword-cvs] sword/src/modules/common rawstr.cpp,1.36,1.37

sword@www.crosswire.org sword@www.crosswire.org
Tue, 25 Feb 2003 20:23:46 -0700


Update of /usr/local/cvsroot/sword/src/modules/common
In directory www:/tmp/cvs-serv30129/src/modules/common

Modified Files:
	rawstr.cpp 
Log Message:
no message

Index: rawstr.cpp
===================================================================
RCS file: /usr/local/cvsroot/sword/src/modules/common/rawstr.cpp,v
retrieving revision 1.36
retrieving revision 1.37
diff -C2 -d -r1.36 -r1.37
*** rawstr.cpp	20 Feb 2003 07:25:20 -0000	1.36
--- rawstr.cpp	26 Feb 2003 03:23:44 -0000	1.37
***************
*** 97,101 ****
   */
  
! void RawStr::getidxbufdat(long ioffset, char **buf)
  {
  	int size;
--- 97,101 ----
   */
  
! void RawStr::getIDXBufDat(long ioffset, char **buf)
  {
  	int size;
***************
*** 131,135 ****
   */
  
! void RawStr::getidxbuf(long ioffset, char **buf)
  {
  	char *trybuf, *targetbuf;
--- 131,135 ----
   */
  
! void RawStr::getIDXBuf(long ioffset, char **buf)
  {
  	char *trybuf, *targetbuf;
***************
*** 142,146 ****
  		offset = swordtoarch32(offset);
  
! 		getidxbufdat(offset, buf);
  		toupperstr_utf8(*buf);
  	}
--- 142,146 ----
  		offset = swordtoarch32(offset);
  
! 		getIDXBufDat(offset, buf);
  		toupperstr_utf8(*buf);
  	}
***************
*** 160,164 ****
   */
  
! signed char RawStr::findoffset(const char *ikey, long *start, unsigned short *size, long away, long *idxoff)
  {
  	char *trybuf, *targetbuf, *key, quitflag = 0;
--- 160,164 ----
   */
  
! signed char RawStr::findOffset(const char *ikey, long *start, unsigned short *size, long away, long *idxoff)
  {
  	char *trybuf, *targetbuf, *key, quitflag = 0;
***************
*** 181,185 ****
  				tryoff = (lastoff == -1) ? headoff + ((((tailoff / 6) - (headoff / 6))) / 2) * 6 : lastoff; 
  				lastoff = -1;
! 				getidxbuf(tryoff, &trybuf);
  
  				if (!*trybuf && tryoff) {		// In case of extra entry at end of idx (not first entry)
--- 181,185 ----
  				tryoff = (lastoff == -1) ? headoff + ((((tailoff / 6) - (headoff / 6))) / 2) * 6 : lastoff; 
  				lastoff = -1;
! 				getIDXBuf(tryoff, &trybuf);
  
  				if (!*trybuf && tryoff) {		// In case of extra entry at end of idx (not first entry)
***************
*** 273,281 ****
   */
  
! void RawStr::preptext(char *buf) {
! 	char *to, *from, space = 0, cr = 0, realdata = 0, nlcnt = 0;
! 
! 	for (to = from = buf; *from; from++) {
! 		switch (*from) {
  		case 10:
  			if (!realdata)
--- 273,281 ----
   */
  
! void RawStr::prepText(SWBuf &buf) {
! 	unsigned int to, from; 
! 	char space = 0, cr = 0, realdata = 0, nlcnt = 0;
! 	for (to = from = 0; buf[from]; from++) {
! 		switch (buf[from]) {
  		case 10:
  			if (!realdata)
***************
*** 286,290 ****
  			if (nlcnt > 1) {
  //				*to++ = nl;
! 				*to++ = nl;
  //				nlcnt = 0;
  			}
--- 286,291 ----
  			if (nlcnt > 1) {
  //				*to++ = nl;
! 				buf[to++] = 10;
! //				*to++ = nl[1];
  //				nlcnt = 0;
  			}
***************
*** 293,297 ****
  			if (!realdata)
  				continue;
! 			*to++ = nl;
  			space = 0;
  			cr = 1;
--- 294,299 ----
  			if (!realdata)
  				continue;
! //			*to++ = nl[0];
! 			buf[to++] = 10;
  			space = 0;
  			cr = 1;
***************
*** 302,319 ****
  		if (space) {
  			space = 0;
! 			if (*from != ' ') {
! 				*to++ = ' ';
  				from--;
  				continue;
  			}
  		}
! 		*to++ = *from;
  	}
! 	*to = 0;
  
! 	while (to > (buf+1)) {			// remove trailing excess
  		to--;
! 		if ((*to == 10) || (*to == ' '))
! 			*to = 0;
  		else break;
  	}
--- 304,321 ----
  		if (space) {
  			space = 0;
! 			if (buf[from] != ' ') {
! 				buf[to++] = ' ';
  				from--;
  				continue;
  			}
  		}
! 		buf[to++] = buf[from];
  	}
! 	buf.setSize(to);
  
! 	while (to > 1) {			// remove trailing excess
  		to--;
! 		if ((buf[to] == 10) || (buf[to] == ' '))
! 			buf.setSize(to);
  		else break;
  	}
***************
*** 331,339 ****
   */
  
! void RawStr::readtext(long istart, unsigned short *isize, char **idxbuf, char **buf)
  {
! 	char *ch;
  	char *idxbuflocal = 0;
! 	getidxbufdat(istart, &idxbuflocal);
  	long start = istart;
  
--- 333,341 ----
   */
  
! void RawStr::readText(long istart, unsigned short *isize, char **idxbuf, SWBuf &buf)
  {
! 	unsigned int ch;
  	char *idxbuflocal = 0;
! 	getIDXBufDat(istart, &idxbuflocal);
  	long start = istart;
  
***************
*** 341,370 ****
  		if (*idxbuf)
  			delete [] *idxbuf;
! 		if (*buf)
! 			delete [] *buf;
! 		*buf    = new char [ ++(*isize) ];
  		*idxbuf = new char [ (*isize) ];
  
- 		memset(*buf, 0, *isize);
  		lseek(datfd->getFd(), start, SEEK_SET);
! 		read(datfd->getFd(), *buf, (int)((*isize) - 1));
  
! 		for (ch = *buf; *ch; ch++) {		// skip over index string
! 			if (*ch == 10) {
  				ch++;
  				break;
  			}
  		}
! 		memmove(*buf, ch, *isize - (unsigned long)(ch-*buf));
! 
  		// resolve link
! 		if (!strncmp(*buf, "@LINK", 5)) {
! 			for (ch = *buf; *ch; ch++) {		// null before nl
! 				if (*ch == 10) {
! 					*ch = 0;
  					break;
  				}
  			}
! 			findoffset(*buf + 6, &start, isize);
  		}
  		else break;
--- 343,371 ----
  		if (*idxbuf)
  			delete [] *idxbuf;
! 		buf = "";
! 		buf.setFillByte(0);
! 		buf.setSize(++(*isize));
! 
  		*idxbuf = new char [ (*isize) ];
  
  		lseek(datfd->getFd(), start, SEEK_SET);
! 		read(datfd->getFd(), buf.getRawData(), (int)((*isize) - 1));
  
! 		for (ch = 0; buf[ch]; ch++) {		// skip over index string
! 			if (buf[ch] == 10) {
  				ch++;
  				break;
  			}
  		}
! 		buf = SWBuf(buf.c_str()+ch);
  		// resolve link
! 		if (!strncmp(buf.c_str(), "@LINK", 5)) {
! 			for (ch = 0; buf[ch]; ch++) {		// null before nl
! 				if (buf[ch] == 10) {
! 					buf[ch] = 0;
  					break;
  				}
  			}
! 			findOffset(buf.c_str() + 6, &start, isize);
  		}
  		else break;
***************
*** 390,394 ****
   */
  
! void RawStr::settext(const char *ikey, const char *buf, long len)
  {
  
--- 391,395 ----
   */
  
! void RawStr::doSetText(const char *ikey, const char *buf, long len)
  {
  
***************
*** 407,411 ****
  	char *ch = 0;
  
! 	char errorStatus = findoffset(ikey, &start, &size, 0, &idxoff);
  	stdstr(&key, ikey);
  	toupperstr_utf8(key);
--- 408,412 ----
  	char *ch = 0;
  
! 	char errorStatus = findOffset(ikey, &start, &size, 0, &idxoff);
  	stdstr(&key, ikey);
  	toupperstr_utf8(key);
***************
*** 413,417 ****
  	len = (len < 0) ? strlen(buf) : len;
  
! 	getidxbufdat(start, &dbKey);
  
  	if (strcmp(key, dbKey) < 0) {
--- 414,418 ----
  	len = (len < 0) ? strlen(buf) : len;
  
! 	getIDXBufDat(start, &dbKey);
  
  	if (strcmp(key, dbKey) < 0) {
***************
*** 445,449 ****
  					}
  				}
! 				findoffset(tmpbuf + 6, &start, &size, 0, &idxoff);
  			}
  			else break;
--- 446,450 ----
  					}
  				}
! 				findOffset(tmpbuf + 6, &start, &size, 0, &idxoff);
  			}
  			else break;
***************
*** 511,518 ****
   */
  
! void RawStr::linkentry(const char *destkey, const char *srckey) {
  	char *text = new char [ strlen(destkey) + 7 ];
  	sprintf(text, "@LINK %s", destkey);
! 	settext(srckey, text);
  	delete [] text;
  }
--- 512,519 ----
   */
  
! void RawStr::doLinkEntry(const char *destkey, const char *srckey) {
  	char *text = new char [ strlen(destkey) + 7 ];
  	sprintf(text, "@LINK %s", destkey);
! 	doSetText(srckey, text);
  	delete [] text;
  }