mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-25 05:55:34 +00:00
Fix encoding of converters path and arguments
* src/converter.C (Converters::convert): Convert command to be executed to the proper encoding. Use from_utf8 instead of from_ascii in order to avoid assertions when displaying an alert. * src/support/docstring.[Ch] (to_filesystem8bit): new conversion function. * lib/scripts/fig2pstex.py * lib/scripts/fig2pdftex.py: Modified to reflect the changes above. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@16803 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
5e948b9bf2
commit
b9aa557b35
@ -28,7 +28,7 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
|
|
||||||
import os, sys, re, locale
|
import os, sys, re
|
||||||
|
|
||||||
|
|
||||||
def runCommand(cmd):
|
def runCommand(cmd):
|
||||||
@ -44,12 +44,7 @@ def runCommand(cmd):
|
|||||||
if len(sys.argv) != 3:
|
if len(sys.argv) != 3:
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
language, output_encoding = locale.getdefaultlocale()
|
input, output = sys.argv[1:]
|
||||||
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)
|
|
||||||
|
|
||||||
# Fail silently if the file doesn't exist
|
# Fail silently if the file doesn't exist
|
||||||
if not os.path.isfile(input):
|
if not os.path.isfile(input):
|
||||||
|
@ -27,18 +27,13 @@
|
|||||||
# the real eps file will be overwritten by a tex file named file.eps.
|
# 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.
|
# We expect two args, the names of the input and output files.
|
||||||
if len(sys.argv) != 3:
|
if len(sys.argv) != 3:
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
language, output_encoding = locale.getdefaultlocale()
|
input, output = sys.argv[1:]
|
||||||
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)
|
|
||||||
|
|
||||||
# Fail silently if the file doesn't exist
|
# Fail silently if the file doesn't exist
|
||||||
if not os.path.isfile(input):
|
if not os.path.isfile(input):
|
||||||
|
@ -426,9 +426,11 @@ bool Converters::convert(Buffer const * buffer,
|
|||||||
int res;
|
int res;
|
||||||
if (conv.original_dir) {
|
if (conv.original_dir) {
|
||||||
Path p(buffer->filePath());
|
Path p(buffer->filePath());
|
||||||
res = one.startscript(type, command);
|
res = one.startscript(type,
|
||||||
|
to_filesystem8bit(from_utf8(command)));
|
||||||
} else
|
} else
|
||||||
res = one.startscript(type, command);
|
res = one.startscript(type,
|
||||||
|
to_filesystem8bit(from_utf8(command)));
|
||||||
|
|
||||||
if (!real_outfile.empty()) {
|
if (!real_outfile.empty()) {
|
||||||
Mover const & mover = getMover(conv.to);
|
Mover const & mover = getMover(conv.to);
|
||||||
@ -450,7 +452,8 @@ bool Converters::convert(Buffer const * buffer,
|
|||||||
string const command2 = script +
|
string const command2 = script +
|
||||||
" < " + quoteName(infile2 + ".out") +
|
" < " + quoteName(infile2 + ".out") +
|
||||||
" > " + quoteName(logfile);
|
" > " + quoteName(logfile);
|
||||||
one.startscript(Systemcall::Wait, command2);
|
one.startscript(Systemcall::Wait,
|
||||||
|
to_filesystem8bit(from_utf8(command2)));
|
||||||
if (!scanLog(*buffer, command, makeAbsPath(logfile, path), errorList))
|
if (!scanLog(*buffer, command, makeAbsPath(logfile, path), errorList))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -464,7 +467,7 @@ bool Converters::convert(Buffer const * buffer,
|
|||||||
// it is a document (.lyx) or something else. Same goes for elsewhere.
|
// it is a document (.lyx) or something else. Same goes for elsewhere.
|
||||||
Alert::error(_("Cannot convert file"),
|
Alert::error(_("Cannot convert file"),
|
||||||
bformat(_("An error occurred whilst running %1$s"),
|
bformat(_("An error occurred whilst running %1$s"),
|
||||||
from_ascii(command.substr(0, 50))));
|
from_utf8(command.substr(0, 50))));
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -487,7 +490,7 @@ bool Converters::convert(Buffer const * buffer,
|
|||||||
if (!mover.rename(FileName(from), FileName(to))) {
|
if (!mover.rename(FileName(from), FileName(to))) {
|
||||||
Alert::error(_("Cannot convert file"),
|
Alert::error(_("Cannot convert file"),
|
||||||
bformat(_("Could not move a temporary directory from %1$s to %2$s."),
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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)
|
bool operator==(lyx::docstring const & l, char const * r)
|
||||||
{
|
{
|
||||||
int const len = l.length();
|
int const len = l.length();
|
||||||
|
@ -59,6 +59,9 @@ std::string const to_local8bit(docstring const & s);
|
|||||||
/// convert \p s from the encoding of the file system to ucs4.
|
/// convert \p s from the encoding of the file system to ucs4.
|
||||||
docstring const from_filesystem8bit(std::string const & s);
|
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
|
/// Compare a docstring with a C string of ASCII characters
|
||||||
bool operator==(lyx::docstring const &, char const *);
|
bool operator==(lyx::docstring const &, char const *);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user