diff options
author | Troy A. Griffitts <scribe@crosswire.org> | 2010-06-02 11:17:47 +0000 |
---|---|---|
committer | Troy A. Griffitts <scribe@crosswire.org> | 2010-06-02 11:17:47 +0000 |
commit | ce0df2e4d80be9035ef1ebd590ef6501582eb297 (patch) | |
tree | a9b8de7d63b1f327163453b79f4b296852c917f8 /modules | |
parent | 1d7d78d110fb952872b423ab9cd4f990bbee23f5 (diff) | |
download | sword-tools-ce0df2e4d80be9035ef1ebd590ef6501582eb297.tar.gz |
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
Diffstat (limited to 'modules')
-rw-r--r-- | modules/nasb/cutil/nasbosis.cpp | 254 |
1 files changed, 134 insertions, 120 deletions
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 <BN> - if (!strncmp(buffer, "<BN>", 4)) { - string book = buffer+4; + if (!strncmp(outstring.c_str(), "<BN>", 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 //<SN>PSALM - if ((!strncmp(buffer, "<CN>CHAPTER", 11)) || (!strncmp(buffer, "<SN>PSALM", 9))) { - string chapterTitle = buffer+4; + if ((!strncmp(outstring.c_str(), "<CN>CHAPTER", 11)) || (!strncmp(outstring.c_str(), "<SN>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) { //<SH> - if (!strncmp(buffer, "<SH>", 4)) { + if (!strncmp(outstring.c_str(), "<SH>", 4)) { outstring = ""; - string heading = buffer+4; + string heading = outstring.c_str()+4; heading = heading.substr(0, heading.find("</SH>")); if (!strncmp(lookahead.c_str(), "<PM>", 4)) { @@ -264,32 +264,18 @@ int main(int argc, char **argv) { outstring += "</verse>\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, "<divineName>Lord's</divineName>"); - else { - found = strstr(buffer+4, "L\\{ORD}/"); - start = (found) ? (found - (buffer+4)) : -1; - if (start > -1) - heading.replace(start, 8, "<divineName>Lord</divineName>"); - } outstring += (string)"<title type=\"sub\" subType=\"x-Section\">" + heading + (string)"</title>"; } - if (!strncmp(buffer, "<SS>", 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, "<divineName>Lord's</divineName>"); - else { - found = strstr(buffer+4, "L\\{ORD}/"); - start = (found) ? (found - (buffer+4)) : -1; - if (start > -1) - heading.replace(start, 8, "<divineName>Lord</divineName>"); - } + if (!strncmp(outstring.c_str(), "<SS>", 4)) { + string heading = (outstring.c_str()+4); + heading = heading.substr(0, heading.find("</SS>")); outstring = (string)"<title type=\"sub\" subType=\"x-SS\">" + heading + (string)"</title>"; } + if (!strncmp(outstring.c_str(), "<SB>", 4)) { + string heading = (outstring.c_str()+4); + heading = heading.substr(0, heading.find("</SB>")); + outstring = (string)"<title type=\"sub\" subType=\"x-SB\">" + heading + (string)"</title>"; + } @@ -359,34 +345,47 @@ int main(int argc, char **argv) { } } - // <C> + // <SF> outstr = outstring.c_str(); - found = strstr(outstr, "<C>"); + found = strstr(outstr, "<SF>"); start = (found) ? (found - outstr) : -1; if (start > -1) { - outstring.replace(start, 3, (string)""); + outstring.replace(start, 4, (string)"<seg type=\"x-SF\">"); continue; } - // <V> + // <SF> outstr = outstring.c_str(); - found = strstr(outstr, "<V>"); + found = strstr(outstr, "</SF>"); start = (found) ? (found - outstr) : -1; if (start > -1) { - outstring.replace(start, 3, (string)""); + outstring.replace(start, 5, (string)"</seg>"); continue; } + + // <RS> outstr = outstring.c_str(); found = strstr(outstr, "<RS>"); start = (found) ? (found - outstr) : -1; if (start > -1) { - outstring.replace(start, 4, (string)"<milestone type=\"x-RS\"/>"); + outstring.replace(start, 4, (string)"<q who=\"Jesus\">"); + continue; + + } + + // <RS> + outstr = outstring.c_str(); + found = strstr(outstr, "</RS>"); + start = (found) ? (found - outstr) : -1; + + if (start > -1) { + outstring.replace(start, 5, (string)"</q>"); continue; } @@ -458,16 +457,6 @@ int main(int argc, char **argv) { continue; } - // <SF> - outstr = outstring.c_str(); - found = strstr(outstr, "<SF>"); - start = (found) ? (found - outstr) : -1; - - if (start > -1) { - outstring.replace(start, 4, (string)"<milestone type=\"x-SF\"/>"); - continue; - - } // <NA> outstr = outstring.c_str(); found = strstr(outstr, "<NA>"); @@ -514,7 +503,7 @@ int main(int argc, char **argv) { start = (found) ? (found - outstr) : -1; if (start > -1) { - outstring.replace(start, 4, (string)"<seg type=\"x-PN\" />"); + outstring.replace(start, 4, (string)"<milestone type=\"x-PN\" />"); continue; } @@ -544,7 +533,7 @@ int main(int argc, char **argv) { start = (found) ? (found - outstr) : -1; if (start > -1) { - outstring.replace(start, 4, (string)"<seg type=\"x-HL\" />"); + outstring.replace(start, 4, (string)"<milestone type=\"x-HL\" />"); 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; + // <V> + s = outstring.find("<V>"); + if (s != string::npos) { + outstring.erase(s, 3); + continue; + } + + // <P> + s = outstring.find("<P>"); + if (s != string::npos) { + outstring.erase(s, 3); + continue; + } + + // <C> + s = outstring.find("<C>"); + if (s != string::npos) { + outstring.erase(s, 3); + continue; + } + + // <CC> + s = outstring.find("<CC>"); + if (s != string::npos) { + outstring.erase(s, 4); + continue; + } + + // <CP> + s = outstring.find("<CP>"); + 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; + } +// ---------------------------------------------- + + // <A> + s = outstring.find("<A>"); + if (s != string::npos) { + outstring.replace(s, 3, "<milestone type=\"line\" subType=\"x-A\"/>"); + 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, "<divineName>Lord</divineName>"); + outstring.replace(start, 14, "<divineName>Lord's</divineName>"); + continue; + } + outstr = outstring.c_str(); + found = strstr(outstr, "L\\{ORD}/"); + start = (found) ? (found - outstr) : -1; + if (start > -1) { + outstring.replace(start, 8, "<divineName>Lord</divineName>,"); 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, "<hi type=\"italic\">"); - continue; - } - outstr = outstring.c_str(); - found = strstr(outstr, "}"); - start = (found) ? (found - outstr) : -1; - if (start > -1) { - outstring.replace(start, 1, "</hi>"); - continue; + if (note) { + outstr = outstring.c_str(); + found = strstr(outstr, "{"); + start = (found) ? (found - outstr) : -1; + if (start > -1) { + outstring.replace(start, 1, "<hi type=\"italic\">"); + continue; + } + outstr = outstring.c_str(); + found = strstr(outstr, "}"); + start = (found) ? (found - outstr) : -1; + if (start > -1) { + outstring.replace(start, 1, "</hi>"); + continue; + } + s = outstring.find("</reference></hi>"); + if (s != string::npos) { + outstring.replace(s, 17, "</hi></reference>"); + 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, "<reference osisRef=\"%s-%s\">%s</reference>%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, "<reference osisRef=\"%s\">%s</reference>%s", VerseKey(*verses.GetElement(i)).getOSISRef(), frag, postJunk); - } - outRef+=buf; - } - if (startFrag < (inRef + strlen(inRef))) - outRef+=startFrag; - return outRef.c_str(); -} -#endif |