From ce0df2e4d80be9035ef1ebd590ef6501582eb297 Mon Sep 17 00:00:00 2001 From: "Troy A. Griffitts" Date: Wed, 2 Jun 2010 11:17:47 +0000 Subject: latest fixed for first cut. Mostly valid XML and OSIS... git-svn-id: https://www.crosswire.org/svn/sword-tools/trunk@278 07627401-56e2-0310-80f4-f8cd0041bdcd --- modules/nasb/cutil/nasbosis.cpp | 254 +++++++++++++++++++++------------------- 1 file changed, 134 insertions(+), 120 deletions(-) (limited to 'modules/nasb/cutil') diff --git a/modules/nasb/cutil/nasbosis.cpp b/modules/nasb/cutil/nasbosis.cpp index b002388..0d408c4 100644 --- a/modules/nasb/cutil/nasbosis.cpp +++ b/modules/nasb/cutil/nasbosis.cpp @@ -111,9 +111,9 @@ void outTrailer(); void unicodeTicks(string &outstring); void prepLine(string &outstring, int currentTestament, bool note); string getNoteBody(int nfd, string ¬eLine, string osisID, int currentBookNo, int currentChapter, int currentVerse, string nStr, const char *nx); -#ifdef HAVESWORD -const char *convertToOSIS(const char *inRef, const SWKey *key); -#endif + + + int main(int argc, char **argv) { @@ -190,8 +190,8 @@ int main(int argc, char **argv) { // BOOK NAMES - if (!strncmp(buffer, "", 4)) { - string book = buffer+4; + if (!strncmp(outstring.c_str(), "", 4)) { + string book = outstring.c_str()+4; book = book.substr(0, book.find_first_of("<")); outstring = ""; if (inVerse) { @@ -230,8 +230,8 @@ int main(int argc, char **argv) { // CHAPTERS //PSALM - if ((!strncmp(buffer, "CHAPTER", 11)) || (!strncmp(buffer, "PSALM", 9))) { - string chapterTitle = buffer+4; + if ((!strncmp(outstring.c_str(), "CHAPTER", 11)) || (!strncmp(outstring.c_str(), "PSALM", 9))) { + string chapterTitle = outstring.c_str()+4; chapterTitle = chapterTitle.substr(0, chapterTitle.find_first_of("<")); string chapter = chapterTitle.substr((chapterTitle[0] == 'C')?8:6); outstring = ""; @@ -251,9 +251,9 @@ int main(int argc, char **argv) { // - if (!strncmp(buffer, "", 4)) { + if (!strncmp(outstring.c_str(), "", 4)) { outstring = ""; - string heading = buffer+4; + string heading = outstring.c_str()+4; heading = heading.substr(0, heading.find("")); if (!strncmp(lookahead.c_str(), "", 4)) { @@ -264,32 +264,18 @@ int main(int argc, char **argv) { outstring += "\n"; inVerse = false; } - const char *found = strstr(buffer+4, "L\\{ORD}/'\\{S}/"); - int start = (found) ? (found - (buffer+4)) : -1; - if (start > -1) - heading.replace(start, 14, "Lord's"); - else { - found = strstr(buffer+4, "L\\{ORD}/"); - start = (found) ? (found - (buffer+4)) : -1; - if (start > -1) - heading.replace(start, 8, "Lord"); - } outstring += (string)"" + heading + (string)""; } - if (!strncmp(buffer, "", 4)) { - string heading = (buffer+4); - const char *found = strstr(buffer+4, "L\\{ORD}/'\\{S}/"); - int start = (found) ? (found - (buffer+4)) : -1; - if (start > -1) - heading.replace(start, 14, "Lord's"); - else { - found = strstr(buffer+4, "L\\{ORD}/"); - start = (found) ? (found - (buffer+4)) : -1; - if (start > -1) - heading.replace(start, 8, "Lord"); - } + if (!strncmp(outstring.c_str(), "", 4)) { + string heading = (outstring.c_str()+4); + heading = heading.substr(0, heading.find("")); outstring = (string)"" + heading + (string)""; } + if (!strncmp(outstring.c_str(), "", 4)) { + string heading = (outstring.c_str()+4); + heading = heading.substr(0, heading.find("")); + outstring = (string)"" + heading + (string)""; + } @@ -359,34 +345,47 @@ int main(int argc, char **argv) { } } - // + // outstr = outstring.c_str(); - found = strstr(outstr, ""); + found = strstr(outstr, ""); start = (found) ? (found - outstr) : -1; if (start > -1) { - outstring.replace(start, 3, (string)""); + outstring.replace(start, 4, (string)""); continue; } - // + // outstr = outstring.c_str(); - found = strstr(outstr, ""); + found = strstr(outstr, ""); start = (found) ? (found - outstr) : -1; if (start > -1) { - outstring.replace(start, 3, (string)""); + outstring.replace(start, 5, (string)""); continue; } + + // outstr = outstring.c_str(); found = strstr(outstr, ""); start = (found) ? (found - outstr) : -1; if (start > -1) { - outstring.replace(start, 4, (string)""); + outstring.replace(start, 4, (string)""); + continue; + + } + + // + outstr = outstring.c_str(); + found = strstr(outstr, ""); + start = (found) ? (found - outstr) : -1; + + if (start > -1) { + outstring.replace(start, 5, (string)""); continue; } @@ -457,16 +456,6 @@ int main(int argc, char **argv) { outstring.replace(start, 3, (string)""); continue; - } - // - outstr = outstring.c_str(); - found = strstr(outstr, ""); - start = (found) ? (found - outstr) : -1; - - if (start > -1) { - outstring.replace(start, 4, (string)""); - continue; - } // outstr = outstring.c_str(); @@ -514,7 +503,7 @@ int main(int argc, char **argv) { start = (found) ? (found - outstr) : -1; if (start > -1) { - outstring.replace(start, 4, (string)""); + outstring.replace(start, 4, (string)""); continue; } @@ -544,7 +533,7 @@ int main(int argc, char **argv) { start = (found) ? (found - outstr) : -1; if (start > -1) { - outstring.replace(start, 4, (string)""); + outstring.replace(start, 4, (string)""); continue; } @@ -601,6 +590,10 @@ int main(int argc, char **argv) { strongsStart = i+1; inNote = false; } + if (!strncmp(lastToken.c_str(), "q who=\"Jesus\"", 13)) { + strongsFound = false; + strongsStart = i+1; + } if (!strncmp(lastToken.c_str(), "seg type=\"otPassage\"", 19)) { strongsFound = false; strongsStart = i+1; @@ -772,11 +765,73 @@ void unicodeTicks(string &outstring) { void prepLine(string &outstring, int currentTestament, bool note) { int end = 0; while (1) { +// ------------------------------------------ +// redundant markers + size_t s; + // + s = outstring.find(""); + if (s != string::npos) { + outstring.erase(s, 3); + continue; + } + + //

+ s = outstring.find("

"); + if (s != string::npos) { + outstring.erase(s, 3); + continue; + } + + // + s = outstring.find(""); + if (s != string::npos) { + outstring.erase(s, 3); + continue; + } + + // + s = outstring.find(""); + if (s != string::npos) { + outstring.erase(s, 4); + continue; + } + + // + s = outstring.find(""); + if (s != string::npos) { + outstring.erase(s, 4); + continue; + } + + // <$F...>> + s = outstring.find("<$F"); + if (s != string::npos) { + size_t e = outstring.find(">>", s); + outstring.erase(s, e-s+2); + continue; + } +// ---------------------------------------------- + + // + s = outstring.find(""); + if (s != string::npos) { + outstring.replace(s, 3, ""); + continue; + } + + const char *outstr = outstring.c_str(); - const char *found = strstr(outstr, "L\\{ORD}/"); + const char *found = strstr(outstr, "L\\{ORD}/'\\{S}/"); int start = (found) ? (found - outstr) : -1; if (start > -1) { - outstring.replace(start, 8, "Lord"); + outstring.replace(start, 14, "Lord's"); + continue; + } + outstr = outstring.c_str(); + found = strstr(outstr, "L\\{ORD}/"); + start = (found) ? (found - outstr) : -1; + if (start > -1) { + outstring.replace(start, 8, "Lord,"); continue; } outstr = outstring.c_str(); @@ -900,22 +955,27 @@ void prepLine(string &outstring, int currentTestament, bool note) { continue; } - if (note) { - outstr = outstring.c_str(); - found = strstr(outstr, "{"); - start = (found) ? (found - outstr) : -1; - if (start > -1) { - outstring.replace(start, 1, ""); - continue; - } - outstr = outstring.c_str(); - found = strstr(outstr, "}"); - start = (found) ? (found - outstr) : -1; - if (start > -1) { - outstring.replace(start, 1, ""); - continue; + if (note) { + outstr = outstring.c_str(); + found = strstr(outstr, "{"); + start = (found) ? (found - outstr) : -1; + if (start > -1) { + outstring.replace(start, 1, ""); + continue; + } + outstr = outstring.c_str(); + found = strstr(outstr, "}"); + start = (found) ? (found - outstr) : -1; + if (start > -1) { + outstring.replace(start, 1, ""); + continue; + } + s = outstring.find(""); + if (s != string::npos) { + outstring.replace(s, 17, ""); + continue; + } } - } break; } } @@ -976,8 +1036,14 @@ string getNoteBody(int fdn, string ¬eLine, string osisID, int currentBookNo, if (start > -1) { retVal.replace(start, 3, " "); } + outstr = retVal.c_str(); + found = strstr(outstr, ";}"); + start = (found) ? (found - outstr) : -1; + if (start > -1) { + retVal.replace(start, 2, "};"); + } VerseKey key = osisID.c_str(); - retVal = convertToOSIS(retVal.c_str(), &key); + retVal = VerseKey::convertToOSIS(retVal.c_str(), &key); } #endif prepLine(retVal, 0, true); @@ -986,55 +1052,3 @@ string getNoteBody(int fdn, string ¬eLine, string osisID, int currentBookNo, return retVal; } -#ifdef HAVESWORD -const char *convertToOSIS(const char *inRef, const SWKey *key) { - static SWBuf outRef; - - outRef = ""; - - VerseKey defLanguage; - ListKey verses = defLanguage.ParseVerseList(inRef, (*key), true); - const char *startFrag = inRef; - for (int i = 0; i < verses.Count(); i++) { - VerseKey *element = SWDYNAMIC_CAST(VerseKey, verses.GetElement(i)); - char buf[5120]; - char frag[800]; - char preJunk[800]; - char postJunk[800]; - memset(buf, 0, 5120); - memset(frag, 0, 800); - memset(preJunk, 0, 800); - memset(postJunk, 0, 800); - while ((*startFrag) && (strchr(" {};,()[].", *startFrag))) { - outRef += *startFrag; - startFrag++; - } - if (element) { - memmove(frag, startFrag, ((const char *)element->userData - startFrag) + 1); - frag[((const char *)element->userData - startFrag) + 1] = 0; - int j; - for (j = strlen(frag)-1; j && (strchr(" {};,()[].", frag[j])); j--); - if (frag[j+1]) - strcpy(postJunk, frag+j+1); - frag[j+1]=0; - startFrag += ((const char *)element->userData - startFrag) + 1; - sprintf(buf, "%s%s", element->LowerBound().getOSISRef(), element->UpperBound().getOSISRef(), frag, postJunk); - } - else { - memmove(frag, startFrag, ((const char *)verses.GetElement(i)->userData - startFrag) + 1); - frag[((const char *)verses.GetElement(i)->userData - startFrag) + 1] = 0; - int j; - for (j = strlen(frag)-1; j && (strchr(" {};,()[].", frag[j])); j--); - if (frag[j+1]) - strcpy(postJunk, frag+j+1); - frag[j+1]=0; - startFrag += ((const char *)verses.GetElement(i)->userData - startFrag) + 1; - sprintf(buf, "%s%s", VerseKey(*verses.GetElement(i)).getOSISRef(), frag, postJunk); - } - outRef+=buf; - } - if (startFrag < (inRef + strlen(inRef))) - outRef+=startFrag; - return outRef.c_str(); -} -#endif -- cgit