get_system_support_dir(abs_binary,
command_line_system_support_dir);
+ // The LyX executable is one level above binary_dir_ if we are running
+ // tex2lyx in place. Otherwise it is in binary_dir_.
+ string abs_lyx_dir;
+ if (build_support_dir_.empty() ||
+ top_build_dir_location == top_build_dir_is_one_level_up)
+ abs_lyx_dir = binary_dir_.absFileName();
+ else {
+ FileName fn(addPath(binary_dir_.absFileName(), "../"));
+ abs_lyx_dir = fn.realPath();
+ }
+ // The LyX executable may have a package suffix if we are not running
+ // in place.
+ if (build_support_dir_.empty())
+ lyx_binary_ = FileName(addName(abs_lyx_dir,
+ "lyx" + string(PROGRAM_SUFFIX)));
+ else
+ lyx_binary_ = FileName(addName(abs_lyx_dir, "lyx"));
+
locale_dir_ = get_locale_dir(system_support_dir_);
FileName const default_user_support_dir =
std::string const & command_line_user_support_dir,
exe_build_dir_to_top_build_dir);
- /** The directory containing the LyX executable.
+ /** The directory containing the main executable (LyX or tex2lyx).
*/
FileName const & binary_dir() const { return binary_dir_; }
+ /** The absolute path to the LyX executable.
+ */
+ FileName const & lyx_binary() const { return lyx_binary_; }
+
/** The top of the LyX source code tree.
*/
static FileName const & top_srcdir();
private:
FileName binary_dir_;
+ FileName lyx_binary_;
FileName system_support_dir_;
FileName build_support_dir_;
FileName user_support_dir_;
#include "support/Messages.h"
#include "support/os.h"
#include "support/Package.h"
+#include "support/Systemcall.h"
#include <cstdlib>
#include <iostream>
bool noweb_mode = false;
+bool pdflatex = false;
+bool roundtrip = false;
namespace {
"\t-f Force overwrite of .lyx files.\n"
"\t-help Print this message and quit.\n"
"\t-n translate a noweb (aka literate programming) file.\n"
- "\t-s syntaxfile read additional syntax file.\n"
+ "\t-roundtrip re-export created .lyx file infile.lyx.lyx to infile.lyx.tex.\n"
+ "\t-s syntaxfile read additional syntax file.\n"
"\t-sysdir dir Set system directory to DIR.\n"
"\t-userdir DIR Set user directory to DIR."
<< endl;
}
+int parse_roundtrip(string const &, string const &)
+{
+ roundtrip = true;
+ return 0;
+}
+
+
void easyParse(int & argc, char * argv[])
{
map<string, cmd_helper> cmdmap;
cmdmap["-n"] = parse_noweb;
cmdmap["-sysdir"] = parse_sysdir;
cmdmap["-userdir"] = parse_userdir;
+ cmdmap["-roundtrip"] = parse_roundtrip;
for (int i = 1; i < argc; ++i) {
map<string, cmd_helper>::const_iterator it
return tex2lyx(FileName(infilename), os, encoding);
}
+
+bool tex2tex(string const & infilename, FileName const & outfilename,
+ string const & encoding)
+{
+ if (!tex2lyx(infilename, outfilename, encoding))
+ return false;
+ string command = quoteName(package().lyx_binary().toFilesystemEncoding());
+ if (overwrite_files)
+ command += " -f main";
+ else
+ command += " -f none";
+ if (pdflatex)
+ command += " -e pdflatex ";
+ else
+ command += " -e latex ";
+ command += quoteName(outfilename.toFilesystemEncoding());
+ Systemcall one;
+ if (one.startscript(Systemcall::Wait, command) == 0)
+ return true;
+ cerr << "Error: Running '" << command << "' failed." << endl;
+ return false;
+}
+
} // namespace lyx
cerr << to_utf8(message.title_) << ":\n"
<< to_utf8(message.details_) << endl;
if (message.type_ == ErrorException)
- exit(1);
+ return EXIT_FAILURE;
}
// Now every known option is parsed. Look for input and output
infilename = makeAbsPath(infilename).absFileName();
string outfilename;
- if (argc > 2) {
+ if (roundtrip) {
+ if (argc > 2) {
+ // Do not allow a user supplied output filename
+ // (otherwise it could easily happen that LyX would
+ // overwrite the original .tex file)
+ cerr << "Error: output filename must not be given in roundtrip mode."
+ << endl;
+ return EXIT_FAILURE;
+ }
+ outfilename = changeExtension(infilename, ".lyx.lyx");
+ } else if (argc > 2) {
outfilename = internal_path(os::utf8_argv(2));
if (outfilename != "-")
outfilename = makeAbsPath(outfilename).absFileName();
FileName const system_syntaxfile = libFileSearch("", "syntax.default");
if (system_syntaxfile.empty()) {
cerr << "Error: Could not find syntax file \"syntax.default\"." << endl;
- exit(1);
+ return EXIT_FAILURE;
}
read_syntaxfile(system_syntaxfile);
if (!syntaxfile.empty())
if (symbols_path.empty()) {
cerr << "Error: Could not find file \"unicodesymbols\"."
<< endl;
- exit(1);
+ return EXIT_FAILURE;
}
FileName const enc_path = libFileSearch(string(), "encodings");
if (enc_path.empty()) {
cerr << "Error: Could not find file \"encodings\"."
<< endl;
- exit(1);
+ return EXIT_FAILURE;
}
encodings.read(enc_path, symbols_path);
if (!default_encoding.empty() && !encodings.fromLaTeXName(default_encoding))
if (outfilename == "-") {
if (tex2lyx(FileName(infilename), cout, default_encoding))
return EXIT_SUCCESS;
- else
- return EXIT_FAILURE;
+ } else if (roundtrip) {
+ if (tex2tex(infilename, FileName(outfilename), default_encoding))
+ return EXIT_SUCCESS;
} else {
if (tex2lyx(infilename, FileName(outfilename), default_encoding))
return EXIT_SUCCESS;
- else
- return EXIT_FAILURE;
}
+ return EXIT_FAILURE;
}
// }])