Now that insetgraphics writes always "\includegraphics{basename}" instead of
"\includegraphics{basename.ext}", I would like to get rid of the
possibility to omit the file extension in LyX. It is broken in 1.4 anyway
(but works in 1.3).
LyX needs the full filename for previews, and it makes the code cleaner if
this special case is removed.
I wrote a lyx2lyx conversion function (since this is a file format change),
but it does not work if the input file is fed to lyx2lx via stdin. Since
lyx invokes lyx2lyx with the input filename on the commandline, I think we
can live with that.
Another lyx2lyx problem is that the "import as" syntax is not supported by
python 1.5. I need that to avoid a name clash between string.join and
os.path.join. I am sure our python expert has a solution.

Is the attached ok, or are there any reasons to keep the current filename
syntax?

Georg
Index: development/FORMAT
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/development/FORMAT,v
retrieving revision 1.26
diff -u -r1.26 FORMAT
--- development/FORMAT	29 Mar 2004 13:17:21 -0000	1.26
+++ development/FORMAT	27 Apr 2004 17:10:06 -0000
@@ -1,6 +1,11 @@
 LyX file-format changes
 -----------------------
 
+2004-04-27  Georg Baum  <[EMAIL PROTECTED]>
+
+	* 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  <[EMAIL PROTECTED]>
 
Index: lib/lyx2lyx/ChangeLog
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/lib/lyx2lyx/ChangeLog,v
retrieving revision 1.29
diff -u -r1.29 ChangeLog
--- lib/lyx2lyx/ChangeLog	19 Apr 2004 14:30:33 -0000	1.29
+++ lib/lyx2lyx/ChangeLog	27 Apr 2004 17:10:09 -0000
@@ -1,3 +1,9 @@
+2004-04-27  Georg Baum  <[EMAIL PROTECTED]>
+
+	* 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   <[EMAIL PROTECTED]>
 	* parser_tools.py (chain): fix the detection of the last format for
 	revertions.
Index: lib/lyx2lyx/lyx_1_4.py
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/lib/lyx2lyx/lyx_1_4.py,v
retrieving revision 1.2
diff -u -r1.2 lyx_1_4.py
--- lib/lyx2lyx/lyx_1_4.py	19 Apr 2004 12:14:15 -0000	1.2
+++ lib/lyx2lyx/lyx_1_4.py	27 Apr 2004 17:10:09 -0000
@@ -18,9 +18,12 @@
 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 import re
+from os import access, F_OK
+from os.path import abspath, dirname, isabs, normpath, join as path_join
 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 +1244,46 @@
         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 = dirname(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 = normpath(path_join(dir, filename))
+	if opt.input == stdin and not 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.err.write("Warning: Can not determine wether file\n")
+	    opt.err.write("         '" + filename + "'\n")
+	    opt.err.write("         needs an extension when reading from standard input.\n")
+	    opt.err.write("         You may need to correct the file manually or\n")
+	    opt.err.write("         run lyx2lyx again with the .lyx file as commandline argument.\n")
+	    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 +1346,17 @@
     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
Index: lib/lyx2lyx/parser_tools.py
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/lib/lyx2lyx/parser_tools.py,v
retrieving revision 1.21
diff -u -r1.21 parser_tools.py
--- lib/lyx2lyx/parser_tools.py	19 Apr 2004 14:30:33 -0000	1.21
+++ lib/lyx2lyx/parser_tools.py	27 Apr 2004 17:10:09 -0000
@@ -242,7 +242,7 @@
 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 @@
                    ("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)
Index: src/ChangeLog
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/ChangeLog,v
retrieving revision 1.1904
diff -u -r1.1904 ChangeLog
--- src/ChangeLog	26 Apr 2004 11:05:18 -0000	1.1904
+++ src/ChangeLog	27 Apr 2004 17:10:14 -0000
@@ -1,3 +1,7 @@
+2004-04-27  Georg Baum  <[EMAIL PROTECTED]>
+
+	* buffer.C: increment format to 233.
+
 2004-04-26  Georg Baum  <[EMAIL PROTECTED]>
 
 	* LaTeXFeatures.C, lyx_sty.[Ch]: add \lyxdot macro
Index: src/buffer.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/buffer.C,v
retrieving revision 1.573
diff -u -r1.573 buffer.C
--- src/buffer.C	13 Apr 2004 13:54:56 -0000	1.573
+++ src/buffer.C	27 Apr 2004 17:10:15 -0000
@@ -135,7 +135,7 @@
 
 namespace {
 
-const int LYX_FORMAT = 232;
+const int LYX_FORMAT = 233;
 
 } // namespace anon
 
Index: src/insets/ChangeLog
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/ChangeLog,v
retrieving revision 1.1008
diff -u -r1.1008 ChangeLog
--- src/insets/ChangeLog	26 Apr 2004 11:05:19 -0000	1.1008
+++ src/insets/ChangeLog	27 Apr 2004 17:10:23 -0000
@@ -1,3 +1,8 @@
+2004-04-27  Georg Baum  <[EMAIL PROTECTED]>
+
+	* insetgraphics.C: require file extension (file format change!)
+	* insetgraphics.C (latex): handle zipped files for "nice" export
+
 2004-04-26  Georg Baum  <[EMAIL PROTECTED]>
 
 	* insetgraphics.C (latex): strip the extension and replace dots in
Index: src/insets/insetgraphics.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetgraphics.C,v
retrieving revision 1.245
diff -u -r1.245 insetgraphics.C
--- src/insets/insetgraphics.C	26 Apr 2004 11:05:19 -0000	1.245
+++ src/insets/insetgraphics.C	27 Apr 2004 17:10:24 -0000
@@ -110,10 +110,6 @@
 
 namespace {
 
-///////////////////////////////////////////////////////////////////////////
-int const VersionNumber = 1;
-///////////////////////////////////////////////////////////////////////////
-
 // This function is a utility function
 // ... that should be with ChangeExtension ...
 inline
@@ -540,21 +536,12 @@
 	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 @@
 		// 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

Reply via email to