On Fri, Mar 12, 2010 at 02:18:40AM +0100, [email protected] wrote:
> Author: forenr
> Date: Fri Mar 12 02:18:39 2010
> New Revision: 33723
> URL: http://www.lyx.org/trac/changeset/33723
>
> Log:
> Fix command line parsing and allow unicode arguments for tex2lyx on Windows.
Jürgen, this is also needed in branch.
> Modified:
> lyx-devel/trunk/src/LyX.cpp
> lyx-devel/trunk/src/support/os.h
> lyx-devel/trunk/src/support/os_cygwin.cpp
> lyx-devel/trunk/src/support/os_unix.cpp
> lyx-devel/trunk/src/support/os_win32.cpp
> lyx-devel/trunk/src/tex2lyx/tex2lyx.cpp
>
> Modified: lyx-devel/trunk/src/LyX.cpp
> ==============================================================================
> --- lyx-devel/trunk/src/LyX.cpp Fri Mar 12 01:27:12 2010 (r33722)
> +++ lyx-devel/trunk/src/LyX.cpp Fri Mar 12 02:18:39 2010 (r33723)
> @@ -1133,6 +1133,7 @@
> // Now, remove used arguments by shifting
> // the following ones remove places down.
> if (remove > 0) {
> + os::remove_internal_args(i, remove);
> argc -= remove;
> for (int j = i; j < argc; ++j)
> argv[j] = argv[j + remove];
>
> Modified: lyx-devel/trunk/src/support/os.h
> ==============================================================================
> --- lyx-devel/trunk/src/support/os.h Fri Mar 12 01:27:12 2010 (r33722)
> +++ lyx-devel/trunk/src/support/os.h Fri Mar 12 02:18:39 2010 (r33723)
> @@ -49,6 +49,9 @@
> /// Returns the i-th program argument in utf8 encoding.
> std::string utf8_argv(int i);
>
> +/// Removes from the internal copy \p num program arguments starting from \p
> i.
> +void remove_internal_args(int i, int num);
> +
> /// Returns the name of the NULL device (/dev/null, null).
> std::string const & nulldev();
>
>
> Modified: lyx-devel/trunk/src/support/os_cygwin.cpp
> ==============================================================================
> --- lyx-devel/trunk/src/support/os_cygwin.cpp Fri Mar 12 01:27:12 2010
> (r33722)
> +++ lyx-devel/trunk/src/support/os_cygwin.cpp Fri Mar 12 02:18:39 2010
> (r33723)
> @@ -228,6 +228,10 @@
> }
>
>
> +void remove_internal_args(int, int)
> +{}
> +
> +
> string current_root()
> {
> return string("/");
>
> Modified: lyx-devel/trunk/src/support/os_unix.cpp
> ==============================================================================
> --- lyx-devel/trunk/src/support/os_unix.cpp Fri Mar 12 01:27:12 2010
> (r33722)
> +++ lyx-devel/trunk/src/support/os_unix.cpp Fri Mar 12 02:18:39 2010
> (r33723)
> @@ -52,6 +52,10 @@
> }
>
>
> +void remove_internal_args(int, int)
> +{}
> +
> +
> string current_root()
> {
> return "/";
>
> Modified: lyx-devel/trunk/src/support/os_win32.cpp
> ==============================================================================
> --- lyx-devel/trunk/src/support/os_win32.cpp Fri Mar 12 01:27:12 2010
> (r33722)
> +++ lyx-devel/trunk/src/support/os_win32.cpp Fri Mar 12 02:18:39 2010
> (r33723)
> @@ -209,6 +209,14 @@
> }
>
>
> +void remove_internal_args(int i, int num)
> +{
> + argc_ -= num;
> + for (int j = i; j < argc_; ++j)
> + argv_[j] = argv_[j + num];
> +}
> +
> +
> string current_root()
> {
> // _getdrive returns the current drive (1=A, 2=B, and so on).
>
> Modified: lyx-devel/trunk/src/tex2lyx/tex2lyx.cpp
> ==============================================================================
> --- lyx-devel/trunk/src/tex2lyx/tex2lyx.cpp Fri Mar 12 01:27:12 2010
> (r33722)
> +++ lyx-devel/trunk/src/tex2lyx/tex2lyx.cpp Fri Mar 12 02:18:39 2010
> (r33723)
> @@ -381,13 +381,14 @@
> continue;
> }
>
> - string arg(to_utf8(from_local8bit((i + 1 < argc) ? argv[i + 1]
> : "")));
> - string arg2(to_utf8(from_local8bit((i + 2 < argc) ? argv[i + 2]
> : "")));
> + string arg = (i + 1 < argc) ? os::utf8_argv(i + 1) : string();
> + string arg2 = (i + 2 < argc) ? os::utf8_argv(i + 2) : string();
>
> int const remove = 1 + it->second(arg, arg2);
>
> // Now, remove used arguments by shifting
> // the following ones remove places down.
> + os::remove_internal_args(i, remove);
> argc -= remove;
> for (int j = i; j < argc; ++j)
> argv[j] = argv[j + remove];
> @@ -519,14 +520,15 @@
>
> lyxerr.setStream(cerr);
>
> + os::init(argc, argv);
> +
> easyParse(argc, argv);
>
> if (argc <= 1)
> error_message("Not enough arguments.");
> - os::init(argc, argv);
>
> try {
> - init_package(internal_path(to_utf8(from_local8bit(argv[0]))),
> + init_package(internal_path(os::utf8_argv(0)),
> cl_system_support, cl_user_support,
> top_build_dir_is_two_levels_up);
> } catch (ExceptionMessage const & message) {
> @@ -538,12 +540,12 @@
>
> // Now every known option is parsed. Look for input and output
> // file name (the latter is optional).
> - string infilename = internal_path(to_utf8(from_local8bit(argv[1])));
> + string infilename = internal_path(os::utf8_argv(1));
> infilename = makeAbsPath(infilename).absFilename();
>
> string outfilename;
> if (argc > 2) {
> - outfilename = internal_path(to_utf8(from_local8bit(argv[2])));
> + outfilename = internal_path(os::utf8_argv(2));
> if (outfilename != "-")
> outfilename = makeAbsPath(outfilename).absFilename();
> } else
--
Enrico