[sword-svn] r2096 - in trunk: . examples/cmdline include olb src/keys src/mgr src/modules/filters src/utilfuns tests tests/testsuite utilities

scribe at www.crosswire.org scribe at www.crosswire.org
Sat Oct 6 17:40:00 MST 2007


Author: scribe
Date: 2007-10-06 17:40:00 -0700 (Sat, 06 Oct 2007)
New Revision: 2096

Modified:
   trunk/ChangeLog
   trunk/examples/cmdline/lookup.cpp
   trunk/include/config.h
   trunk/include/stringmgr.h
   trunk/include/swbuf.h
   trunk/include/utilxml.h
   trunk/olb/addstrongs.cpp
   trunk/olb/olb2sword.cpp
   trunk/olb/prn2swordfrm.cpp
   trunk/src/keys/genarray.c
   trunk/src/keys/versekey.cpp
   trunk/src/mgr/filemgr.cpp
   trunk/src/modules/filters/osisstrongs.cpp
   trunk/src/modules/filters/utf8transliterator.cpp
   trunk/src/utilfuns/utilxml.cpp
   trunk/tests/complzss.cpp
   trunk/tests/compnone.cpp
   trunk/tests/compzip.cpp
   trunk/tests/swbuftest.cpp
   trunk/tests/testblocks.cpp
   trunk/tests/testsuite/xmltag.good
   trunk/tests/translittest.cpp
   trunk/tests/xmltest.cpp
   trunk/utilities/cipherraw.cpp
   trunk/utilities/gbfidx.cpp
   trunk/utilities/genbookutil.cpp
   trunk/utilities/lexdump.c
   trunk/utilities/no13.c
   trunk/utilities/step2vpl.cpp
   trunk/utilities/stepdump.cpp
   trunk/utilities/vpl2mod.cpp
   trunk/utilities/vpl2zmod2.cpp
Log:
	Added SWBuf::stripPrefix method which works nice
		for returning and stripping stuff like
		'lemma' from "lemma:G1234"
	Added part params to XMLTag::setAttribute
	Changed OSISStrongs to only strip lemma parts with
		strong prefix
	Applied fix for newer version of gcc which errors if
		create perms are not passed to ::open
		(Deji Akingunola <dakingun at gmail dot com>)



Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2007-09-29 00:47:00 UTC (rev 2095)
+++ trunk/ChangeLog	2007-10-07 00:40:00 UTC (rev 2096)
@@ -1,5 +1,16 @@
 API ChangeLog 
 
+6-Oct-2007	Troy A. Griffitts <scribe at crosswire.org>
+	Added SWBuf::stripPrefix method which works nice
+		for returning and stripping stuff like
+		'lemma' from "lemma:G1234"
+	Added part params to XMLTag::setAttribute
+	Changed OSISStrongs to only strip lemma parts with
+		strong prefix
+	Applied fix for newer version of gcc which errors if
+		create perms are not passed to ::open
+		(Deji Akingunola <dakingun at gmail dot com>)
+
 13-Sep-2007	Troy A. Griffitts <scribe at crosswire.org>
 	Added InstallMgr::getModuleStatus to return a list
 		of differences between the modules of two SWMgr
@@ -25,7 +36,7 @@
 	Finished first stable version of rewrite of imp2gbs
 	Fixed bug in treekey where didn't break on found sibling
 	Added .trim to localName segments of genbook path,
-		e.g. /this / is/a/test/  - all spaces will be removed.
+		e.g. /this / is/a/test/  - all spaces will be removed
 	Added recognition of additional greek accent ~
 		in UTF8GreekAccents filter
 	Fixed bug in RawGenBook::setText where default size

Modified: trunk/examples/cmdline/lookup.cpp
===================================================================
--- trunk/examples/cmdline/lookup.cpp	2007-09-29 00:47:00 UTC (rev 2095)
+++ trunk/examples/cmdline/lookup.cpp	2007-10-07 00:40:00 UTC (rev 2096)
@@ -18,8 +18,8 @@
 int main(int argc, char **argv)
 {
 	
-//	SWMgr manager(new MarkupFilterMgr(FMT_WEBIF));
-	SWMgr manager(new MarkupFilterMgr(FMT_HTMLHREF));
+	SWMgr manager(new MarkupFilterMgr(FMT_WEBIF));
+//	SWMgr manager(new MarkupFilterMgr(FMT_HTMLHREF));
 	SWModule *target;
 
 	if (argc != 3) {

Modified: trunk/include/config.h
===================================================================
--- trunk/include/config.h	2007-09-29 00:47:00 UTC (rev 2095)
+++ trunk/include/config.h	2007-10-07 00:40:00 UTC (rev 2096)
@@ -1,4 +1,4 @@
-/* include/config.h.  Generated from config.h.in by configure.  */
+/* include/config.h.  Generated by configure.  */
 /* include/config.h.in.  Generated from configure.ac by autoheader.  */
 
 /* Define to 1 if you have the <dlfcn.h> header file. */

Modified: trunk/include/stringmgr.h
===================================================================
--- trunk/include/stringmgr.h	2007-09-29 00:47:00 UTC (rev 2095)
+++ trunk/include/stringmgr.h	2007-10-07 00:40:00 UTC (rev 2096)
@@ -56,12 +56,15 @@
 	
 	/** Converts the param to an upper case Utf8 string
 	* @param text The text encoded in utf8 which should be turned into an upper case string
-	* @param max Only change max chars
+	* @param max Max buffer size
+	* @return text buffer (only for convenience)
 	*/	
 	virtual char *upperUTF8(char *text, unsigned int max = 0) const;
    
 	/** Converts the param to an uppercase latin1 string
 	* @param text The text encoded in latin1 which should be turned into an upper case string
+	* @param max Max buffer size
+	* @return text buffer (only for convenience)
 	*/	
 	virtual char *upperLatin1(char *text, unsigned int max = 0) const;
 	

Modified: trunk/include/swbuf.h
===================================================================
--- trunk/include/swbuf.h	2007-09-29 00:47:00 UTC (rev 2095)
+++ trunk/include/swbuf.h	2007-10-07 00:40:00 UTC (rev 2096)
@@ -317,26 +317,86 @@
 	inline SWBuf &operator =(const SWBuf &other) { set(other); return *this; }
 	inline SWBuf &operator +=(const char *str) { append(str); return *this; }
 	inline SWBuf &operator +=(char ch) { append(ch); return *this; }
+
+	/**
+	 * Decrease the buffer size, discarding the last characters
+	 * @param len how many bytes to decrease the buffer size
+	 */
 	inline SWBuf &operator -=(unsigned long len) { setSize(length()-len); return *this; }
+
+	/**
+	 * Decrease the buffer size, discarding the last character
+	 */
 	inline SWBuf &operator --(int) { operator -=(1); return *this; }
 
+	/**
+	 * Shift the buffer to the left, discarding the first bytes, decreasing the buffer size
+	 */
 	inline SWBuf &operator <<(unsigned long n) { if (n && length()) { n = (n<=length())?n:(length()-1); memmove(buf, buf+n, length()-n); (*this)-=n; } return *this; }
+
+	/**
+	 * Shift the buffer to the right, increasing the buffer size
+	 */
 	inline SWBuf &operator >>(unsigned long n) { setSize(length()+n); memmove(buf+n, buf, length()-n); return *this; }
+
+	/**
+	 * Concatenate another buffer to the end of this buffer
+	 */
 	inline SWBuf operator +(const SWBuf &other) const {
 		SWBuf retVal = buf;
 		retVal += other;
 		return retVal;
 	}
+
+	/**
+	 * Concatenate a byte to the end of this buffer
+	 */
 	inline SWBuf operator +(char ch) const { return (*this) + SWBuf(ch); }
 
+	/**
+	 * Trim whitespace from the start of this buffer, shifting the buffer left as necessary
+	 */
 	inline SWBuf &trimStart() { while (size() && (strchr("\t\r\n ", *(buf)))) *this << 1; return *this; }
+
+	/**
+	 * Trim whitespace from the end of this buffer, decreasing the size as necessary
+	 */
 	inline SWBuf &trimEnd() { while (size() && (strchr("\t\r\n ", *(end-1)))) setSize(size()-1); return *this; }
+
+	/**
+	 * Trim whitespace from the start and end of this buffer, shifting left and decreasing size as necessary
+	 */
 	inline SWBuf &trim() { trimStart(); return trimEnd(); }
+
+
+	/**
+	 * Strip a prefix from this buffer up to a separator byte.
+	 * Returns the prefix and modifies this buffer, shifting left to remove prefix
+	 * @param separator to use (e.g. ':')
+	 * @return prefix if separator character found; otherwise, null and leaves buffer unmodified
+	 */
+	inline const char *stripPrefix(char separator) { const char *m = strchr(buf, ':'); if (m) { int len = m-buf; char *hold = new char[len]; memcpy(hold, buf, len); *this << (len+1); memcpy(end+1, hold, len); delete [] hold; end[len+1] = 0; } return (m) ? end+1 : 0; }  // safe.  we know we don't actually realloc and shrink buffer when shifting, so we can place our return val at end.
+
 	// this could be nicer, like replacing a contiguous series of target bytes with single replacement; offering replacement const char *
+	/**
+	 * Replace with a new byte value all occurances in this buffer of any byte value specified in a set
+	 * @param targets a set of bytes, any of which will be replaced
+	 * @param newByte value to use as replacement.
+	 *
+	 * Example: replaceBytes("abc", 'z');  // replaces all occurances of 'a', 'b', and 'c' with 'z'
+	 */
 	inline SWBuf &replaceBytes(const char *targets, char newByte) { for (unsigned int i = 0; (i < size()); i++) { if (strchr(targets, buf[i])) buf[i] = newByte; } return *this; }
 
+	/**
+	 * @return returns true if this buffer starts with the specified prefix
+	 */
 	inline bool startsWith(const SWBuf &prefix) const { return !strncmp(c_str(), prefix.c_str(), prefix.size()); }
+
+	/**
+	 * @return returns true if this buffer ends with the specified postfix
+	 */
 	inline bool endsWith(const SWBuf &postfix) const { return (size() >= postfix.size())?!strncmp(end-postfix.size(), postfix.c_str(), postfix.size()):false; }
+
 	inline int compare(const SWBuf &other) const { return strcmp(c_str(), other.c_str()); }
 	inline bool operator ==(const SWBuf &other) const { return !compare(other); }
 	inline bool operator !=(const SWBuf &other) const { return compare(other); }
@@ -345,8 +405,16 @@
 	inline bool operator <=(const SWBuf &other) const { return compare(other) <= 0; }
 	inline bool operator >=(const SWBuf &other) const { return compare(other) >= 0; }
 
+	/**
+	 * @return returns true if this buffer starts with the specified prefix
+	 */
 	inline bool startsWith(const char *prefix) const { return !strncmp(c_str(), prefix, strlen(prefix)); }
+
+	/**
+	 * @return returns true if this buffer ends with the specified postfix
+	 */
 	inline bool endsWith(const char *postfix) const { unsigned int psize = strlen(postfix); return (size() >= psize)?!strncmp(end-psize, postfix, psize):false; }
+
 	inline int compare(const char *other) const { return strcmp(c_str(), other); }
 	inline bool operator ==(const char *other) const { return !compare(other); }
 	inline bool operator !=(const char *other) const { return compare(other); }

Modified: trunk/include/utilxml.h
===================================================================
--- trunk/include/utilxml.h	2007-09-29 00:47:00 UTC (rev 2095)
+++ trunk/include/utilxml.h	2007-10-07 00:40:00 UTC (rev 2096)
@@ -76,7 +76,7 @@
 
 	// return values should not be considered to persist beyond the return of the function.
 	const char *getAttribute(const char *attribName, int partNum = -1, char partSplit = '|') const;
-	const char *setAttribute(const char *attribName, const char *attribValue);
+	const char *setAttribute(const char *attribName, const char *attribValue, int partNum = -1, char partSplit = '|');
 	const char *toString() const;
 	inline operator const char *() const { return toString(); }
 	inline XMLTag & operator =(const char *tagString) { setText(tagString); return *this; }

Modified: trunk/olb/addstrongs.cpp
===================================================================
--- trunk/olb/addstrongs.cpp	2007-09-29 00:47:00 UTC (rev 2095)
+++ trunk/olb/addstrongs.cpp	2007-10-07 00:40:00 UTC (rev 2096)
@@ -25,7 +25,7 @@
     call DOINIT(argv[1]);   /* initialise system */
  else
     call DOINIT("g:\\bible\\av");   /* initialise system */
-	fd = open("../modules/texts/rawtext/kjv/ot", O_RDONLY);
+	fd = open("../modules/texts/rawtext/kjv/ot", O_RDONLY, S_IREAD|S_IWRITE);
 
 					   /* get text for Ge 1:1 & Rev 22:21 */
 
@@ -98,4 +98,4 @@
     }
 
  DOEND();
-}
\ No newline at end of file
+}

Modified: trunk/olb/olb2sword.cpp
===================================================================
--- trunk/olb/olb2sword.cpp	2007-09-29 00:47:00 UTC (rev 2095)
+++ trunk/olb/olb2sword.cpp	2007-10-07 00:40:00 UTC (rev 2096)
@@ -243,28 +243,28 @@
 
 	strcpy(fname, (testmnt==2) ? "nt" : "ot");
 	unlink(fname);
-	if ((fp = open(fname, O_CREAT|O_RDWR|O_BINARY)) == -1) {
+	if ((fp = open(fname, O_CREAT|O_RDWR|O_BINARY, S_IREAD|S_IWRITE)) == -1) {
 		fprintf(stderr, "Couldn't open file: %s\n", fname);
 		exit(1);
 	}
 
 	sprintf(buf, "%s.vss", fname);
 	unlink(buf);
-	if ((vfp = open(buf, O_CREAT|O_WRONLY|O_BINARY)) == -1) {
+	if ((vfp = open(buf, O_CREAT|O_WRONLY|O_BINARY, S_IREAD|S_IWRITE)) == -1) {
 		fprintf(stderr, "Couldn't open file: %s\n", buf);
 		exit(1);
 	}
 
 	sprintf(buf, "%s.cps", fname);
 	unlink(buf);
-	if ((cfp = open(buf, O_CREAT|O_WRONLY|O_BINARY)) == -1) {
+	if ((cfp = open(buf, O_CREAT|O_WRONLY|O_BINARY, S_IREAD|S_IWRITE)) == -1) {
 		fprintf(stderr, "Couldn't open file: %s\n", buf);
 		exit(1);
 	}
 
 	sprintf(buf, "%s.bks", fname);
 	unlink(buf);
-	if ((bfp = open(buf, O_CREAT|O_WRONLY|O_BINARY)) == -1) {
+	if ((bfp = open(buf, O_CREAT|O_WRONLY|O_BINARY, S_IREAD|S_IWRITE)) == -1) {
 		fprintf(stderr, "Couldn't open file: %s\n", buf);
 		exit(1);
 	}

Modified: trunk/olb/prn2swordfrm.cpp
===================================================================
--- trunk/olb/prn2swordfrm.cpp	2007-09-29 00:47:00 UTC (rev 2095)
+++ trunk/olb/prn2swordfrm.cpp	2007-10-07 00:40:00 UTC (rev 2096)
@@ -44,7 +44,7 @@
 	char end = 0;
 	
 
-	if ((fp = open(fileName, O_RDONLY|O_BINARY)) == -1) {
+	if ((fp = open(fileName, O_RDONLY|O_BINARY, S_IREAD|S_IWRITE)) == -1) {
 		sprintf(buf, "Couldn't open file: %s\n", fileName);
 		MessageBox(this->Handle, buf, "ProcessFile", MB_OK);
 		return;

Modified: trunk/src/keys/genarray.c
===================================================================
--- trunk/src/keys/genarray.c	2007-09-29 00:47:00 UTC (rev 2095)
+++ trunk/src/keys/genarray.c	2007-10-07 00:40:00 UTC (rev 2096)
@@ -19,7 +19,7 @@
 			l3 = 1;
 			sprintf(buf, "%s", fnames[(l1*2)+l2]);
 			printf("		// %s\n", fnames[(l1*2)+l2]);
-			fd = open(buf, O_RDONLY|O_BINARY);
+			fd = open(buf, O_RDONLY|O_BINARY, S_IREAD|S_IWRITE|S_IRGRP|S_IROTH);
 			while (read(fd, &val, 4) == 4) {
 				l3++;
 				printf("%ld, ", val/(4 + (l2*2)));

Modified: trunk/src/keys/versekey.cpp
===================================================================
--- trunk/src/keys/versekey.cpp	2007-09-29 00:47:00 UTC (rev 2095)
+++ trunk/src/keys/versekey.cpp	2007-10-07 00:40:00 UTC (rev 2096)
@@ -388,10 +388,10 @@
 
 		if (!i) {
 			if (hasUTF8Support) { //we have support for UTF-8 handling; we expect UTF-8 encoded locales
-				abbr = stringMgr->upperUTF8(abbr, strlen(abbr)*2);
+				stringMgr->upperUTF8(abbr, strlen(abbr)*2);
 			}
 			else {
-				abbr = stringMgr->upperLatin1(abbr);
+				stringMgr->upperLatin1(abbr);
 			}
 		}
 

Modified: trunk/src/mgr/filemgr.cpp
===================================================================
--- trunk/src/mgr/filemgr.cpp	2007-09-29 00:47:00 UTC (rev 2095)
+++ trunk/src/mgr/filemgr.cpp	2007-10-07 00:40:00 UTC (rev 2096)
@@ -393,7 +393,7 @@
 	int sfd, dfd, len;
 	char buf[4096];
 
-	if ((sfd = ::open(sourceFile, O_RDONLY|O_BINARY)) < 1)
+	if ((sfd = ::open(sourceFile, O_RDONLY|O_BINARY, S_IREAD|S_IWRITE|S_IRGRP|S_IROTH)) < 1)
 		return -1;
 	if ((dfd = createPathAndFile(targetFile)) < 1)
 		return -1;

Modified: trunk/src/modules/filters/osisstrongs.cpp
===================================================================
--- trunk/src/modules/filters/osisstrongs.cpp	2007-09-29 00:47:00 UTC (rev 2095)
+++ trunk/src/modules/filters/osisstrongs.cpp	2007-10-07 00:40:00 UTC (rev 2096)
@@ -32,8 +32,7 @@
 
 
 char OSISStrongs::processText(SWBuf &text, const SWKey *key, const SWModule *module) {
-	char token[2112]; // cheese.  Fix.
-	int tokpos = 0;
+	SWBuf token;
 	bool intoken = false;
 	bool lastspace = false;
 	int wordNum = 1;
@@ -46,15 +45,13 @@
 	for (text = ""; *from; ++from) {
 		if (*from == '<') {
 			intoken = true;
-			tokpos = 0;
-			token[0] = 0;
-			token[1] = 0;
-			token[2] = 0;
+			token = "";
 			continue;
 		}
 		if (*from == '>') {	// process tokens
 			intoken = false;
-			if ((*token == 'w') && (token[1] == ' ')) {	// Word
+			if (token.startsWith("w ")) {	// Word
+				XMLTag wtag(token);
 				if (module->isProcessEntryAttributes()) {
 					wordStart = from+1;
 					char gh = 0;
@@ -62,7 +59,6 @@
 					if (key) {
 						vkey = SWDYNAMIC_CAST(VerseKey, key);
 					}
-					XMLTag wtag(token);
 					SWBuf lemma      = "";
 					SWBuf morph      = "";
 					SWBuf src        = "";
@@ -71,6 +67,9 @@
 
 					const char *attrib;
 					sprintf(wordstr, "%03d", wordNum);
+
+					// why is morph entry attribute processing done in here?  Well, it's faster.  It makes more local sense to place this code in osismorph.
+					// easier to keep lemma and morph in same wordstr number too maybe.
 					if ((attrib = wtag.getAttribute("morph"))) {
 						int count = wtag.getAttributePartCount("morph", ' ');
 						int i = (count > 1) ? 0 : -1;		// -1 for whole value cuz it's faster, but does the same thing as 0
@@ -107,6 +106,7 @@
 						int count = wtag.getAttributePartCount("lemma", ' ');
 						int i = (count > 1) ? 0 : -1;		// -1 for whole value cuz it's faster, but does the same thing as 0
 						do {
+							gh = 0;
 							SWBuf lClass = "";
 							SWBuf l = "";
 							attrib = wtag.getAttribute("lemma", i, ' ');
@@ -119,13 +119,15 @@
 								attrib += (len+1);
 							}
 							if ((lClass == "x-Strongs") || (lClass == "strong") || (lClass == "Strong")) {
-								gh = isdigit(attrib[0]) ? 0:attrib[0];
-								if (!gh) {
+								if (isdigit(attrib[0])) {
 									if (vkey) {
 										gh = vkey->Testament() ? 'H' : 'G';
 									}
 								}
-								else attrib++;
+								else {
+									gh = *attrib;
+									attrib++;
+								}
 								lClass = "strong";
 							}
 							if (gh) l += gh;
@@ -177,30 +179,41 @@
 
 					if (wtag.isEmpty()) {
 						int j;
-						for (j = strlen(token)-1; ((j>0) && (strchr(" /", token[j]))); j--);
-						token[j+1] = 0;
+						for (j = token.length()-1; ((j>0) && (strchr(" /", token[j]))); j--);
+						token.size(j+1);
 					}
 					
-					strcat(token, " wn=\"");
-					strcat(token, wordstr);
-					strcat(token, "\"");
+					token += " wn=\"";
+					token += wordstr;
+					token += "\"";
 
 					if (wtag.isEmpty()) {
-						strcat(token, "/");
+						token += "/";
 					}
 
 					wordNum++;
 				}
 
 				if (!option) {
-					// remove all lemmas.  This class should be renamed to OSISLemma
-					char *num = strstr(token, "lemma=\"");
-					if (num) {
-						memcpy(num, "savlm", 5);
+					int count = wtag.getAttributePartCount("lemma", ' ');
+					for (int i = 0; i < count; i++) {
+						SWBuf a = wtag.getAttribute("lemma", i, ' ');
+						const char *prefix = a.stripPrefix(':');
+						if ((prefix) && (!strcmp(prefix, "x-Strongs") || !strcmp(prefix, "strong") || !strcmp(prefix, "Strong"))) {
+							// remove attribute part
+							wtag.setAttribute("lemma", 0, i, ' ');
+							i--;
+							count--;
+						}
 					}
+					token = wtag;
+					token.trim();
+					// drop <>
+					token << 1;
+					token--;
 				}
 			}
-			if ((*token == '/') && (token[1] == 'w')) {	// Word End
+			if (token.startsWith("/w")) {	// Word End
 				if (module->isProcessEntryAttributes()) {
 					if (wordStart) {
 						SWBuf tmp;
@@ -220,9 +233,7 @@
 			continue;
 		}
 		if (intoken) {
-			if (tokpos < 2045)
-				token[tokpos++] = *from;
-				token[tokpos+2] = 0;
+			token += *from;
 		}
 		else	{
 			text.append(*from);

Modified: trunk/src/modules/filters/utf8transliterator.cpp
===================================================================
--- trunk/src/modules/filters/utf8transliterator.cpp	2007-09-29 00:47:00 UTC (rev 2095)
+++ trunk/src/modules/filters/utf8transliterator.cpp	2007-10-07 00:40:00 UTC (rev 2096)
@@ -349,7 +349,7 @@
                         scripts[i] = false;
                 }
 
-                for (i = 0; i < len; i++) {
+                for (i = 0; i < (unsigned long)len; i++) {
                         j = ublock_getCode(source[i]);
 			scripts[SE_LATIN] = true;
 			switch (j) {

Modified: trunk/src/utilfuns/utilxml.cpp
===================================================================
--- trunk/src/utilfuns/utilxml.cpp	2007-09-29 00:47:00 UTC (rev 2095)
+++ trunk/src/utilfuns/utilxml.cpp	2007-10-07 00:40:00 UTC (rev 2096)
@@ -224,12 +224,39 @@
 }
 
 
-const char *XMLTag::setAttribute(const char *attribName, const char *attribValue) {
+const char *XMLTag::setAttribute(const char *attribName, const char *attribValue, int partNum, char partSplit) {
 	if (!parsed)
 		parse();
+
+	SWBuf newVal = "";
+	// set part of an attribute
+	if (partNum > -1) {
+		const char *wholeAttr = getAttribute(attribName);
+		int attrCount = getAttributePartCount(attribName, partSplit);
+		for (int i = 0; i < attrCount; i++) {
+			if (i == partNum) {
+				if (attribValue) {
+					newVal += attribValue;
+					newVal += partSplit;
+				}
+				else {
+					// discard this part per null attribValue
+				}
+			}
+			else {
+				newVal += getPart(wholeAttr, i, partSplit);
+				newVal += partSplit;
+			}
+		}
+		if (newVal.length()) newVal--;	// discard the last partSplit
+		attribValue = (!attribValue && !newVal.length()) ? 0 : newVal.c_str();
+	}
+
+	// perform the actual set
 	if (attribValue)
 		attributes[attribName] = attribValue;
 	else	attributes.erase(attribName);
+
 	return attribValue;
 }
 

Modified: trunk/tests/complzss.cpp
===================================================================
--- trunk/tests/complzss.cpp	2007-09-29 00:47:00 UTC (rev 2095)
+++ trunk/tests/complzss.cpp	2007-10-07 00:40:00 UTC (rev 2096)
@@ -41,10 +41,10 @@
 #define O_BINARY 0
 #endif
 
-	ufd  = open(fname, O_RDWR|O_CREAT|O_BINARY, 00644);
+	ufd  = open(fname, O_RDWR|O_CREAT|O_BINARY, S_IREAD|S_IWRITE|S_IRGRP|S_IROTH);
 
 	sprintf(buf, "%s.lzs", fname);
-	zfd = open(buf, O_RDWR|O_CREAT|O_BINARY, 00644);
+	zfd = open(buf, O_RDWR|O_CREAT|O_BINARY, S_IREAD|S_IWRITE|S_IRGRP|S_IROTH);
 }
 
 	

Modified: trunk/tests/compnone.cpp
===================================================================
--- trunk/tests/compnone.cpp	2007-09-29 00:47:00 UTC (rev 2095)
+++ trunk/tests/compnone.cpp	2007-10-07 00:40:00 UTC (rev 2096)
@@ -41,10 +41,10 @@
 #define O_BINARY 0
 #endif
 
-	ufd  = open(fname, O_RDWR|O_CREAT|O_BINARY, 00644);
+	ufd  = open(fname, O_RDWR|O_CREAT|O_BINARY, S_IREAD|S_IWRITE|S_IRGRP|S_IROTH);
 
 	sprintf(buf, "%s.zzz", fname);
-	zfd = open(buf, O_RDWR|O_CREAT|O_BINARY, 00644);
+	zfd = open(buf, O_RDWR|O_CREAT|O_BINARY, S_IREAD|S_IWRITE|S_IRGRP|S_IROTH);
 }
 
 	

Modified: trunk/tests/compzip.cpp
===================================================================
--- trunk/tests/compzip.cpp	2007-09-29 00:47:00 UTC (rev 2095)
+++ trunk/tests/compzip.cpp	2007-10-07 00:40:00 UTC (rev 2096)
@@ -39,10 +39,10 @@
 #define O_BINARY 0
 #endif
 
-	ufd  = open(fname, O_RDWR|O_CREAT|O_BINARY, 00644);
+	ufd  = open(fname, O_RDWR|O_CREAT|O_BINARY, S_IREAD|S_IWRITE|S_IRGRP|S_IROTH);
 
 	sprintf(buf, "%s.zip", fname);
-	zfd = open(buf, O_RDWR|O_CREAT|O_BINARY, 00644);
+	zfd = open(buf, O_RDWR|O_CREAT|O_BINARY, S_IREAD|S_IWRITE|S_IRGRP|S_IROTH);
 }
 
 	

Modified: trunk/tests/swbuftest.cpp
===================================================================
--- trunk/tests/swbuftest.cpp	2007-09-29 00:47:00 UTC (rev 2095)
+++ trunk/tests/swbuftest.cpp	2007-10-07 00:40:00 UTC (rev 2096)
@@ -125,6 +125,12 @@
 	cout << "x should be (hello wurld): (" << x << ")\n";
 	StringType y = x + " " + x;
 	cout << "should be (hello wurld hello wurld): (" << y << ")\n";
+
+	sword::SWBuf prefixTest = "prefix:value";
+	cout << "Prefix test: " << prefixTest << "\n";
+	cout << "Prefix should be (prefix): " << prefixTest.stripPrefix(':') << "\n";
+	cout << "Value should be (value): " << prefixTest << "\n";
+
 //	y.appendFormatted(" from %d %s running %02.05f miles", 4, "dogs", 1.9f);
 //	cout << "should be (hello wurld hello wurld from 4 dogs running 1.90000 miles): (" << y << ")\n";
 //	y += '!';

Modified: trunk/tests/testblocks.cpp
===================================================================
--- trunk/tests/testblocks.cpp	2007-09-29 00:47:00 UTC (rev 2095)
+++ trunk/tests/testblocks.cpp	2007-10-07 00:40:00 UTC (rev 2096)
@@ -15,7 +15,7 @@
 	std::cout << "\nEnter new Entry's text. '.' on an empty line to finish:\n";
 	do {
 		std::cout << "> ";
-		gets(line);
+		fgets(line, 1000, stdin);
 		input = line;
 		if (input.compare("."))
 			body.append(input);
@@ -60,7 +60,7 @@
 
 	do {
 		std::cout << "[" << eb->getCount() << "] > ";
-		gets(line);
+		fgets(line, 1000, stdin);
 		input = line;
 		if (input.length() > 0) {
 			switch (input[0]) {

Modified: trunk/tests/testsuite/xmltag.good
===================================================================
--- trunk/tests/testsuite/xmltag.good	2007-09-29 00:47:00 UTC (rev 2095)
+++ trunk/tests/testsuite/xmltag.good	2007-10-07 00:40:00 UTC (rev 2096)
@@ -21,6 +21,14 @@
  isEmpty: 1
  isEndTag: 0
 
+Setting attribute 'multiPart' to: 'ABC D EF GHIJ'
+<verse addedAttribute='with a " quote' multiPart="ABC D EF GHIJ" osisID="John.1.1" type="test type" yeah="stuff"/>
+Setting part 2 to 'MMM'
+<verse addedAttribute='with a " quote' multiPart="ABC D MMM GHIJ" osisID="John.1.1" type="test type" yeah="stuff"/>
+Removing part 1
+<verse addedAttribute='with a " quote' multiPart="ABC MMM GHIJ" osisID="John.1.1" type="test type" yeah="stuff"/>
+Removing part 2
+<verse addedAttribute='with a " quote' multiPart="ABC MMM" osisID="John.1.1" type="test type" yeah="stuff"/>
 <yo mama='stuff' />
 <yo mama="stuff"/>
 <yo addedAttribute='with a " quote' mama="stuff"/>

Modified: trunk/tests/translittest.cpp
===================================================================
--- trunk/tests/translittest.cpp	2007-09-29 00:47:00 UTC (rev 2095)
+++ trunk/tests/translittest.cpp	2007-10-07 00:40:00 UTC (rev 2096)
@@ -35,8 +35,7 @@
 
 
   UErrorCode status = U_ZERO_ERROR;
-  UDataMemory *pappData = udata_open("/usr/local/lib/sword/swicu", 
-	"res", "root", &status);
+//  UDataMemory *pappData = udata_open("/usr/local/lib/sword/swicu", "res", "root", &status);
   if (U_FAILURE(status)) 
   {
   	std::cout << "error: " << status << ":" << 
@@ -48,7 +47,7 @@
   UConverter *conv;
   //UParseError perr = U_ZERO_ERROR;
   int32_t uBufSize = 0, uLength = 0;
-  void * pAppData=NULL;
+//  void * pAppData=NULL;
   char * samplestring = "If this compiles and runs without errors, apparently ICU is working.";
   //ures_open("/usr/local/lib/sword/swicu.dat", 
  // 	NULL, &status);

Modified: trunk/tests/xmltest.cpp
===================================================================
--- trunk/tests/xmltest.cpp	2007-09-29 00:47:00 UTC (rev 2095)
+++ trunk/tests/xmltest.cpp	2007-10-07 00:40:00 UTC (rev 2096)
@@ -31,4 +31,22 @@
 	cout << " isEmpty: " << x.isEmpty() << "\n";
 	cout << " isEndTag: " << x.isEndTag() << "\n";
 	cout << "\n";
+
+	
+	if (argc < 2) {  // only run if we're defaulted
+		const char *testParts="ABC D EF GHIJ";
+		cout << "Setting attribute 'multiPart' to: '" << testParts << "'\n";
+		x.setAttribute("multiPart", testParts);
+		cout << x << "\n";
+		cout << "Setting part 2 to 'MMM'\n";
+		x.setAttribute("multiPart", "MMM", 2, ' ');
+		cout << x << "\n";
+		cout << "Removing part 1\n";
+		x.setAttribute("multiPart", 0, 1, ' ');
+		cout << x << "\n";
+		cout << "Removing part 2\n";
+		x.setAttribute("multiPart", 0, 2, ' ');
+		cout << x << "\n";
+	}
+	
 }

Modified: trunk/utilities/cipherraw.cpp
===================================================================
--- trunk/utilities/cipherraw.cpp	2007-09-29 00:47:00 UTC (rev 2095)
+++ trunk/utilities/cipherraw.cpp	2007-10-07 00:40:00 UTC (rev 2096)
@@ -45,13 +45,13 @@
 
 	tmpbuf = new char [ strlen(argv[1]) + 11 ];
 	sprintf(tmpbuf, "%sot.zzz", argv[1]);
-	ofd[0] = open(tmpbuf, O_WRONLY|O_BINARY|O_CREAT);
+	ofd[0] = open(tmpbuf, O_WRONLY|O_BINARY|O_CREAT, S_IREAD|S_IWRITE|S_IRGRP|S_IROTH);
 	sprintf(tmpbuf, "%sot.zzz.vss", argv[1]);
-	oxfd[0] = open(tmpbuf, O_WRONLY|O_BINARY|O_CREAT);
+	oxfd[0] = open(tmpbuf, O_WRONLY|O_BINARY|O_CREAT, S_IREAD|S_IWRITE|S_IRGRP|S_IROTH);
 	sprintf(tmpbuf, "%snt.zzz", argv[1]);
-	ofd[1] = open(tmpbuf, O_WRONLY|O_BINARY|O_CREAT);
+	ofd[1] = open(tmpbuf, O_WRONLY|O_BINARY|O_CREAT, S_IREAD|S_IWRITE|S_IRGRP|S_IROTH);
 	sprintf(tmpbuf, "%snt.zzz.vss", argv[1]);
-	oxfd[1] = open(tmpbuf, O_WRONLY|O_BINARY|O_CREAT);
+	oxfd[1] = open(tmpbuf, O_WRONLY|O_BINARY|O_CREAT, S_IREAD|S_IWRITE|S_IRGRP|S_IROTH);
 
 	delete [] tmpbuf;
 

Modified: trunk/utilities/gbfidx.cpp
===================================================================
--- trunk/utilities/gbfidx.cpp	2007-09-29 00:47:00 UTC (rev 2095)
+++ trunk/utilities/gbfidx.cpp	2007-10-07 00:40:00 UTC (rev 2096)
@@ -253,25 +253,25 @@
 #endif				// don't need it.
 	char buf[255];
 
-	if ((fp = open(fname, O_RDONLY|O_BINARY)) == -1) {
+	if ((fp = open(fname, O_RDONLY|O_BINARY, S_IREAD|S_IWRITE|S_IRGRP|S_IROTH)) == -1) {
 		fprintf(stderr, "Couldn't open file: %s\n", fname);
 		exit(1);
 	}
 
 	sprintf(buf, "%s.vss", fname);
-	if ((vfp = open(buf, O_CREAT|O_WRONLY|O_BINARY)) == -1) {
+	if ((vfp = open(buf, O_CREAT|O_WRONLY|O_BINARY, S_IREAD|S_IWRITE|S_IRGRP|S_IROTH)) == -1) {
 		fprintf(stderr, "Couldn't open file: %s\n", buf);
 		exit(1);
 	}
 
 	sprintf(buf, "%s.cps", fname);
-	if ((cfp = open(buf, O_CREAT|O_WRONLY|O_BINARY)) == -1) {
+	if ((cfp = open(buf, O_CREAT|O_WRONLY|O_BINARY, S_IREAD|S_IWRITE|S_IRGRP|S_IROTH)) == -1) {
 		fprintf(stderr, "Couldn't open file: %s\n", buf);
 		exit(1);
 	}
 
 	sprintf(buf, "%s.bks", fname);
-	if ((bfp = open(buf, O_CREAT|O_WRONLY|O_BINARY)) == -1) {
+	if ((bfp = open(buf, O_CREAT|O_WRONLY|O_BINARY, S_IREAD|S_IWRITE|S_IRGRP|S_IROTH)) == -1) {
 		fprintf(stderr, "Couldn't open file: %s\n", buf);
 		exit(1);
 	}

Modified: trunk/utilities/genbookutil.cpp
===================================================================
--- trunk/utilities/genbookutil.cpp	2007-09-29 00:47:00 UTC (rev 2095)
+++ trunk/utilities/genbookutil.cpp	2007-10-07 00:40:00 UTC (rev 2096)
@@ -34,7 +34,7 @@
 void setLocalName(TreeKeyIdx *treeKey) {
 	char buf[1023];
 	std::cout << "Enter New Node Name: ";
-	gets(buf);
+	fgets(buf, 1000, stdin);
 	treeKey->setLocalName(buf);
 	treeKey->save();
 }
@@ -43,7 +43,7 @@
 void gotoPath(TreeKeyIdx *treeKey) {
 	char buf[1023];
 	std::cout << "Enter Path: ";
-	gets(buf);
+	fgets(buf, 1000, stdin);
 	(*treeKey) = buf;
 }
 
@@ -51,7 +51,7 @@
 void assurePath(TreeKeyIdx *treeKey) {
 	char buf[1023];
 	std::cout << "Enter Path: ";
-	gets(buf);
+	fgets(buf, 1000, stdin);
 	treeKey->assureKeyPath(buf);
 }
 
@@ -70,7 +70,7 @@
 		char buf[1023];
 		std::cout << "Enter New Entry Text ('.' on a line by itself to end): \n";
 		do {
-			gets(buf);
+			fgets(buf, 1000, stdin);
 			if ((buf[0] == '.') && (buf[1] == 0))
 				break;
 			body += buf;
@@ -87,7 +87,7 @@
 	if (treeKey->getOffset()) {
 		char buf[1023];
 		std::cout << "Enter New Sibbling Name: ";
-		gets(buf);
+		fgets(buf, 1000, stdin);
 		treeKey->append();
 		treeKey->setLocalName(buf);
 		treeKey->save();
@@ -99,7 +99,7 @@
 void appendChild(TreeKeyIdx *treeKey) {
 	char buf[1023];
 	std::cout << "Enter New Child Name: ";
-	gets(buf);
+	fgets(buf, 1000, stdin);
 	treeKey->appendChild();
 	treeKey->setLocalName(buf);
 	treeKey->save();
@@ -138,7 +138,7 @@
 
 	do {
 		std::cout << "[" << treeKey->getText() << "] > ";
-		gets(line);
+		fgets(line, 1000, stdin);
 		input = line;
 		if (input.length() > 0) {
 			switch (input[0]) {

Modified: trunk/utilities/lexdump.c
===================================================================
--- trunk/utilities/lexdump.c	2007-09-29 00:47:00 UTC (rev 2095)
+++ trunk/utilities/lexdump.c	2007-10-07 00:40:00 UTC (rev 2096)
@@ -1,6 +1,8 @@
 #include <ctype.h>
 #include <stdio.h>
 #include <fcntl.h>
+#include <sys/stat.h>
+#include <sys/types.h>
 #include <errno.h>
 #include <stdlib.h>
 #include <string.h>
@@ -29,9 +31,9 @@
 
 	tmpbuf = calloc(strlen(argv[1]) + 11,1);
 	sprintf(tmpbuf, "%s.idx", argv[1]);
-	idxfd = open(tmpbuf, O_RDONLY|O_BINARY);
+	idxfd = open(tmpbuf, O_RDONLY|O_BINARY, S_IREAD|S_IWRITE|S_IRGRP|S_IROTH);
 	sprintf(tmpbuf, "%s.dat", argv[1]);
-	datfd = open(tmpbuf, O_RDONLY|O_BINARY);
+	datfd = open(tmpbuf, O_RDONLY|O_BINARY, S_IREAD|S_IWRITE|S_IRGRP|S_IROTH);
 	free(tmpbuf);
 
 	offset = atoi(argv[2]) * 6;

Modified: trunk/utilities/no13.c
===================================================================
--- trunk/utilities/no13.c	2007-09-29 00:47:00 UTC (rev 2095)
+++ trunk/utilities/no13.c	2007-10-07 00:40:00 UTC (rev 2096)
@@ -11,7 +11,7 @@
 		fprintf(stderr, "This program writes to stdout, so to be useful,\n\tit should be redirected (e.g no13 bla > bla.dat)\nusage: %s <filename>\n", argv[0]);
 		exit(1);
 	}
-	fd = open(argv[1], O_RDONLY);
+	fd = open(argv[1], O_RDONLY, S_IREAD|S_IWRITE|S_IRGRP|S_IROTH);
 	while (read(fd, &ch, 1) == 1) {
 		if (ch == 0x0d) {	// CR
 			breakcnt++;

Modified: trunk/utilities/step2vpl.cpp
===================================================================
--- trunk/utilities/step2vpl.cpp	2007-09-29 00:47:00 UTC (rev 2095)
+++ trunk/utilities/step2vpl.cpp	2007-10-07 00:40:00 UTC (rev 2096)
@@ -138,7 +138,7 @@
 		bookpath += "/";
 
 	fileName = bookpath + "Book.dat";
-	int fdbook = open(fileName.c_str(), O_RDONLY|O_BINARY);
+	int fdbook = open(fileName.c_str(), O_RDONLY|O_BINARY, S_IREAD|S_IWRITE|S_IRGRP|S_IROTH);
 
 	if (fdbook < 1) {
 		cerr << "error, couldn't open file: " << fileName << "\n";
@@ -151,7 +151,7 @@
 
 
 	fileName = bookpath + "Viewable.idx";
-	int fdviewable = open(fileName.c_str(), O_RDONLY|O_BINARY);
+	int fdviewable = open(fileName.c_str(), O_RDONLY|O_BINARY, S_IREAD|S_IWRITE|S_IRGRP|S_IROTH);
 
 	if (fdviewable < 1) {
 		cerr << "error, couldn't open file: " << fileName << "\n";
@@ -166,7 +166,7 @@
 
 
 	fileName = bookpath + "Vsync.idx";
-	int fdvsync = open(fileName.c_str(), O_RDONLY|O_BINARY);
+	int fdvsync = open(fileName.c_str(), O_RDONLY|O_BINARY, S_IREAD|S_IWRITE|S_IRGRP|S_IROTH);
 
 	if (fdvsync < 1) {
 		cerr << "error, couldn't open file: " << fileName << "\n";
@@ -174,7 +174,7 @@
 	}
 
 	fileName = bookpath + "Sections.idx";
-	int fdsections = open(fileName.c_str(), O_RDONLY|O_BINARY);
+	int fdsections = open(fileName.c_str(), O_RDONLY|O_BINARY, S_IREAD|S_IWRITE|S_IRGRP|S_IROTH);
 
 	if (fdsections < 1) {
 		cerr << "error, couldn't open file: " << fileName << "\n";

Modified: trunk/utilities/stepdump.cpp
===================================================================
--- trunk/utilities/stepdump.cpp	2007-09-29 00:47:00 UTC (rev 2095)
+++ trunk/utilities/stepdump.cpp	2007-10-07 00:40:00 UTC (rev 2096)
@@ -79,7 +79,7 @@
 		bookpath += "/";
 
 	fileName = bookpath + "Book.dat";
-	int fd = open(fileName.c_str(), O_RDONLY|O_BINARY);
+	int fd = open(fileName.c_str(), O_RDONLY|O_BINARY, S_IREAD|S_IWRITE|S_IRGRP|S_IROTH);
 
 	if (fd < 1) {
 		cerr << "error, couldn't open file: " << fileName << "\n";
@@ -92,7 +92,7 @@
 
 
 	fileName = bookpath + "Viewable.idx";
-	int fdv = open(fileName.c_str(), O_RDONLY|O_BINARY);
+	int fdv = open(fileName.c_str(), O_RDONLY|O_BINARY, S_IREAD|S_IWRITE|S_IRGRP|S_IROTH);
 
 	if (fdv < 1) {
 		cerr << "error, couldn't open file: " << fileName << "\n";

Modified: trunk/utilities/vpl2mod.cpp
===================================================================
--- trunk/utilities/vpl2mod.cpp	2007-09-29 00:47:00 UTC (rev 2095)
+++ trunk/utilities/vpl2mod.cpp	2007-10-07 00:40:00 UTC (rev 2096)
@@ -163,7 +163,7 @@
 	}
 
 	// Let's see if we can open our input file
-	int fd = open(argv[1], O_RDONLY|O_BINARY);
+	int fd = open(argv[1], O_RDONLY|O_BINARY, S_IREAD|S_IWRITE|S_IRGRP|S_IROTH);
 	if (fd < 0) {
 		fprintf(stderr, "error: %s: couldn't open input file: %s \n", argv[0], argv[1]);
 		exit(-2);

Modified: trunk/utilities/vpl2zmod2.cpp
===================================================================
--- trunk/utilities/vpl2zmod2.cpp	2007-09-29 00:47:00 UTC (rev 2095)
+++ trunk/utilities/vpl2zmod2.cpp	2007-10-07 00:40:00 UTC (rev 2096)
@@ -176,7 +176,7 @@
 	}
 
 	// Let's see if we can open our input file
-	int fd = open(argv[1], O_RDONLY|O_BINARY);
+	int fd = open(argv[1], O_RDONLY|O_BINARY, S_IREAD|S_IWRITE|S_IRGRP|S_IROTH);
 	if (fd < 0) {
 		fprintf(stderr, "error: %s: couldn't open input file: %s \n", argv[0], argv[1]);
 		exit(-2);




More information about the sword-cvs mailing list