The attached patch simply refactors the name mangling code in
insetgraphics into a separate function. OK to commit?
If we're unable to resolve this "long file name causes gs to die"
problem, then I'd suggest reworking the function to use the file name
only and a unique counter ID.
--
Angus
Index: src/insets/insetgraphics.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetgraphics.C,v
retrieving revision 1.146.2.12
diff -u -p -r1.146.2.12 insetgraphics.C
--- src/insets/insetgraphics.C 4 Jul 2005 11:26:41 -0000 1.146.2.12
+++ src/insets/insetgraphics.C 8 Jul 2005 15:33:29 -0000
@@ -523,6 +523,29 @@ string const InsetGraphics::createLatexO
}
+namespace {
+
+string const mangle_filename(string const & input)
+{
+ string const ext = GetExtension(input);
+ // Remove the extension and replace all '/' with '_'.
+ string output = subst(ChangeExtension(input, string()), "/", "_");
+ // Replace all ' ' with '_'.
+ output = subst(output, " ", "_");
+ // Replace all '.' with '_' and add the extension back on.
+ output = ChangeExtension(subst(output, ".", "_"), ext);
+
+#if defined(__CYGWIN__) || defined(__CYGWIN32__) || defined(_WIN32)
+ // Mangle the drive letter in a Windows-style path.
+ if (output.size() >= 2 && output[1] == ':')
+ output[1] = '_';
+#endif
+ return output;
+}
+
+}
+
+
string const InsetGraphics::prepareFile(Buffer const * buf) const
{
// LaTeX can cope if the graphics file doesn't exist, so just
@@ -619,21 +642,7 @@ string const InsetGraphics::prepareFile(
<< "\tthe orig file is: " << orig_file_with_path << endl;
if (lyxrc.use_tempdir) {
- string const ext_tmp = GetExtension(orig_file_with_path);
- // without ext and /
- temp_file = subst(
- ChangeExtension(orig_file_with_path, string()), "/", "_");
- // Replace ' ' in the file name with '_'
- temp_file = subst(temp_file, " ", "_");
- // without dots and again with ext
- temp_file = ChangeExtension(
- subst(temp_file, ".", "_"), ext_tmp);
-
-#if defined(__CYGWIN__) || defined(__CYGWIN32__) || defined(_WIN32)
- // Mangle the drive letter in a Windows-style path.
- if (temp_file.size() >= 2 && temp_file[1] == ':')
- temp_file[1] = '_';
-#endif
+ temp_file = mangle_filename(orig_file_with_path);
// now we have any_dir_file.ext
temp_file = MakeAbsPath(temp_file, buf->tmppath);