diff options
author | Daniel Glassey <wdg@debian.org> | 2015-09-07 11:14:57 +0100 |
---|---|---|
committer | Daniel Glassey <wdg@debian.org> | 2015-09-07 11:14:57 +0100 |
commit | 7b6c8b08e9d29332dcd0a1029e7421334bfb6f61 (patch) | |
tree | dc263ee8b6c923716a8e0fed64756b7af1238dc7 /utilities/osis2mod.cpp | |
parent | 7a00574163029c0c2b649878c95d5acbd083564a (diff) |
Imported Upstream version 1.7.3+dfsg
Diffstat (limited to 'utilities/osis2mod.cpp')
-rw-r--r-- | utilities/osis2mod.cpp | 107 |
1 files changed, 68 insertions, 39 deletions
diff --git a/utilities/osis2mod.cpp b/utilities/osis2mod.cpp index eab2ee0..b8514b1 100644 --- a/utilities/osis2mod.cpp +++ b/utilities/osis2mod.cpp @@ -2,9 +2,9 @@ * * osis2mod.cpp - Utility to import a module in OSIS format * - * $Id: osis2mod.cpp 2893 2013-07-16 03:07:02Z scribe $ + * $Id: osis2mod.cpp 3177 2014-04-17 04:24:37Z greg.hellings $ * - * Copyright 2003-2013 CrossWire Bible Society (http://www.crosswire.org) + * Copyright 2003-2014 CrossWire Bible Society (http://www.crosswire.org) * CrossWire Bible Society * P. O. Box 2528 * Tempe, AZ 85280-2528 @@ -414,10 +414,10 @@ bool isValidRef(const char *buf) { */ void makeValidRef(VerseKey &key) { VerseKey saveKey; - saveKey.setVersificationSystem(currentVerse.getVersificationSystem()); + saveKey.setVersificationSystem(key.getVersificationSystem()); saveKey.setAutoNormalize(false); saveKey.setIntros(true); - saveKey = currentVerse; + saveKey = key; // Since isValidRef returned false constrain the key to the nearest prior reference. // If we are past the last chapter set the reference to the last chapter @@ -465,7 +465,7 @@ void makeValidRef(VerseKey &key) { void writeEntry(SWBuf &text, bool force = false) { char keyOsisID[255]; - static const char* revision = "<milestone type=\"x-importer\" subType=\"x-osis2mod\" n=\"$Rev: 2893 $\"/>"; + static const char* revision = "<milestone type=\"x-importer\" subType=\"x-osis2mod\" n=\"$Rev: 3177 $\"/>"; static bool firstOT = true; static bool firstNT = true; @@ -528,8 +528,9 @@ void writeEntry(SWBuf &text, bool force = false) { // If the entry already exists, then append this entry to the text. // This is for verses that are outside the chosen versification. They are appended to the prior verse. // The space should not be needed if we retained verse tags. - SWBuf currentText = module->getRawEntry(); - if (currentText.length()) { + if (module->hasEntry(¤tVerse)) { + module->flush(); + SWBuf currentText = module->getRawEntry(); cout << "INFO(WRITE): Appending entry: " << currentVerse.getOSISRef() << ": " << activeVerseText << endl; activeVerseText = currentText + " " + activeVerseText; } @@ -1140,7 +1141,7 @@ bool handleToken(SWBuf &text, XMLTag token) { * requiring each stored entry (i.e. verses) to be well-formed xml. * This routine normalizes container elements which could cross verse boundaries into milestones. * For most of these OSIS elements, there is a milestone form. However, p is not milestoneable. - * For this reason, p is transformed into lb elements. + * For this reason, p is transformed into div elements with type x-p. * param t the tag to transform * return the transformed tag or the original one */ @@ -1161,9 +1162,9 @@ XMLTag transformBSP(XMLTag t) { SWBuf tagName = t.getName(); if (!t.isEndTag()) { - // Transform <p> into <div type="paragraph"> and milestone it + // Transform <p> into <div type="x-p"> and milestone it if (tagName == "p") { - t.setText("<div type=\"paragraph\" />"); + t.setText("<div type=\"x-p\" />"); sprintf(buf, "gen%d", sID++); t.setAttribute("sID", buf); } @@ -1222,7 +1223,7 @@ XMLTag transformBSP(XMLTag t) { tagName == "verse" ) { // make this a clone of the start tag with sID changed to eID - // Note: in the case of </p> the topToken is a <div type="paragraph"> + // Note: in the case of </p> the topToken is a <div type="x-p"> t = topToken; t.setAttribute("eID", t.getAttribute("sID")); t.setAttribute("sID", 0); @@ -1277,10 +1278,10 @@ void writeLinks() } } -void usage(const char *app, const char *error = 0) { - +void usage(const char *app, const char *error = 0, const bool verboseHelp = false) { + if (error) fprintf(stderr, "\n%s: %s\n", app, error); - + fprintf(stderr, "OSIS Bible/commentary module creation tool for The SWORD Project\n"); fprintf(stderr, "\nusage: %s <output/path> <osisDoc> [OPTIONS]\n", app); fprintf(stderr, " <output/path>\t\t an existing folder that the module will be written\n"); @@ -1293,37 +1294,57 @@ void usage(const char *app, const char *error = 0) { fprintf(stderr, "\t\t\t\t 2 - verse; 3 - chapter; 4 - book\n"); fprintf(stderr, " -c <cipher_key>\t encipher module using supplied key\n"); fprintf(stderr, "\t\t\t\t (default no enciphering)\n"); + +#ifdef _ICU_ fprintf(stderr, " -N\t\t\t do not convert UTF-8 or normalize UTF-8 to NFC\n"); - fprintf(stderr, "\t\t\t\t (default is to convert to UTF-8, if needed,\n"); - fprintf(stderr, "\t\t\t\t and then normalize to NFC)\n"); - fprintf(stderr, "\t\t\t\t Note: UTF-8 texts should be normalized to NFC.\n"); + if (verboseHelp) { + fprintf(stderr, "\t\t\t\t (default is to convert to UTF-8, if needed,\n"); + fprintf(stderr, "\t\t\t\t and then normalize to NFC)\n"); + fprintf(stderr, "\t\t\t\t Note: UTF-8 texts should be normalized to NFC.\n"); + } +#endif + fprintf(stderr, " -s <2|4>\t\t bytes used to store entry size (default is 2).\n"); - fprintf(stderr, "\t\t\t\t Note: useful for commentaries with very large\n"); - fprintf(stderr, "\t\t\t\t entries in uncompressed modules\n"); - fprintf(stderr, "\t\t\t\t (2 bytes to store size equal 65535 characters)\n"); + if (verboseHelp) { + fprintf(stderr, "\t\t\t\t Note: useful for commentaries with very large\n"); + fprintf(stderr, "\t\t\t\t entries in uncompressed modules\n"); + fprintf(stderr, "\t\t\t\t (2 bytes to store size equal 65535 characters)\n"); + } fprintf(stderr, " -v <v11n>\t\t specify a versification scheme to use (default is KJV)\n"); - fprintf(stderr, "\t\t\t\t Note: The following are valid values for v11n:\n"); + fprintf(stderr, "\t\t\t\t Note: The following are valid values for v11n:"); + VersificationMgr *vmgr = VersificationMgr::getSystemVersificationMgr(); StringList av11n = vmgr->getVersificationSystems(); for (StringList::iterator loop = av11n.begin(); loop != av11n.end(); loop++) { - fprintf(stderr, "\t\t\t\t\t%s\n", (*loop).c_str()); + if ((distance(av11n.begin(), loop) % 3) == 0) { + fprintf(stderr, "\n\t\t\t\t %-12s", (*loop).c_str()); + } + else { + fprintf(stderr, "\t%-12s", (*loop).c_str()); + } } - fprintf(stderr, " -d <flags>\t\t turn on debugging (default is 0)\n"); - fprintf(stderr, "\t\t\t\t Note: This flag may change in the future.\n"); - fprintf(stderr, "\t\t\t\t Flags: The following are valid values:\n"); - fprintf(stderr, "\t\t\t\t\t0 - no debugging\n"); - fprintf(stderr, "\t\t\t\t\t1 - writes to module, very verbose\n"); - fprintf(stderr, "\t\t\t\t\t2 - verse start and end\n"); - fprintf(stderr, "\t\t\t\t\t4 - quotes, esp. Words of Christ\n"); - fprintf(stderr, "\t\t\t\t\t8 - titles\n"); - fprintf(stderr, "\t\t\t\t\t16 - inter-verse material\n"); - fprintf(stderr, "\t\t\t\t\t32 - BSP to BCV transformations\n"); - fprintf(stderr, "\t\t\t\t\t64 - v11n exceptions\n"); - fprintf(stderr, "\t\t\t\t\t128 - parsing of osisID and osisRef\n"); - fprintf(stderr, "\t\t\t\t\t256 - internal stack\n"); - fprintf(stderr, "\t\t\t\t\t512 - miscellaneous\n"); - fprintf(stderr, "\t\t\t\t This argument can be used more than once. (Or\n"); - fprintf(stderr, "\t\t\t\t the flags may be added together.)\n"); + fprintf(stderr, "\n"); + + if (verboseHelp) { + fprintf(stderr, " -d <flags>\t\t turn on debugging (default is 0)\n"); + fprintf(stderr, "\t\t\t\t Note: This flag may change in the future.\n"); + fprintf(stderr, "\t\t\t\t Flags: The following are valid values:\n"); + fprintf(stderr, "\t\t\t\t\t0 - no debugging\n"); + fprintf(stderr, "\t\t\t\t\t1 - writes to module, very verbose\n"); + fprintf(stderr, "\t\t\t\t\t2 - verse start and end\n"); + fprintf(stderr, "\t\t\t\t\t4 - quotes, esp. Words of Christ\n"); + fprintf(stderr, "\t\t\t\t\t8 - titles\n"); + fprintf(stderr, "\t\t\t\t\t16 - inter-verse material\n"); + fprintf(stderr, "\t\t\t\t\t32 - BSP to BCV transformations\n"); + fprintf(stderr, "\t\t\t\t\t64 - v11n exceptions\n"); + fprintf(stderr, "\t\t\t\t\t128 - parsing of osisID and osisRef\n"); + fprintf(stderr, "\t\t\t\t\t256 - internal stack\n"); + fprintf(stderr, "\t\t\t\t\t512 - miscellaneous\n"); + fprintf(stderr, "\t\t\t\t This argument can be used more than once. (Or\n"); + fprintf(stderr, "\t\t\t\t the flags may be added together.)\n"); + } + fprintf(stderr, " -h \t\t\t print verbose usage text\n"); + fprintf(stderr, "\n"); fprintf(stderr, "See http://www.crosswire.org/wiki/osis2mod for more details.\n"); fprintf(stderr, "\n"); @@ -1531,7 +1552,15 @@ void processOSIS(istream& infile) { int main(int argc, char **argv) { - fprintf(stderr, "You are running osis2mod: $Rev: 2893 $\n"); + fprintf(stderr, "You are running osis2mod: $Rev: 3177 $\n"); + + if (argc > 1) { + for (int i = 1; i < argc; i++) { + if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) { + usage(*argv, "", true); + } + } + } // Let's test our command line arguments if (argc < 3) { |