Exemple #1
0
        private void PreprocessOneFile(string inputPath, List <string> tablePaths, string outputPath)
        {
            DateTime fileDate;

            fileDate = File.GetLastWriteTimeUtc(inputPath);
            if (fileDate > sourceDate)
            {
                sourceDate = fileDate;
                projectOptions.SourceFileDate = sourceDate;
            }
            string input;
            // Read file into input
            // Instead of asking the user what the character encoding is, we guess that it is either
            // Windows 1252 or UTF-8, and choose which one of those based on the assumed presence of
            // surrogates in UTF-8, unless there is a byte-order mark.
            Encoding enc = fileHelper.IdentifyFileCharset(inputPath);
            // MessageBox.Show(inputPath + " is encoded as " + enc.ToString());
            StreamReader reader = new StreamReader(inputPath, enc /* Encoding.GetEncoding(globe.globe.projectOptions.InputEncoding) */);

            input = reader.ReadToEnd() + "\0";
            reader.Close();

            // Copy input into buffer
            byte[] inputBytes = Encoding.UTF8.GetBytes(input); // replaced by previous output for subsequent iterations.
            int    cbyteInput = inputBytes.Length;             // replaced by output length for subsequent iterations

            byte[] outBuffer = inputBytes;                     // in case 0 iterations
            int    nOutLen   = inputBytes.Length;

            foreach (string tp in tablePaths)
            {
                if (tp.EndsWith(".process"))
                {
                    // This will become a switch if we get more processes
                    if (tp == kFootnotesProcess)
                    {
                        FixMultipleFootnotes(ref inputBytes, ref cbyteInput);
                        outBuffer = inputBytes; // in case last pass
                        nOutLen   = cbyteInput; // in case last pass.
                    }
                    else
                    {
                        WriteLine("ERROR: Process " + tp + " not known.");
                        return;
                    }
                    continue;
                }
                string tablePath = Path.Combine(inputProjectDirectory, tp);
                if (!File.Exists(tablePath))
                {
                    tablePath = Path.Combine(inputDirectory, tp);
                }
                if (!File.Exists(tablePath))
                {
                    tablePath = SFConverter.FindAuxFile(tp);
                }
                if (File.Exists(tablePath))
                {
                    if (tablePath.EndsWith(".re"))
                    {
                        // Apply a regular expression substitution
                        string       temp        = Encoding.UTF8.GetString(inputBytes, 0, cbyteInput - 1); // leave out final null
                        StreamReader tableReader = new StreamReader(tablePath, Encoding.UTF8);
                        fileDate = File.GetLastWriteTimeUtc(tablePath);
                        if (fileDate > sourceDate)
                        {
                            sourceDate = fileDate;
                            projectOptions.SourceFileDate = sourceDate;
                        }
                        while (!tableReader.EndOfStream)
                        {
                            string source = tableReader.ReadLine();
                            if (source.Trim().Length == 0)
                            {
                                continue;
                            }

                            char delim = source[0];
                            if (delim == ':')
                            {
                                temp = DoRangeReplacement(source, temp);
                            }
                            else
                            {
                                string[] parts       = source.Split(new char[] { delim });
                                string   pattern     = parts[1];               // parts[0] is the empty string before the first delimiter
                                string   replacement = parts[2];
                                replacement = replacement.Replace("$r", "\r"); // Allow $r in replacement to become a true cr
                                replacement = replacement.Replace("$n", "\n"); // Allow (literal) $n in replacement to become a true newline
                                temp        = System.Text.RegularExpressions.Regex.Replace(temp, pattern, replacement);
                            }
                        }
                        tableReader.Close();
                        temp       = temp + "\0";
                        outBuffer  = Encoding.UTF8.GetBytes(temp);
                        inputBytes = outBuffer;
                        cbyteInput = nOutLen = inputBytes.Length;
                    }
                }
                else
                {
                    MessageBox.Show("Can't find preprocessing file " + tp, "Error in preprocessing file list");
                }
            }

            // Convert the output back to a file
            Directory.CreateDirectory(Path.GetDirectoryName(outputPath)); // make sure it exists.
            StreamWriter output = new StreamWriter(outputPath, false, Encoding.UTF8);

            // Make sure no trailing nulls get written to file.
            while (nOutLen > 0 && outBuffer[nOutLen - 1] == 0)
            {
                nOutLen--;
            }
            string outputString = Encoding.UTF8.GetString(outBuffer, 0, nOutLen);

            output.Write(outputString);
            output.Close();

            // Eradicate depricated PUA characters
            fileHelper.revisePua(outputPath);
        }
Exemple #2
0
        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);
            }
        }
Exemple #3
0
        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();
            }
        }
Exemple #4
0
        public void WriteTheModule()
        {
            string about;   // licenseHtml or contents of about.inc in input project directory

            if (String.IsNullOrEmpty(globe.projectOptions.fcbhId))
            {
                return;
            }
            int i;

            if ((globe.projectOptions.languageId.Length < 3) ||
                (globe.projectOptions.translationId.Length < 3))
            {
                return;
            }
            string UsfxPath         = Path.Combine(globe.outputProjectDirectory, "usfx");
            string browserBiblePath = Path.Combine(globe.outputProjectDirectory, "browserBible");
            string browserBibleCssFileName;

            // Using latin.css for ALL projects marked as having a Latin script, regardless of exclusive use of common characters or not per Ken Bitgood 20 April 2016.
            // Reversed 15 Dec 2018 due to problems with NASB display.
            if (globe.projectOptions.commonChars)
            {
                browserBibleCssFileName = "latin.css";
            }
            else
            {
                browserBibleCssFileName = globe.projectOptions.customCssFileName;
            }
            Utils.EnsureDirectory(browserBiblePath);
            if (String.IsNullOrEmpty(globe.projectOptions.fcbhId))
            {
                MessageBox.Show("Missing FCBHID for " + globe.projectOptions.translationId);
                globe.projectOptions.fcbhId = globe.projectOptions.translationId;
            }



            if (!Directory.Exists(UsfxPath))
            {
                MessageBox.Show(UsfxPath + " not found!", "ERROR");
                return;
            }
            if (Directory.Exists(browserBiblePath))
            {   // Delete any old files in this directory.
                Utils.DeleteDirectory(browserBiblePath);
            }
            Utils.EnsureDirectory(browserBiblePath);
            string browserBibleCss = Path.Combine(browserBiblePath, browserBibleCssFileName);

            Utils.DeleteFile(browserBibleCss);
            // Always get the browser Bible CSS file from BibleConv/browserBiblecss/ with the same file name as the current custom CSS file name used for simple HTML.
            string browserBiblecssDir = Path.Combine(globe.dataRootDir, "browserBiblecss");
            string specialCss         = Path.Combine(browserBiblecssDir, browserBibleCssFileName);

            if (File.Exists(specialCss))
            {
                File.Copy(specialCss, browserBibleCss);
            }
            string fallbackCss = Path.Combine(browserBiblecssDir, "fallback.css");

            if (File.Exists(fallbackCss))
            {
                File.Copy(fallbackCss, Path.Combine(browserBiblePath, "fallback.css"));
            }
            string aboutFile = Path.Combine(globe.inputProjectDirectory, "about.inc");

            if (File.Exists(aboutFile))
            {
                StreamReader sr = new StreamReader(aboutFile);
                about = globe.expandPercentEscapes(sr.ReadToEnd());
                sr.Close();
            }
            else
            {
                about = globe.copyrightPermissionsStatement();
            }



            string sqlDir = Path.Combine(globe.outputProjectDirectory, "sql");

            Utils.EnsureDirectory(sqlDir);
            usfx2BrowserBible toBrowserBible;

            toBrowserBible = new usfx2BrowserBible();
            toBrowserBible.projectOptions   = globe.projectOptions;
            toBrowserBible.projectOutputDir = globe.outputProjectDirectory;
            toBrowserBible.stripPictures    = true;
            DateTime srcDate = globe.sourceDate;   // Bring local to avoid potential exception in marshall-by-reference class

            toBrowserBible.indexDateStamp = "This module was generated by <a href='http://eBible.org'>eBible.org</a> on " + DateTime.UtcNow.ToString("d MMM yyyy") +
                                            " from source files dated " + srcDate.ToString("d MMM yyyy" + ".");

            if (!String.IsNullOrEmpty(certified))
            {
                StreamReader sr   = new StreamReader("/home/kahunapule/sync/doc/Electronic Scripture Publishing/ebible_certified_sm.b64");
                string       cert = sr.ReadToEnd();
                sr.Close();
                File.Copy(certified, Path.Combine(browserBiblePath, "eBible.org_certified.jpg"));
                toBrowserBible.indexDateStamp = String.Format("{0}<br /><a href='http://eBible.org/certified/' target='_blank'><img src='data:image/png;base64,{1}'>",
                                                              toBrowserBible.indexDateStamp, cert);
            }
            toBrowserBible.CrossRefToFilePrefixMap = globe.projectOptions.CrossRefToFilePrefixMap;
            string usfxFilePath = Path.Combine(UsfxPath, "usfx.xml");
            string orderFile    = Path.Combine(globe.inputProjectDirectory, "bookorder.txt");

            if (!File.Exists(orderFile))
            {
                orderFile = SFConverter.FindAuxFile("bookorder.txt");
            }
            StringBuilder localNumbers = new StringBuilder("\"numbers\":[");

            for (i = 0; i < 150; i++)
            {
                localNumbers.Append("\"" + fileHelper.LocalizeDigits(i.ToString()) + "\",");
            }
            localNumbers.Append("\"" + fileHelper.LocalizeDigits("150") + "\"],");
            toBrowserBible.country     = globe.projectOptions.country;
            toBrowserBible.countryCode = globe.projectOptions.countryCode;
            toBrowserBible.bookInfo.ReadPublicationOrder(orderFile);
            toBrowserBible.MergeXref(Path.Combine(globe.inputProjectDirectory, "xref.xml"));
            toBrowserBible.sourceLink               = globe.expandPercentEscapes("<a href=\"http://%h/%t\">%v</a>");
            toBrowserBible.textDirection            = globe.projectOptions.textDir;
            toBrowserBible.languageNameInEnglish    = globe.projectOptions.languageNameInEnglish;
            toBrowserBible.languageNameInVernacular = globe.projectOptions.languageName;
            toBrowserBible.traditionalAbbreviation  = globe.projectOptions.translationTraditionalAbbreviation;
            toBrowserBible.englishDescription       = globe.projectOptions.EnglishDescription;
            toBrowserBible.customCssName            = browserBibleCssFileName;
            toBrowserBible.numbers     = localNumbers.ToString();
            toBrowserBible.fcbhAudioNt = globe.projectOptions.fcbhAudioNT;
            toBrowserBible.fcbhAudioOt = globe.projectOptions.fcbhAudioOT;
            toBrowserBible.fcbhDramaNt = globe.projectOptions.fcbhDramaNT;
            toBrowserBible.fcbhDramaOt = globe.projectOptions.fcbhDramaOT;
            toBrowserBible.fcbhPortion = globe.projectOptions.fcbhAudioPortion;
            toBrowserBible.coverName   = Path.GetFileName(globe.preferredCover);
            string coverPath = Path.Combine(browserBiblePath, toBrowserBible.coverName);

            File.Copy(globe.preferredCover, coverPath, true);
            string covertnpng = Path.Combine(browserBiblePath, "covertn.png");
            string covertnb64 = Path.Combine(browserBiblePath, "covertn.b64");

            fileHelper.RunCommand(String.Format("shrinkcover {0} {1} {2}", coverPath, covertnpng, covertnb64));
            toBrowserBible.b64CoverName = covertnb64;
            if ((globe.er != null) && (globe.er.countries != null))
            {
                toBrowserBible.countries = globe.er.countries;
            }
            if (globe.projectOptions.commonChars)
            {
                toBrowserBible.preferredFont = "latin";
            }
            else
            {
                toBrowserBible.preferredFont = globe.projectOptions.fontFamily;
            }
            toBrowserBible.shortTitle  = globe.projectOptions.shortTitle;
            toBrowserBible.fcbhId      = globe.projectOptions.fcbhId;
            toBrowserBible.dialectCode = globe.projectOptions.languageId + globe.projectOptions.dialect + globe.projectOptions.script;
            toBrowserBible.script      = globe.projectOptions.script;
            string sqlTranslationId = globe.projectOptions.translationId.Replace("-", "_");

            toBrowserBible.sqlTableName = sqlTranslationId + "_isvl";
            toBrowserBible.sqlFileName  = Path.Combine(Path.Combine(globe.outputProjectDirectory, "sql"), globe.projectOptions.translationId + "_isvl.sql");
            toBrowserBible.langCodes    = globe.languageCodes;
            toBrowserBible.xrefCall.SetMarkers(globe.projectOptions.xrefCallers);
            toBrowserBible.footNoteCall.SetMarkers(globe.projectOptions.footNoteCallers);
            toBrowserBible.redistributable = globe.projectOptions.redistributable;
            toBrowserBible.projectInputDir = globe.inputProjectDirectory;
            toBrowserBible.ConvertUsfxToHtml(usfxFilePath, browserBiblePath,
                                             globe.projectOptions.vernacularTitle,
                                             globe.projectOptions.languageId,
                                             globe.projectOptions.translationId,
                                             globe.projectOptions.chapterLabel,
                                             globe.projectOptions.psalmLabel,
                                             "<a href='copyright.htm'>" + usfxToHtmlConverter.EscapeHtml(globe.shortCopyrightMessage) + "</a>",
                                             globe.expandPercentEscapes(globe.projectOptions.homeLink),
                                             globe.expandPercentEscapes(globe.projectOptions.footerHtml),
                                             globe.expandPercentEscapes(globe.projectOptions.indexHtml),
                                             about,
                                             globe.projectOptions.ignoreExtras,
                                             globe.projectOptions.goText);
            ci = new CreateIndex();
            ci.MakeJsonIndex(Path.Combine(Path.Combine(globe.outputProjectDirectory, "search"), "verseText.xml"), Path.Combine(browserBiblePath, "index"),
                             Path.Combine(sqlDir, sqlTranslationId + "_conc.sql"));
            ci.MakeLemmaIndex(Path.Combine(Path.Combine(globe.outputProjectDirectory, "search"), "verseText.lemma"), Path.Combine(browserBiblePath, "indexlemma"));
            string fontsDir = Path.Combine(browserBiblePath, "fonts");

            fileHelper.EnsureDirectory(fontsDir);
            string fontSource = Path.Combine(globe.dataRootDir, "fonts");
            string fontName   = globe.projectOptions.fontFamily.ToLower().Replace(' ', '_');

            fileHelper.CopyFile(Path.Combine(fontSource, fontName + ".ttf"), Path.Combine(fontsDir, fontName + ".ttf"));
            fileHelper.CopyFile(Path.Combine(fontSource, fontName + ".woff"), Path.Combine(fontsDir, fontName + ".woff"));
            fileHelper.CopyFile(Path.Combine(fontSource, fontName + ".eot"), Path.Combine(fontsDir, fontName + ".eot"));
            Utils.DeleteFile(covertnpng);
            Utils.DeleteFile(covertnb64);
            Logit.CloseFile();
            if (Logit.loggedError)
            {
                globe.projectOptions.lastRunResult = false;
            }
            if (Logit.loggedWarning)
            {
                globe.projectOptions.warningsFound = true;
            }
        }
Exemple #5
0
        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();
        }
Exemple #6
0
        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();
        }
Exemple #7
0
        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();
        }