using std::vector;
using std::map;
+using lyx::support::ChangeExtension;
using lyx::support::isStrUnsignedInt;
using lyx::support::ltrim;
using lyx::support::MakeAbsPath;
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"
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;
}
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;
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;
+ }
}
// }])