From b36c13278b0fcadb3efbb8e8c775e37fc29d800c Mon Sep 17 00:00:00 2001 From: Georg Baum Date: Thu, 29 Apr 2004 09:24:29 +0000 Subject: [PATCH] require file extension for included graphics git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8706 a592a061-630c-0410-9148-cb99ea01b6c8 --- development/FORMAT | 5 ++++ lib/lyx2lyx/ChangeLog | 6 +++++ lib/lyx2lyx/lyx_1_4.py | 54 ++++++++++++++++++++++++++++++++++++- lib/lyx2lyx/parser_tools.py | 4 +-- src/ChangeLog | 4 +++ src/buffer.C | 2 +- src/insets/ChangeLog | 5 ++++ src/insets/insetgraphics.C | 20 +++----------- 8 files changed, 80 insertions(+), 20 deletions(-) diff --git a/development/FORMAT b/development/FORMAT index ad24e10799..de32b9134b 100644 --- a/development/FORMAT +++ b/development/FORMAT @@ -1,6 +1,11 @@ LyX file-format changes ----------------------- +2004-04-29 Georg Baum + + * format incremented to 233. + * insetgraphics does not allow filenames without extension anymore. + The complete filename has to be given. 2004-03-29 Jürgen Spitzmüller diff --git a/lib/lyx2lyx/ChangeLog b/lib/lyx2lyx/ChangeLog index 2bd4869289..f9984032cb 100644 --- a/lib/lyx2lyx/ChangeLog +++ b/lib/lyx2lyx/ChangeLog @@ -1,3 +1,9 @@ +2004-04-29 Georg Baum + + * lyx_1_4.py (convert_graphics): new, convert graphics filenames + * lyx_1_4.py (revert, convert): handle format 233 + * lyx2lyx: up the format to 233. + 2004-04-19 José Matos * parser_tools.py (chain): fix the detection of the last format for revertions. diff --git a/lib/lyx2lyx/lyx_1_4.py b/lib/lyx2lyx/lyx_1_4.py index 212805b338..058d3e9f7b 100644 --- a/lib/lyx2lyx/lyx_1_4.py +++ b/lib/lyx2lyx/lyx_1_4.py @@ -18,9 +18,12 @@ # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. import re +from os import access, F_OK +import os.path from parser_tools import find_token, find_end_of_inset, get_next_paragraph, \ get_paragraph, get_value, del_token, is_nonempty_line,\ - find_tokens, find_end_of + find_tokens, find_end_of, find_token2 +from sys import stdin from string import replace, split, find, strip, join ## @@ -1115,6 +1118,46 @@ def revert_float(lines, opt): del_token(lines, 'sideways', i, j) i = i + 1 +def convert_graphics(lines, opt): + """ Add extension to filenames of insetgraphics if necessary. + """ + if opt.input == stdin: + dir = "" + else: + dir = os.path.dirname(os.path.abspath(opt.input.name)) + i = 0 + while 1: + i = find_token(lines, "\\begin_inset Graphics", i) + if i == -1: + return + + j = find_token2(lines, "filename", i) + if j == -1: + return + i = i + 1 + filename = split(lines[j])[1] + absname = os.path.normpath(os.path.join(dir, filename)) + if opt.input == stdin and not os.path.isabs(filename): + # We don't know the directory and cannot check the file. + # We could use a heuristic and take the current directory, + # and we could try to find out if filename has an extension, + # but that would be just guesses and could be wrong. + opt.warning("""Warning: Can not determine wether file + %s + needs an extension when reading from standard input. + You may need to correct the file manually or run + lyx2lyx again with the .lyx file as commandline argument.""" % filename) + continue + # This needs to be the same algorithm as in pre 233 insetgraphics + if access(absname, F_OK): + continue + if access(absname + ".ps", F_OK): + lines[j] = replace(lines[j], filename, filename + ".ps") + continue + if access(absname + ".eps", F_OK): + lines[j] = replace(lines[j], filename, filename + ".eps") + + ## # Convertion hub # @@ -1177,8 +1220,17 @@ def convert(header, body, opt): if opt.format < 232: convert_bibtopic(header, opt) opt.format = 232 + if opt.end == opt.format: return + + if opt.format < 233: + convert_graphics(body, opt) + opt.format = 233 def revert(header, body, opt): + if opt.format > 232: + opt.format = 232 + if opt.end == opt.format: return + if opt.format > 231: revert_bibtopic(header, opt) opt.format = 231 diff --git a/lib/lyx2lyx/parser_tools.py b/lib/lyx2lyx/parser_tools.py index 95f60d22fc..ac4651c4c3 100644 --- a/lib/lyx2lyx/parser_tools.py +++ b/lib/lyx2lyx/parser_tools.py @@ -242,7 +242,7 @@ def set_version(lines, version): format_re = re.compile(r"(\d)[\.,]?(\d\d)") fileformat = re.compile(r"\\lyxformat\s*(\S*)") lst_ft = [210, 215, 216, 217, 218, 220, 221, 223, 224, 225, 226, 227, 228, 229, - 230, 231, 232] + 230, 231, 232, 233] format_relation = [("0_10", [210], ["0.10.7","0.10"]), ("0_12", [215], ["0.12","0.12.1","0.12"]), @@ -254,7 +254,7 @@ format_relation = [("0_10", [210], ["0.10.7","0.10"]), ("1_1_6fix3", [218], ["1.1.6fix3","1.1.6fix4","1.1"]), ("1_2", [220], ["1.2.0","1.2.1","1.2.3","1.2.4","1.2"]), ("1_3", [221], ["1.3.0","1.3.1","1.3.2","1.3.3","1.3.4","1.3"]), - ("1_4", [223,224,225,226,227,228,229,230,231,232], ["1.4.0cvs","1.4"])] + ("1_4", [223,224,225,226,227,228,229,230,231,232,233], ["1.4.0cvs","1.4"])] def lyxformat(format, opt): result = format_re.match(format) diff --git a/src/ChangeLog b/src/ChangeLog index a6dddf70b8..05404ca962 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,7 @@ +2004-04-29 Georg Baum + + * buffer.C: increment format to 233. + 2004-04-28 Angus Leeming * BufferView.[Ch] (c-tor): diff --git a/src/buffer.C b/src/buffer.C index e6e5d02a63..054c7f0659 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -135,7 +135,7 @@ extern BufferList bufferlist; namespace { -const int LYX_FORMAT = 232; +const int LYX_FORMAT = 233; } // namespace anon diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index 3f3e4c711d..e14530d5df 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,8 @@ +2004-04-29 Georg Baum + + * insetgraphics.C: require file extension (file format change!) + * insetgraphics.C (latex): handle zipped files for "nice" export + 2004-04-26 Georg Baum * insetgraphics.C (latex): strip the extension and replace dots in diff --git a/src/insets/insetgraphics.C b/src/insets/insetgraphics.C index 3f9f3465a3..288a645daf 100644 --- a/src/insets/insetgraphics.C +++ b/src/insets/insetgraphics.C @@ -110,10 +110,6 @@ using std::ostringstream; namespace { -/////////////////////////////////////////////////////////////////////////// -int const VersionNumber = 1; -/////////////////////////////////////////////////////////////////////////// - // This function is a utility function // ... that should be with ChangeExtension ... inline @@ -540,21 +536,12 @@ int InsetGraphics::latex(Buffer const & buf, ostream & os, string const relative_file = params().filename.relFilename(buf.filePath()); - // A missing (e)ps-extension is no problem for LaTeX, so - // we have to test three different cases -#ifdef WITH_WARNINGS -#warning uh, but can our cache handle it ? no. -#endif string const file_ = params().filename.absFilename(); - bool const file_exists = - !file_.empty() && - (IsFileReadable(file_) || // original - IsFileReadable(file_ + ".eps") || // original.eps - IsFileReadable(file_ + ".ps")); // original.ps + bool const file_exists = !file_.empty() && IsFileReadable(file_); string const message = file_exists ? string() : string("bb = 0 0 200 100, draft, type=eps"); // if !message.empty() than there was no existing file - // "filename(.(e)ps)" found. In this case LaTeX + // "filename" found. In this case LaTeX // draws only a rectangle with the above bb and the // not found filename in it. lyxerr[Debug::GRAPHICS] @@ -596,7 +583,8 @@ int InsetGraphics::latex(Buffer const & buf, ostream & os, // Remove the extension so the LaTeX will use whatever // is appropriate (when there are several versions in // different formats) - if (!(IsFileReadable(file_ + ".eps") || IsFileReadable(file_ + ".ps"))) + basename = RemoveExtension(basename); + if(params().filename.isZipped()) basename = RemoveExtension(basename); // This works only if the filename contains no dots besides // the just removed one. We can fool here by replacing all -- 2.39.2