From 18f79eeddcf58e2b20c883ca26d895ab34c074c2 Mon Sep 17 00:00:00 2001 From: Julien Rioux Date: Mon, 3 Oct 2011 17:47:37 +0000 Subject: [PATCH] tex2lyx : More descriptive --help message and implement --version (#6827). The init_package before easyParse is necessary to initiate the default values for userdir and sysdir, which are now part of the help message. This step would be necessary anyway if we ever internationalize tex2lyx. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@39799 a592a061-630c-0410-9148-cb99ea01b6c8 --- development/scons/scons_manifest.py | 1 + src/tex2lyx/CMakeLists.txt | 4 +-- src/tex2lyx/Makefile.am | 3 ++- src/tex2lyx/tex2lyx.cpp | 40 ++++++++++++++++++++++++++--- 4 files changed, 41 insertions(+), 7 deletions(-) diff --git a/development/scons/scons_manifest.py b/development/scons/scons_manifest.py index bb1883c4ae..af9d072987 100644 --- a/development/scons/scons_manifest.py +++ b/development/scons/scons_manifest.py @@ -633,6 +633,7 @@ src_tex2lyx_copied_files = Split(''' ModuleList.cpp Spacing.cpp TextClass.cpp + version.cpp insets/InsetLayout.cpp ''') diff --git a/src/tex2lyx/CMakeLists.txt b/src/tex2lyx/CMakeLists.txt index 49d39c4bd4..0debbeb022 100644 --- a/src/tex2lyx/CMakeLists.txt +++ b/src/tex2lyx/CMakeLists.txt @@ -13,9 +13,9 @@ set(LINKED_sources ${TOP_SRC_DIR}/src/lengthcommon.cpp) set(LINKED_headers) foreach(_src insets/InsetLayout Color Counters - Encoding FloatList Floating + Encoding FloatList Floating FontInfo Layout LayoutFile LayoutModuleList Lexer ModuleList TextClass - FontInfo Spacing) + Spacing version) list(APPEND LINKED_sources ${TOP_SRC_DIR}/src/${_src}.cpp) list(APPEND LINKED_headers ${TOP_SRC_DIR}/src/${_src}.h) endforeach(_src) diff --git a/src/tex2lyx/Makefile.am b/src/tex2lyx/Makefile.am index ac38c8025b..fc39503b90 100644 --- a/src/tex2lyx/Makefile.am +++ b/src/tex2lyx/Makefile.am @@ -44,7 +44,8 @@ LINKED_FILES = \ ../ModuleList.cpp \ ../Spacing.cpp \ ../TextClass.cpp \ - ../TextClass.h + ../TextClass.h \ + ../version.cpp BUILT_SOURCES = $(PCH_FILE) diff --git a/src/tex2lyx/tex2lyx.cpp b/src/tex2lyx/tex2lyx.cpp index 8ba2c4ddec..d5538d8c36 100644 --- a/src/tex2lyx/tex2lyx.cpp +++ b/src/tex2lyx/tex2lyx.cpp @@ -11,6 +11,7 @@ // {[( #include +#include #include "tex2lyx.h" @@ -464,13 +465,33 @@ int parse_help(string const &, string const &) "\t-n translate a noweb (aka literate programming) 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." + "\t-sysdir SYSDIR Set system directory to SYSDIR.\n" + "\t Default: " << package().system_support() << "\n" + "\t-userdir USERDIR Set user directory to USERDIR.\n" + "\t Default: " << package().user_support() << "\n" + "\t-version Summarize version and build info.\n" + "Paths:\n" + "\tThe program searches for the files \"encodings\", \"lyxmodules.lst\",\n" + "\t\"textclass.lst\", \"syntax.default\", and \"unicodesymbols\", first in\n" + "\t\"USERDIR\", then in \"SYSDIR\". The subdirectories \"USERDIR/layouts\"\n" + "\tand \"SYSDIR/layouts\" are searched for layout and module files.\n" + "Check the tex2lyx man page for more details." << endl; exit(error_code); } +int parse_version(string const &, string const &) +{ + lyxerr << "tex2lyx " << lyx_version + << " (" << lyx_release_date << ")" << endl; + lyxerr << "Built on " << __DATE__ << ", " << __TIME__ << endl; + + lyxerr << lyx_version_info << endl; + exit(error_code); +} + + void error_message(string const & message) { cerr << "tex2lyx: " << message << "\n\n"; @@ -555,12 +576,14 @@ void easyParse(int & argc, char * argv[]) { map cmdmap; + cmdmap["-help"] = parse_help; + cmdmap["--help"] = parse_help; + cmdmap["-version"] = parse_version; + cmdmap["--version"] = parse_version; cmdmap["-c"] = parse_class; cmdmap["-e"] = parse_encoding; cmdmap["-f"] = parse_force; cmdmap["-s"] = parse_syntaxfile; - cmdmap["-help"] = parse_help; - cmdmap["--help"] = parse_help; cmdmap["-n"] = parse_noweb; cmdmap["-sysdir"] = parse_sysdir; cmdmap["-userdir"] = parse_userdir; @@ -766,6 +789,15 @@ int main(int argc, char * argv[]) os::init(argc, argv); + try { + init_package(internal_path(os::utf8_argv(0)), string(), string()); + } catch (ExceptionMessage const & message) { + cerr << to_utf8(message.title_) << ":\n" + << to_utf8(message.details_) << endl; + if (message.type_ == ErrorException) + return EXIT_FAILURE; + } + easyParse(argc, argv); if (argc <= 1) -- 2.39.2