diff --git a/lib/scripts/fig2pdftex.py b/lib/scripts/fig2pdftex.py index 19207d107b..6f711bffbc 100644 --- a/lib/scripts/fig2pdftex.py +++ b/lib/scripts/fig2pdftex.py @@ -28,7 +28,7 @@ # -import os, sys, re, locale +import os, sys, re def runCommand(cmd): @@ -44,12 +44,7 @@ def runCommand(cmd): if len(sys.argv) != 3: sys.exit(1) -language, output_encoding = locale.getdefaultlocale() -if output_encoding == None: - output_encoding = 'latin1' - -input = unicode(sys.argv[1], 'utf8').encode(output_encoding) -output = unicode(sys.argv[2], 'utf8').encode(output_encoding) +input, output = sys.argv[1:] # Fail silently if the file doesn't exist if not os.path.isfile(input): diff --git a/lib/scripts/fig2pstex.py b/lib/scripts/fig2pstex.py index c474d1b09d..1a559821a7 100644 --- a/lib/scripts/fig2pstex.py +++ b/lib/scripts/fig2pstex.py @@ -27,18 +27,13 @@ # the real eps file will be overwritten by a tex file named file.eps. # -import os, sys, locale +import os, sys # We expect two args, the names of the input and output files. if len(sys.argv) != 3: sys.exit(1) -language, output_encoding = locale.getdefaultlocale() -if output_encoding == None: - output_encoding = 'latin1' - -input = unicode(sys.argv[1], 'utf8').encode(output_encoding) -output = unicode(sys.argv[2], 'utf8').encode(output_encoding) +input, output = sys.argv[1:] # Fail silently if the file doesn't exist if not os.path.isfile(input): diff --git a/src/converter.C b/src/converter.C index 0cea5a852f..18dddd33dc 100644 --- a/src/converter.C +++ b/src/converter.C @@ -426,9 +426,11 @@ bool Converters::convert(Buffer const * buffer, int res; if (conv.original_dir) { Path p(buffer->filePath()); - res = one.startscript(type, command); + res = one.startscript(type, + to_filesystem8bit(from_utf8(command))); } else - res = one.startscript(type, command); + res = one.startscript(type, + to_filesystem8bit(from_utf8(command))); if (!real_outfile.empty()) { Mover const & mover = getMover(conv.to); @@ -450,7 +452,8 @@ bool Converters::convert(Buffer const * buffer, string const command2 = script + " < " + quoteName(infile2 + ".out") + " > " + quoteName(logfile); - one.startscript(Systemcall::Wait, command2); + one.startscript(Systemcall::Wait, + to_filesystem8bit(from_utf8(command2))); if (!scanLog(*buffer, command, makeAbsPath(logfile, path), errorList)) return false; } @@ -464,7 +467,7 @@ bool Converters::convert(Buffer const * buffer, // it is a document (.lyx) or something else. Same goes for elsewhere. Alert::error(_("Cannot convert file"), bformat(_("An error occurred whilst running %1$s"), - from_ascii(command.substr(0, 50)))); + from_utf8(command.substr(0, 50)))); } return false; } @@ -487,7 +490,7 @@ bool Converters::convert(Buffer const * buffer, if (!mover.rename(FileName(from), FileName(to))) { Alert::error(_("Cannot convert file"), bformat(_("Could not move a temporary directory from %1$s to %2$s."), - from_ascii(from), from_ascii(to))); + from_utf8(from), from_utf8(to))); return false; } } diff --git a/src/support/docstring.C b/src/support/docstring.C index dd5069acac..a50f3a2b94 100644 --- a/src/support/docstring.C +++ b/src/support/docstring.C @@ -125,6 +125,13 @@ docstring const from_filesystem8bit(std::string const & s) } +std::string const to_filesystem8bit(docstring const & s) +{ + QByteArray const encoded = QFile::encodeName(toqstr(s)); + return std::string(encoded.begin(), encoded.end()); +} + + bool operator==(lyx::docstring const & l, char const * r) { int const len = l.length(); diff --git a/src/support/docstring.h b/src/support/docstring.h index ec5f4012c9..87c5ed43f2 100644 --- a/src/support/docstring.h +++ b/src/support/docstring.h @@ -59,6 +59,9 @@ std::string const to_local8bit(docstring const & s); /// convert \p s from the encoding of the file system to ucs4. docstring const from_filesystem8bit(std::string const & s); +/// convert \p s from ucs4 to the encoding of the file system. +std::string const to_filesystem8bit(docstring const & s); + /// Compare a docstring with a C string of ASCII characters bool operator==(lyx::docstring const &, char const *);