private void convertButton_Click(object sender, System.EventArgs e) { Logit.OpenFile("WordSendLog.txt"); Logit.GUIWriteString = new StringDelegate(WriteToStatusListBox); Logit.WriteLine("Sorry, this program is still under construction."); Logit.CloseFile(); }
/// <summary> /// Copy a node from the current XmlTextReader object to the given XmlTextWriter object. /// </summary> /// <param name="xw">the XmlTextWriter object to write to</param> public void CopyNode(XmlTextWriter xw) { switch (NodeType) { case XmlNodeType.Element: xw.WriteStartElement(Name); xw.WriteAttributes(this, true); if (IsEmptyElement) { xw.WriteEndElement(); } break; case XmlNodeType.EndElement: xw.WriteEndElement(); break; case XmlNodeType.Text: xw.WriteString(Value); break; case XmlNodeType.SignificantWhitespace: xw.WriteWhitespace(Value); break; case XmlNodeType.Whitespace: // You could insert xw.WriteWhitespace(Value); to preserve // insignificant white space, but it either adds bloat or // messes up formatting. break; case XmlNodeType.Attribute: xw.WriteAttributeString(Name, Value); break; case XmlNodeType.ProcessingInstruction: xw.WriteProcessingInstruction(Name, Value); break; case XmlNodeType.XmlDeclaration: xw.WriteStartDocument(true); break; default: Logit.WriteLine("Doing NOTHING with type=" + NodeType.ToString() + " Name=" + Name + " Value=" + Value); // DEBUG break; } }
static void Main(string[] args) { int i; bool showBanner = true; string logName = "usfm2usfxlog.txt"; string outName = ""; ArrayList fileSpecs = new ArrayList(127); Logit.useConsole = true; for (i = 0; i < args.Length; i++) { // Scan the command line string s = args[i]; if ((s != null) && (s.Length > 0)) { if (((s[0] == '-') || (s[0] == '/')) && (s.Length > 1)) { // command line switch: take action switch (Char.ToLower(s[1])) { case 'n': // No banner display showBanner = false; break; case 'o': // Set output file name outName = SFConverter.GetOption(ref i, args); break; case 'l': // Set log name logName = SFConverter.GetOption(ref i, args); break; case '-': case 'h': case '?': showBanner = true; break; default: Logit.WriteLine("Unrecognized command line switch: " + args[i]); showBanner = true; break; } } else { fileSpecs.Add(args[i]); } } } Logit.OpenFile(logName); if (showBanner) { Logit.WriteLine("This is part of Haiola open source software."); Logit.WriteLine("Please see http://haiola.org for copyright information."); Logit.WriteLine(@" Syntax: usfm2usfx [-o Output] [-n] [-l logname] [-?] filespec(s) Output = output USFX file name -n = don't display copyright and banner information. logname = log file name (default is usfm2usfxlog.txt) -? = cancel previous /n and show this information. filespec = SFM file specification(s) to read. Wild cards are OK. You may use / instead of - to introduce switches. Do not use either of those two characters as the first character of a file name. "); } if (outName == "") { outName = "output.usfx.xml"; } if (fileSpecs.Count < 1) { Logit.WriteLine("Nothing to do. No input files specified."); } else { // Instantiate the object that does most of the work. SFConverter.scripture = new Scriptures(); // Read the input USFM files into internal data structures. for (i = 0; i < fileSpecs.Count; i++) { SFConverter.ProcessFilespec((string)fileSpecs[i]); } // Write out the USFX file. SFConverter.scripture.WriteUSFX(outName); } }
public bool ConvertUsfxToSile(string usfxFileName, string sileDirectory) { bool result = false; sileDir = sileDirectory; usfx = new XmlTextReader(usfxFileName); usfx.WhitespaceHandling = WhitespaceHandling.All; while (usfx.Read()) { Logit.ShowStatus("converting to SILE " + cv); if (usfx.NodeType == XmlNodeType.Element) { level = usfx.GetAttribute("level"); style = usfx.GetAttribute("style"); sfm = usfx.GetAttribute("sfm"); caller = usfx.GetAttribute("caller"); id = usfx.GetAttribute("id"); switch (usfx.Name) { case "languageCode": SkipElement(); break; case "book": currentBookHeader = currentBookTitle = String.Empty; toc1 = toc2 = toc3 = String.Empty; inToc1 = inToc2 = inToc3 = false; currentChapter = currentChapterPublished = currentChapterAlternate = String.Empty; currentVerse = currentVersePublished = currentVerseAlternate = String.Empty; titleWritten = false; chapterWritten = false; if (id.Length > 2) { currentBookAbbrev = id; bookRecord = (BibleBookRecord)bookInfo.books[currentBookAbbrev]; } if ((bookRecord == null) || (id.Length <= 2)) { Logit.WriteError("Cannot process unknown book: " + currentBookAbbrev); return(false); } if ((bookRecord.testament == "a") && !globe.projectOptions.includeApocrypha) { SkipElement(); } else if (!globe.projectOptions.allowedBookList.Contains(bookRecord.tla)) // Check for presence of book in bookorder.txt { SkipElement(); } else { // We have a book we want to write out. OpenSileFile(); } break; case "fe": // End note. Rarely used, fortunately, but in the standards. Treat as regular footnote. case "f": // footnote if (!usfx.IsEmptyElement) { if (caller == "-") { caller = String.Empty; } else if ((caller == "+") || (String.IsNullOrEmpty(caller))) { caller = footnoteMark.Marker(); } sileFile.WriteStartElement("f"); sileFile.WriteAttributeString("caller", caller); } break; case "x": // Cross references if (!usfx.IsEmptyElement) { if (caller == "-") { caller = String.Empty; } else if ((caller == "+") || (String.IsNullOrEmpty(caller))) { caller = xrefMark.Marker(); } sileFile.WriteStartElement("x"); sileFile.WriteAttributeString("caller", caller); } break; case "ide": case "fm": // Should not actually be in any field texts. Safe to skip. case "idx": // Peripherals - Back Matter Index SkipElement(); break; case "ie": // Introduction end SkipElement(); break; case "id": if (id != currentBookAbbrev) { Logit.WriteError("Book ID in <id> and <book> do not match: " + currentBookAbbrev + " is not " + id); } SkipElement(); // Strip out comment portion. break; case "toc": // Table of Contents entries if (String.IsNullOrEmpty(level) || (level == "1")) { inToc1 = true; } else if (level == "2") { inToc2 = true; } else if (level == "3") { inToc3 = true; } else { SkipElement(); } break; case "rem": // Comment; not part of the actual text SkipElement(); break; case "h": currentBookHeader = ReadElementText().Trim(); break; case "c": currentChapter = id; currentChapterPublished = fileHelper.LocalizeDigits(currentChapter); currentChapterAlternate = String.Empty; currentVerse = currentVersePublished = currentVerseAlternate = String.Empty; currentChapterPublished = chapterLabel + fileHelper.LocalizeDigits(ReadElementText().Trim()); chapterWritten = false; break; case "cl": if (currentChapter == String.Empty) { chapterLabel = ReadElementText().Trim() + " "; } else { currentChapterPublished = ReadElementText().Trim(); } break; case "cp": if (!usfx.IsEmptyElement) { currentChapterPublished = ReadElementText().Trim(); } break; case "v": PrintChapter(); currentVersePublished = fileHelper.LocalizeDigits(id); currentVerse = id.Replace("\u200F", ""); // Strip out RTL character currentVerseAlternate = ""; if (!usfx.IsEmptyElement) { usfx.Read(); if (usfx.NodeType == XmlNodeType.Text) { currentVersePublished = fileHelper.LocalizeDigits(usfx.Value.Trim()); } if (usfx.NodeType != XmlNodeType.EndElement) { usfx.Read(); } } break; case "va": // Not supported by The Sword Project SkipElement(); break; case "vp": SkipElement(); /* This feature is not supported by The Sword Project. * if (!usfx.IsEmptyElement) * { * usfx.Read(); * if (usfx.NodeType == XmlNodeType.Text) * { * currentVersePublished = usfx.Value.Trim(); * if (currentVersePublished.Length > 0) * { * vpeID = StartId(); * StartMosisElement("verse"); * mosis.WriteAttributeString("osisID", osisVerseId); * mosis.WriteAttributeString("sID", verseeID); * mosis.WriteAttributeString("n", currentVersePublished); * WriteMosisEndElement(); // verse * } * } * } */ break; case "periph": SkipElement(); break; case "cs": // Rare or new character style: don't know what it should be, so throw away tag & keep text. break; case "gw": // Do nothing. Not sure what to do with glossary words, yet. case "xt": // Do nothing. case "ft": // Ignore. It does nothing useful, but is an artifact of USFM exclusive character styles. break; case "usfx": // Nothing to do, here. break; case "dc": case "xdc": case "fdc": if (!globe.projectOptions.includeApocrypha) { SkipElement(); } break; default: sileFile.WriteStartElement(usfx.Name); if (id != null) { sileFile.WriteAttributeString("id", id); } if (caller != null) { sileFile.WriteAttributeString("caller", caller); } if (level != null) { sileFile.WriteAttributeString("level", level); } if (sfm != null) { sileFile.WriteAttributeString("sfm", sfm); } if (style != null) { sileFile.WriteAttributeString("style", style); } if (usfx.IsEmptyElement) { sileFile.WriteEndElement(); } break; } } else if (usfx.NodeType == XmlNodeType.EndElement) { if (inToc1 || inToc2) { if (usfx.Name == "toc") { inToc2 = inToc1 = false; } else if (inToc1 && usfx.Name == "it") { toc1 += "</hi></seg>"; } else { Logit.WriteLine("Warning: " + usfx.Name + " end markup in title at " + currentBookAbbrev + " not written to OSIS file"); } } else { switch (usfx.Name) { case "w": case "zw": if (inStrongs) { WriteMosisEndElement(); inStrongs = false; } break; case "wj": WriteMosisEndElement(); // q break; case "book": EndLineGroup(); EndCurrentVerse(); EndCurrentChapter(); EndIntroduction(); EndMajorSection(); WriteMosisEndElement(); // div type="book" CheckElementLevel(3, "closed book"); break; case "bdit": WriteMosisEndElement(); // hi italic WriteMosisEndElement(); // hi bold break; case "p": if (itemLevel > 0) { itemLevel--; } CheckMinimumLevel(5, "Ending " + usfx.Name + " " + osisVerseId); inNote = false; if (eatPoetryLineEnd) { eatPoetryLineEnd = false; } else { WriteMosisEndElement(); } break; case "q": if (eatPoetryLineEnd) { eatPoetryLineEnd = false; } else { WriteMosisEndElement(); } break; case "ref": if (inReference) { WriteMosisEndElement(); // reference inReference = false; } break; case "fe": case "f": case "x": if (inNote) { inNote = false; WriteMosisEndElement(); // End of note } break; case "add": if (!inNote) { WriteMosisEndElement(); } break; case "qs": if (inLineGroup) { WriteMosisEndElement(); inPoetryLine = false; } break; case "bd": case "bk": case "cl": case "d": case "dc": case "em": case "fk": case "fp": case "fq": case "fqa": case "fr": case "fv": case "k": case "no": case "pn": case "qac": case "qt": case "r": case "rq": case "s": case "sc": case "sig": case "sls": case "table": case "tc": case "tcr": case "th": case "thr": case "tl": case "tr": case "xo": case "ord": // case "xq": Not useful for Sword modules. WriteMosisEndElement(); // note, hi, reference, title, l, transChange, etc. break; case "it": if (!inStrongs) { WriteMosisEndElement(); } break; case "nd": WriteMosisEndElement(); // divineName WriteMosisEndElement(); // seg break; case "xk": case "fl": case "zcr": case "zcb": case "zcg": case "zcy": // not supported. break; /* Can't get to this case (caught in "if" above) * case "toc": * inToc2 = inToc1 = false; * break;*/ } } } else if (((usfx.NodeType == XmlNodeType.Text) || (usfx.NodeType == XmlNodeType.SignificantWhitespace) || (usfx.NodeType == XmlNodeType.Whitespace)) && !ignore) { if (inToc1) { toc1 = toc1 + usfx.Value; } else if (inToc2) { toc2 = toc2 + usfx.Value; } else { mosis.WriteString(usfx.Value); } } } return(result); }
public void PreprocessUsfmFiles(string SourceDir) { // First, copy BookNames.xml for ready reference. We will update it later. string bookNamesCopy = Path.Combine(outputProjectDirectory, "BookNames.xml"); string bookNamesSource = Path.Combine(SourceDir, "BookNames.xml"); if (File.Exists(bookNamesCopy)) { File.Delete(bookNamesCopy); } if (File.Exists(bookNamesSource)) { File.Copy(bookNamesSource, bookNamesCopy, true); } // Now, get on with preprocessing the USFM files. Logit.GUIWriteString = GUIWriteString; Logit.OpenFile(Path.Combine(outputProjectDirectory, "preprocesslog.txt")); // string SourceDir = Path.Combine(globe.inputProjectDirectory, "Source"); /* * StreamReader sr = new StreamReader(orderFile); * string allowedBookList = sr.ReadToEnd(); * sr.Close(); */ string bookId; string UsfmDir = Path.Combine(outputProjectDirectory, "extendedusfm"); if (!Directory.Exists(SourceDir)) { WriteLine("ERROR: " + SourceDir + " not found!"); return; } // Start with an EMPTY USFM directory to avoid problems with old files Utils.DeleteDirectory(UsfmDir); fileHelper.EnsureDirectory(UsfmDir); string[] inputFileNames = Directory.GetFiles(SourceDir); if (inputFileNames.Length == 0) { WriteLine("ERROR: No files found in " + SourceDir); return; } foreach (string inputFile in inputFileNames) { string filename = Path.GetFileName(inputFile); string lowerName = filename.ToLower(); string fileType = Path.GetExtension(filename).ToUpper(); if ((fileType != ".BAK") && (fileType != ".LDS") && (fileType != ".SSF") && (fileType != ".DBG") && (fileType != ".WDL") && (fileType != ".STY") && (fileType != ".XML") && (fileType != ".HTM") && (fileType != ".KB2") && (fileType != ".HTML") && (fileType != ".CSS") && (fileType != ".SWP") && (fileType != ".ID") && (fileType != ".DIC") && (fileType != ".LDML") && (fileType != ".JSON") && (fileType != ".VRS") && (fileType != ".INI") && (fileType != ".CSV") && (fileType != ".TSV") && (fileType != ".CCT") && (!inputFile.EndsWith("~")) && (lowerName != "autocorrect.txt") && (lowerName != "tmp.txt") && (lowerName != "changes.txt") && (lowerName != "hyphenatedWords.txt") && (lowerName != "wordboundariesoutput.txt") && (lowerName != "printdraftchanges.txt")) { ShowStatus("preprocessing " + filename); Application.DoEvents(); if (!fileHelper.fAllRunning) { break; } string outputFileName = MakeUpUsfmFileName(inputFile, out bookId) + ".usfm"; if (outputFileName.Length < 8) { if (fileType != ".TXT") { Logit.WriteLine("No proper \\id line found in " + inputFile); } } else { if (projectOptions.allowedBookList.Contains(bookId)) { string outputFilePath = Path.Combine(UsfmDir, outputFileName); PreprocessOneFile(inputFile, projectOptions.preprocessingTables, outputFilePath); } /* * else * { * Logit.WriteLine("Skipping book " + bookId + " (not in " + orderFile + ")"); * } */ } } } }
/// <summary> /// Read an imp or OSIS file and convert at least the main canonical text to USFX. /// </summary> /// <param name="infile">input imp or OSIS file name</param> /// <param name="outfile">output USFX file name</param> public void readImpOsis(string infile, string outfile) { string line; string inname = infile; string bookAbbr = String.Empty; string bcv = String.Empty; string bk; int currentChapter = 0; int currentVerse = 0; int c = 0; int v = 0; string id = String.Empty; string type = String.Empty; string osisID = String.Empty; string sID = String.Empty; string eID = String.Empty; string lemma = String.Empty; string morph = String.Empty; string added = String.Empty; string marker = String.Empty; string subType = String.Empty; string src = String.Empty; string savlm = String.Empty; string n = String.Empty; string who = String.Empty; StreamReader sr; try { sr = new StreamReader(infile, Encoding.UTF8); line = sr.ReadLine().TrimStart(); sr.Close(); if (line.StartsWith("$$$")) { inname = outfile + ".tMpXmL"; Logit.WriteLine("Converting imp file " + infile + " to imp xml file " + inname); ImpOsis2Xml(infile, inname); } else if (!line.StartsWith("<?xml version=\"1.0\"")) { Logit.WriteError("I don't know what to do with this file: " + infile); return; } xr = new XmlTextReader(inname); holyBooks.OpenUsfx(outfile); Logit.WriteLine("Converting from " + inname + " to USFX file " + outfile); while (xr.Read()) { if ((delayedVerse > 0) && (xr.Name != "milestone")) { if (!inParagraph) { StartNewParagraph("p"); } if (delayedVerse > 0) { WriteEmptyElementWithAttributes("v", "id", delayedVerse.ToString()); delayedVerse = 0; } RestartWJ(); delayedVerse = 0; } if (xr.NodeType == XmlNodeType.Element) { id = GetNamedAttribute("id"); type = GetNamedAttribute("type"); osisID = GetNamedAttribute("osisID"); sID = GetNamedAttribute("sID"); eID = GetNamedAttribute("eID"); lemma = GetNamedAttribute("lemma"); morph = GetNamedAttribute("morph"); added = GetNamedAttribute("added"); marker = GetNamedAttribute("marker"); who = GetNamedAttribute("who"); subType = GetNamedAttribute("subType"); src = GetNamedAttribute("src"); savlm = GetNamedAttribute("savlm"); n = GetNamedAttribute("n"); sfm = GetNamedAttribute("sfm"); switch (xr.Name) { case "header": SkipElement(); break; case "impxml": Logit.WriteLine("Parsing " + inname + " as imp xml."); break; case "osis": Logit.WriteLine("Parsing " + inname + " as OSIS"); break; case "book": StartBook(id); break; case "chapter": bcv = ParseOsisId(osisID, out bk, out c, out v); EndParagraph(); WriteEmptyElementWithAttributes("c", "id", c.ToString()); currentChapter = c; break; case "v": WriteEmptyElementWithAttributes("v", "id", id); break; case "p": StartNewParagraph("p", sfm); break; case "verse": if (eID.Length > 0) { SuspendWJ(); WriteEmptyElementWithAttributes("ve"); } else { bcv = ParseOsisId(osisID, out bk, out c, out v); if (c != currentChapter) { EndParagraph(); WriteEmptyElementWithAttributes("c", "id", c.ToString()); currentChapter = c; } delayedVerse = v; currentVerse = v; } break; case "transChange": holyBooks.xw.WriteStartElement("add"); break; case "div": switch (type) { case "book": bcv = ParseOsisId(osisID, out bk, out c, out v); StartBook(bk); break; case "colophon": StartNewParagraph("p", "ie"); break; } break; case "milestone": if ((type == "x-extra-p") || (type == "x-p")) { SuspendWJ(); StartNewParagraph("p"); if (marker.Length > 0) { holyBooks.xw.WriteString(marker + " "); } } break; case "w": lemma = (lemma + " " + savlm).Trim(); morph = (morph + " " + src).Trim(); wHasContent = (!xr.IsEmptyElement) && ((lemma.Length + morph.Length) > 0); if (wHasContent) { holyBooks.xw.WriteStartElement("w"); if (lemma.Length > 0) { holyBooks.xw.WriteAttributeString("s", lemma.Replace("strong:", "")); } if (morph.Length > 0) { holyBooks.xw.WriteAttributeString("m", morph.Trim()); } if (xr.IsEmptyElement) { holyBooks.xw.WriteEndElement(); } } else { // Otherwise, don't bother with the tag, because we really don't know semantically what it means. Logit.WriteLine("Warning: empty <w> element ignored at " + bcv); } break; case "title": switch (type) { case "main": StartNewParagraph("mt"); break; case "psalm": StartNewParagraph("d"); break; case "acrostic": StartNewParagraph("s"); break; case "chapter": if (!inParagraph) { StartNewParagraph("p"); } SkipElement(); break; } break; case "note": // type="study" if (type == "study") { holyBooks.xw.WriteStartElement("f"); holyBooks.xw.WriteAttributeString("caller", "+"); } else { SkipElement(); } break; case "divineName": holyBooks.xw.WriteStartElement("nd"); break; case "foreign": holyBooks.xw.WriteStartElement("tl"); if (n.Length > 0) { holyBooks.xw.WriteString(" " + n + " "); } break; case "ip": holyBooks.xw.WriteStartElement("p"); holyBooks.xw.WriteAttributeString("sfm", "ip"); break; case "q": if (marker != String.Empty) { Console.WriteLine("Unsupported marker in <q> at {0}: \"{1}\"", bcv, marker); } if (who == "Jesus") { StartWJ(); } break; } } else if (xr.NodeType == XmlNodeType.EndElement) { switch (xr.Name) { case "w": if (wHasContent) { holyBooks.xw.WriteEndElement(); } break; case "book": EndBook(); currentChapter = 0; break; case "divineName": case "transChange": case "foreign": case "note": case "ip": holyBooks.xw.WriteEndElement(); break; case "verse": // <ve /> SuspendWJ(); WriteEmptyElementWithAttributes("ve"); break; case "q": EndWJ(); break; case "title": EndParagraph(); break; case "p": EndParagraph(); break; } } else if (xr.NodeType == XmlNodeType.Text) { holyBooks.xw.WriteString(xr.Value); } else if (xr.NodeType == XmlNodeType.Whitespace) { holyBooks.xw.WriteWhitespace(xr.Value); } } holyBooks.CloseUsfx(); xr.Close(); } catch (Exception ex) { Logit.WriteError("Error at " + bcv); Logit.WriteError(ex.Message); Logit.WriteError(ex.StackTrace); } }
static void Main(string[] args) { int i; bool showBanner = false; string logName = "WordSendLog.txt"; string inName = ""; string outName = ".sfm"; // string jobOptionsName = Environment.GetEnvironmentVariable("APPDATA")+ // "\\SIL\\WordSend\\joboptions.xml"; Logit.useConsole = true; for (i = 0; i < args.Length; i++) { // Scan the command line string s = args[i]; if ((s != null) && (s.Length > 0)) { if ((s[0] == '-') && (s.Length > 1)) { // command line switch: take action switch (Char.ToLower(s[1])) { case 'o': // Set output file name outName = SFConverter.GetOption(ref i, args); break; case 'i': // Set input file name inName = SFConverter.GetOption(ref i, args); break; case 'l': // Set log name logName = SFConverter.GetOption(ref i, args); break; case '-': case 'h': case '?': showBanner = true; break; default: Logit.WriteLine("Unrecognized command line switch: " + args[i]); showBanner = true; break; } } else if (inName == "") { inName = args[i]; } } } Logit.OpenFile(logName); Logit.WriteLine("\nWordSend project usfx2usfm compiled " + Version.date); if (inName == "") { showBanner = true; } else { Logit.WriteLine("Input file name is " + inName + "; output suffx is " + outName); // Something to refactor: make this line not required. // SFConverter.jobIni = new XMLini(jobOptionsName); // Here we instantiate the object that does most of the work. SFConverter.scripture = new Scriptures(); // Write out the USFM file SFConverter.scripture.USFXtoUSFM(inName, Path.GetDirectoryName(outName), Path.GetFileName(outName)); } if (showBanner) { Logit.WriteLine(""); Logit.WriteLine(Version.copyright); Logit.WriteLine(""); Logit.WriteLine(Version.contact); Logit.WriteLine(@" Syntax: usfx2usfm [-o Output] [-?] [-l logname] [-i] inputfile Output = output USFM path and file name suffix default is .sfm book code will be added, i. e. pdg.sfm -> MATpdg.sfm and subdir\eng.sfm -> subdir\MATeng.sfm logname is name of log file to write, default is WordSendLog.txt -h or -? = show this information. inputfile = name of USFX file to convert to USFM File names with embedded spaces must be surrounded by quotes. Do not use - as the first character of a path or file name. "); Logit.CloseFile(); } }
static void Main(string[] args) { int i; bool showBanner = false; string logName = "usfx2mosislog.txt"; string inName = "usfx.xml"; string outName = "mosis.xml"; string ethnologueCode = String.Empty; string translationId = String.Empty; Logit.useConsole = true; for (i = 0; i < args.Length; i++) { // Scan the command line string s = args[i]; if ((s != null) && (s.Length > 0)) { if ((s[0] == '-') && (s.Length > 1)) { // command line switch: take action switch (Char.ToLower(s[1])) { case 'o': // Set output file name outName = SFConverter.GetOption(ref i, args); break; case 'i': // Set input file name inName = SFConverter.GetOption(ref i, args); break; case 'l': // Set log name logName = SFConverter.GetOption(ref i, args); break; case 't': translationId = SFConverter.GetOption(ref i, args); break; case '-': case 'h': case '?': case '/': showBanner = true; break; default: Logit.WriteLine("Unrecognized command line switch: " + args[i]); showBanner = true; break; } } else if (inName == "") { inName = args[i]; } } } Logit.OpenFile(logName); if (showBanner) { Logit.WriteLine(""); Logit.WriteLine("This is part of Haiola open source software."); Logit.WriteLine("Please see http://haiola.org for copyright information."); Logit.WriteLine(@" Syntax: usfx2usfm [-t translationId] [-o Output] [-?] [-l logname] [-i] [inputfile] translationId = unique translation identifier default is Ethnologue language code specified in usfx file Output = output USFM path and file name suffix default is mosis.xml logname is name of log file to write, default is usfx2mosislog.txt -h or -? = show this information. inputfile = name of USFX file to convert to USFM default is usfx.xml File names with embedded spaces must be surrounded by quotes. Do not use - as the first character of a path or file name. "); } else { Logit.WriteLine(DateTime.Now.ToString()); Logit.WriteLine("Input USFX: " + inName + "; output MOSIS: " + outName); usfxToMosisConverter toMosis = new usfxToMosisConverter(); toMosis.translationId = translationId; toMosis.revisionDateTime = DateTime.Now; toMosis.languageCode = String.Empty; toMosis.vernacularTitle = toMosis.contentCreator = toMosis.contentContributor = String.Empty; toMosis.englishDescription = toMosis.lwcDescription = toMosis.printPublisher = String.Empty; toMosis.ePublisher = toMosis.languageName = toMosis.dialect = String.Empty; toMosis.vernacularLanguageName = toMosis.copyrightNotice = String.Empty; toMosis.rightsNotice = String.Empty; toMosis.langCodes = new LanguageCodeInfo(); toMosis.ConvertUsfxToMosis(inName, outName); } Logit.CloseFile(); }
static void Main(string[] args) { bool showBanner = true; bool showHelp = false; string logName = "WordSendLog.txt"; string inName = ""; string outName = ""; int i; string jobOptionsName = Environment.GetEnvironmentVariable("APPDATA") + "\\SIL\\WordSend\\joboptions.xml"; SFConverter.jobIni = new XMLini(jobOptionsName); Logit.useConsole = true; for (i = 0; i < args.Length; i++) { // Scan the command line string s = args[i]; if ((s != null) && (s.Length > 0)) { if (((s[0] == '-') || (s[0] == '/')) && (s.Length > 1)) { // command line switch: take action switch (Char.ToLower(s[1])) { case 'n': // No banner display showBanner = false; break; case 'o': // Set output file name outName = SFConverter.GetOption(ref i, args); break; case 'i': // Set input file name inName = SFConverter.GetOption(ref i, args); break; case 'l': // Set log name logName = SFConverter.GetOption(ref i, args); break; case '?': case 'h': case '-': showBanner = true; showHelp = true; break; default: Logit.WriteLine("Unrecognized command line switch: " + args[i]); break; } } else { if (inName == "") { inName = s; } else { if (outName == "") { outName = s; } else { showBanner = true; showHelp = true; } } } } } SFConverter.scripture = new Scriptures(); Logit.OpenFile(logName); if (showBanner) { Logit.WriteLine("\nWordSend project extract_usfx compiled " + Version.date); Logit.WriteLine(""); Logit.WriteLine(Version.copyright); Logit.WriteLine(""); Logit.WriteLine(Version.contact); } if ((outName.Length < 1) || (inName.Length < 1)) { showHelp = true; } if (showHelp) { Logit.WriteLine(@" Syntax: sf2word [-l logname] [-h] [-n] [-i] inputfile [-o] outputfile logname = log file name (default is WordSendLog.txt) -h = show this information then exit -n = supress banner inputfile = Microsoft Word XML file that has embedded USFX outputfile = name of USFX file to write "); Logit.CloseFile(); return; } Logit.WriteLine("Auxilliary files read."); SFConverter.scripture.ExtractUSFX(inName, outName); Logit.WriteLine("Done."); Logit.CloseFile(); }
static void Main(string[] args) { int i; bool showBanner = true; string outName = ""; string logName = "WordSendLog.txt"; string jobOptionsName = Environment.GetEnvironmentVariable("APPDATA") + "\\SIL\\WordSend\\joboptions.xml"; string templateName = ""; ArrayList fileSpecs = new ArrayList(127); Logit.useConsole = true; for (i = 0; i < args.Length; i++) { // Scan the command line string s = args[i]; if ((s != null) && (s.Length > 0)) { if (((s[0] == '-') || (s[0] == '/')) && (s.Length > 1)) { // command line switch: take action switch (Char.ToLower(s[1])) { case 'j': // Job options file name jobOptionsName = SFConverter.GetOption(ref i, args); break; case 'n': // No banner display showBanner = false; break; case 'o': // Set output file name outName = SFConverter.GetOption(ref i, args); break; case 't': // Set template file name templateName = SFConverter.GetOption(ref i, args); break; case 'l': // Set log name logName = SFConverter.GetOption(ref i, args); break; case '?': case 'h': case '-': showBanner = true; break; default: Logit.WriteLine("Unrecognized command line switch: " + args[i]); break; } } else { fileSpecs.Add(args[i]); } } } Logit.OpenFile(logName); Logit.WriteLine("\nWordSend project sf2word compiled " + Version.date); if (showBanner) { Logit.WriteLine(""); Logit.WriteLine(Version.copyright); Logit.WriteLine(""); Logit.WriteLine(Version.contact); Logit.WriteLine(@" Syntax: sf2word [-o Output] [-j Job] [-t Template] [-n] [-?] [-l logname] filespec(s) Output = output WordML file name Job = name of XML job options file created with usfm2word.exe. Template = example WordML document with the required style definitions -n = don't display copyright and banner information. -? = cancel previous /n and show this information. -l = set log file name (default is WordSendLog.txt in the current directory) filespec = SFM file specification to read If a JobOptions file is specified, and that file contains the input file specifications, then filespec(s) need not be specified on the command line. If filespec(s) or output files are specified on the command line, then the command line overrides those specifications in the job options file. You may use / instead of - to introduce switches. Do not use / or - as the first character of a file name. "); } // Read XML job options file. Note that this file is only read // from in the command line program, but may be // written to from the Windows UI version. It is reasonable to // set up the options the way you want them in the Windows UI // version of the program, then read them with this command line // version. We convert some command line arguments to entries // in this class for consistency in the handling of options // between the command line and Windows UI versions. SFConverter.jobIni = new XMLini(jobOptionsName); SFConverter.jobIni.WriteString("TemplateName", templateName); if (outName == "") { outName = SFConverter.jobIni.ReadString("outputFileName", "Output.xml"); } if (templateName != "") { SFConverter.jobIni.WriteString("templateName", templateName); } if (fileSpecs.Count < 1) { int numSfmFiles = SFConverter.jobIni.ReadInt("numSfmFiles", 0); for (i = 0; i < numSfmFiles; i++) { fileSpecs.Add( (object)SFConverter.jobIni.ReadString("sfmFile" + i.ToString(), "*.sfm")); } } if (fileSpecs.Count < 1) { Logit.WriteLine("Nothing to do. No input files specified."); } else { // We don't really have a need for application options in the // command line program, but if we did, they would go in the // following place: // SFConverter.appIni = new XMLini(Environment.GetEnvironmentVariable("APPDATA")+"\\SIL\\WordSend\\sf2word.xml"); // Here we instantiate the object that does most of the work. SFConverter.scripture = new Scriptures(); Logit.WriteLine("Job options: " + jobOptionsName); Logit.WriteLine("Output file: " + outName); // Read the input USFM files into internal data structures. for (i = 0; i < fileSpecs.Count; i++) { SFConverter.ProcessFilespec((string)fileSpecs[i]); } // Write out the WordML file. SFConverter.scripture.WriteToWordML(outName); } Logit.CloseFile(); }
/// <summary> /// Reads a Paratext .ssf file and imports selected configuration items into our own Options object. /// </summary> /// <param name="projectOptions">Options object to update with data in the Paratext .ssf file.</param> /// <param name="ssfFileName">Full path to the Paratext .ssf file to update.</param> public void ReadParatextSsf(Options projectOptions, string ssfFileName) { string elementName, setting; try { if (!File.Exists(ssfFileName)) { return; } XmlTextReader ssf = new XmlTextReader(ssfFileName); ssf.WhitespaceHandling = WhitespaceHandling.Significant; ssf.MoveToContent(); while (ssf.Read()) { if ((ssf.NodeType == XmlNodeType.Element) && (ssf.Name != "ScriptureText")) { if (!ssf.IsEmptyElement) { elementName = ssf.Name; ssf.Read(); // Get content of element if ((ssf.NodeType == XmlNodeType.Text) && (!String.IsNullOrEmpty(ssf.Value))) { setting = ssf.Value; switch (elementName) { case "Encoding": if (setting != "65001") { Logit.WriteLine("Warning: Paratext encoding is not Unicode UTF-8 (" + setting + ") in " + ssfFileName); } break; case "EthnologueCode": if (projectOptions.languageId.Length < 3) { projectOptions.languageId = setting; } break; case "RangeIndicator": // verse range separator projectOptions.rangeSeparator = setting; break; case "SequenceIndicator": projectOptions.multiRefSameChapterSeparator = setting; break; case "ChapterVerseSeparator": projectOptions.CVSeparator = setting; break; case "ChapterRangeSeparator": projectOptions.multiRefDifferentChapterSeparator = setting; break; case "BookSequenceSeparator": projectOptions.BookSequenceSeparator = setting; break; case "ChapterNumberSeparator": projectOptions.ChapterNumberSeparator = setting; break; case "BookSourceForMarkerXt": projectOptions.BookSourceForMarkerXt = setting; break; case "BookSourceForMarkerR": projectOptions.BookSourceForMarkerR = setting; break; case "Guid": projectOptions.paratextGuid = setting; break; } } } } } ssf.Close(); projectOptions.Write(); } catch (Exception ex) { Logit.WriteError("Error reading Paratext options file " + ssfFileName + ": " + ex.Message); Logit.WriteError(ex.StackTrace); } }