[sword-cvs] sword/src/modules swmodule.cpp,1.50,1.51

sword@www.crosswire.org sword@www.crosswire.org
Mon, 10 Nov 2003 00:24:14 -0700


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

Modified Files:
	swmodule.cpp 
Log Message:
Added new search type for searching entry attributes: e.g.
AVPhrase//Phrase/savior
Need to change last leg to be regex instead of strstr


Index: swmodule.cpp
===================================================================
RCS file: /usr/local/cvsroot/sword/src/modules/swmodule.cpp,v
retrieving revision 1.50
retrieving revision 1.51
diff -u -d -r1.50 -r1.51
--- swmodule.cpp	29 Aug 2003 06:00:16 -0000	1.50
+++ swmodule.cpp	10 Nov 2003 07:24:11 -0000	1.51
@@ -357,6 +357,7 @@
  *				>=0 - regex
  *				-1  - phrase
  *				-2  - multiword
+ *				-3  - entryAttrib
  * 	flags		- options flags for search
  *	justCheckIfSupported	- if set, don't search, only tell if this
  *							function supports requested search.
@@ -377,7 +378,8 @@
 	char perc = 1;
 	bool savePEA = isProcessEntryAttributes();
 
-	processEntryAttributes(false);
+	processEntryAttributes(searchType == -3);
+	
 	listkey.ClearList();
 
 	if (!key->Persist()) {
@@ -435,6 +437,32 @@
 		}
 	}
 
+	if (searchType == -3) {
+		wordBuf = (char *)calloc(sizeof(char), strlen(istr) + 1);
+		char *checkSlash = wordBuf;
+		strcpy(wordBuf, istr);
+		words = (char **)calloc(sizeof(char *), 10);
+		int allocWords = 10;
+		while (*checkSlash == '/')
+			words[wordCount++] = checkSlash++;
+		words[wordCount] = strtok(wordBuf, "/");
+		while (words[wordCount]) {
+			wordCount++;
+			if (wordCount == allocWords) {
+				allocWords+=10;
+				words = (char **)realloc(words, sizeof(char *)*allocWords);
+			}
+			checkSlash = words[wordCount-1] + (strlen(words[wordCount-1]))+1;
+			while (*checkSlash == '/')
+				words[wordCount++] = checkSlash++;
+			words[wordCount] = strtok(NULL, "/");
+		}
+		for (int i = 0; i < wordCount; i++) {
+			if (words[i][0] == '/')
+				words[i][0] = 0;
+		}
+	}
+
 	perc = 5;
 	(*percent)(perc, percentUserData);
 
@@ -470,27 +498,79 @@
 				listkey << textkey;
 			}
 		}
-		else {
-			if (searchType == -1) {
-				sres = ((flags & REG_ICASE) == REG_ICASE) ? stristr(StripText(), istr) : strstr(StripText(), istr);
-				if (sres) {
-						textkey = KeyText();
-						listkey << textkey;
-				}
-			}
-			if (searchType == -2) {
-				int i;
-				const char *stripBuf = StripText();
-				for (i = 0; i < wordCount; i++) {
-					sres = ((flags & REG_ICASE) == REG_ICASE) ? stristr(stripBuf, words[i]) : strstr(stripBuf, words[i]);
-					if (!sres)
-						break;
-				}
-				if (i == wordCount) {
+		else if (searchType == -1) {
+			sres = ((flags & REG_ICASE) == REG_ICASE) ? stristr(StripText(), istr) : strstr(StripText(), istr);
+			if (sres) {
 					textkey = KeyText();
 					listkey << textkey;
-				}
+			}
+		}
+		else if (searchType == -2) {
+			int i;
+			const char *stripBuf = StripText();
+			for (i = 0; i < wordCount; i++) {
+				sres = ((flags & REG_ICASE) == REG_ICASE) ? stristr(stripBuf, words[i]) : strstr(stripBuf, words[i]);
+				if (!sres)
+					break;
+			}
+			if (i == wordCount) {
+				textkey = KeyText();
+				listkey << textkey;
+			}
+		}
+		else if (searchType == -3) {
+			int i;
+			RenderText();	// force parse
+			AttributeTypeList &entryAttribs = getEntryAttributes();
+			AttributeTypeList::iterator i1Start, i1End;
+			AttributeList::iterator i2Start, i2End;
+			AttributeValue::iterator i3Start, i3End;
 
+			if ((words[0]) && (words[0][0])) {
+				i1Start = entryAttribs.find(words[0]);
+				i1End = i1Start;
+				if (i1End != entryAttribs.end())
+				i1End++;
+			}
+			else {
+				i1Start = entryAttribs.begin();
+				i1End   = entryAttribs.end();
+			}
+			for (;i1Start != i1End; i1Start++) {
+				if ((words[1]) && (words[1][0])) {
+					i2Start = i1Start->second.find(words[1]);
+					i2End = i2Start;
+					if (i2End != i1Start->second.end())
+						i2End++;
+				}
+				else {
+					i2Start = i1Start->second.begin();
+					i2End   = i1Start->second.end();
+				}
+				for (;i2Start != i2End; i2Start++) {
+					if ((words[2]) && (words[2][0])) {
+						i3Start = i2Start->second.find(words[2]);
+						i3End = i3Start;
+						if (i3End != i2Start->second.end())
+							i3End++;
+					}
+					else {
+						i3Start = i2Start->second.begin();
+						i3End   = i2Start->second.end();
+					}
+					for (;i3Start != i3End; i3Start++) {
+						sres = ((flags & REG_ICASE) == REG_ICASE) ? stristr(i3Start->second.c_str(), words[3]) : strstr(i3Start->second.c_str(), words[3]);
+						if (sres) {
+							textkey = KeyText();
+							listkey << textkey;
+							break;
+						}
+					}
+					if (i3Start != i3End)
+						break;
+				}
+				if (i2Start != i2End)
+					break;
 			}
 		}
 		(*this)++;