]> git.lyx.org Git - lyx.git/blobdiff - src/tex2lyx/tex2lyx.C
Continue to improve GtkLengthEntry
[lyx.git] / src / tex2lyx / tex2lyx.C
index b3d4da3031e1df2f74ad911e1e8c4f07a5008b91..22c13660d118296d77d11a5f9210847f51d64bb8 100644 (file)
@@ -52,6 +52,7 @@ using std::string;
 using std::vector;
 using std::map;
 
+using lyx::support::ChangeExtension;
 using lyx::support::isStrUnsignedInt;
 using lyx::support::ltrim;
 using lyx::support::MakeAbsPath;
@@ -267,7 +268,7 @@ typedef boost::function<int(string const &, string const &)> cmd_helper;
 
 int parse_help(string const &, string const &)
 {
-       cerr << "Usage: tex2lyx [ command line switches ] <infile.tex>\n"
+       cerr << "Usage: tex2lyx [ command line switches ] <infile.tex> [<outfile.lyx>]\n"
                "Command line switches (case sensitive):\n"
                "\t-help              summarize tex2lyx usage\n"
                "\t-f                 Force creation of .lyx files even if they exist already\n"
@@ -482,7 +483,7 @@ int main(int argc, char * argv[])
        easyParse(argc, argv);
 
        if (argc <= 1) {
-               cerr << "Usage: tex2lyx [ command line switches ] <infile.tex>\n"
+               cerr << "Usage: tex2lyx [ command line switches ] <infile.tex> [<outfile.lyx>]\n"
                          "See tex2lyx -help." << endl;
                return 2;
        }
@@ -491,6 +492,17 @@ int main(int argc, char * argv[])
        lyx::support::init_package(argv[0], cl_system_support, cl_user_support,
                                   lyx::support::top_build_dir_is_two_levels_up);
 
+       // Now every known option is parsed. Look for input and output
+       // file name (the latter is optional).
+       string const infilename = MakeAbsPath(argv[1]);
+       string outfilename;
+       if (argc > 2) {
+               outfilename = argv[2];
+               if (outfilename != "-")
+                       outfilename = MakeAbsPath(argv[2]);
+       } else
+               outfilename = ChangeExtension(infilename, ".lyx");
+
        string const system_syntaxfile = lyx::support::LibFileSearch("", "syntax.default");
        if (system_syntaxfile.empty()) {
                cerr << "Error: Could not find syntax file \"syntax.default\"." << endl;
@@ -500,14 +512,20 @@ int main(int argc, char * argv[])
        if (!syntaxfile.empty())
                read_syntaxfile(syntaxfile);
 
-       string const infilename = MakeAbsPath(argv[1]);
        masterFilePath = OnlyPath(infilename);
        parentFilePath = masterFilePath;
 
-       if (tex2lyx(infilename, cout))
-               return EXIT_SUCCESS;
-       else
-               return EXIT_FAILURE;
+       if (outfilename == "-") {
+               if (tex2lyx(infilename, cout))
+                       return EXIT_SUCCESS;
+               else
+                       return EXIT_FAILURE;
+       } else {
+               if (tex2lyx(infilename, outfilename))
+                       return EXIT_SUCCESS;
+               else
+                       return EXIT_FAILURE;
+       }
 }
 
 // }])