]> git.lyx.org Git - lyx.git/blobdiff - src/tex2lyx/tex2lyx.cpp
Skip missing optional argument insets in tex2lyx
[lyx.git] / src / tex2lyx / tex2lyx.cpp
index 8772d6bea735e3630ab04782ebfd6f435b28b68b..2ef209fc42305fc03731aa0a84da5197c6637535 100644 (file)
@@ -205,7 +205,7 @@ typedef map<string, DocumentClassPtr> ModuleMap;
 ModuleMap modules;
 
 
-bool addModule(string const module, LayoutFile const & baseClass, LayoutModuleList & m, vector<string> & visited)
+bool addModule(string const module, LayoutFile const & baseClass, LayoutModuleList & m, vector<string> & visited)
 {
        // avoid endless loop for circular dependency
        vector<string>::const_iterator const vb = visited.begin();
@@ -494,7 +494,7 @@ void read_syntaxfile(FileName const & file_name)
        // modeled after TeX.
        // Unknown tokens are just silently ignored, this helps us to skip some
        // reLyX specific things.
-       Parser p(is);
+       Parser p(is, string());
        while (p.good()) {
                Token const & t = p.get_token();
                if (t.cat() == catEscape) {
@@ -519,6 +519,7 @@ void read_syntaxfile(FileName const & file_name)
 
 string documentclass;
 string default_encoding;
+bool fixed_encoding = false;
 string syntaxfile;
 bool copy_files = false;
 bool overwrite_files = false;
@@ -531,12 +532,13 @@ typedef int (*cmd_helper)(string const &, string const &);
 
 int parse_help(string const &, string const &)
 {
-       cerr << "Usage: tex2lyx [options] infile.tex [outfile.lyx]\n"
+       cout << "Usage: tex2lyx [options] infile.tex [outfile.lyx]\n"
                "Options:\n"
                "\t-c textclass       Declare the textclass.\n"
                "\t-m mod1[,mod2...]  Load the given modules.\n"
                "\t-copyfiles         Copy all included files to the directory of outfile.lyx.\n"
                "\t-e encoding        Set the default encoding (latex name).\n"
+               "\t-fixedenc encoding Like -e, but ignore encoding changing commands while parsing.\n"
                "\t-f                 Force overwrite of .lyx files.\n"
                "\t-help              Print this message and quit.\n"
                "\t-n                 translate literate programming (noweb, sweave,... ) file.\n"
@@ -561,11 +563,12 @@ int parse_help(string const &, string const &)
 
 int parse_version(string const &, string const &)
 {
-       lyxerr << "tex2lyx " << lyx_version
-              << " (" << lyx_release_date << ")" << endl;
-       lyxerr << "Built on " << __DATE__ << ", " << __TIME__ << endl;
+       cout << "tex2lyx " << lyx_version
+            << " (" << lyx_release_date << ")" << endl;
+       cout << "Built on " << lyx_build_date << ", " << lyx_build_time
+            << endl;
 
-       lyxerr << lyx_version_info << endl;
+       cout << lyx_version_info << endl;
        exit(error_code);
 }
 
@@ -605,6 +608,16 @@ int parse_encoding(string const & arg, string const &)
 }
 
 
+int parse_fixed_encoding(string const & arg, string const &)
+{
+       if (arg.empty())
+               error_message("Missing encoding string after -fixedenc switch");
+       default_encoding = arg;
+       fixed_encoding = true;
+       return 1;
+}
+
+
 int parse_syntaxfile(string const & arg, string const &)
 {
        if (arg.empty())
@@ -686,6 +699,7 @@ void easyParse(int & argc, char * argv[])
        cmdmap["-c"] = parse_class;
        cmdmap["-m"] = parse_module;
        cmdmap["-e"] = parse_encoding;
+       cmdmap["-fixedenc"] = parse_fixed_encoding;
        cmdmap["-f"] = parse_force;
        cmdmap["-s"] = parse_syntaxfile;
        cmdmap["-n"] = parse_noweb;
@@ -775,6 +789,14 @@ bool roundtripMode()
 }
 
 
+string fixedEncoding()
+{
+       if (fixed_encoding)
+               return default_encoding;
+       return "";
+}
+
+
 namespace {
 
 /*!
@@ -803,7 +825,7 @@ bool tex2lyx(idocstream & is, ostream & os, string encoding)
                }
        }
 
-       Parser p(is);
+       Parser p(is, fixed_encoding ? default_encoding : string());
        p.setEncoding(encoding);
        //p.dump();