On Mon, Dec 18, 2006 at 08:56:26PM +0100, Georg Baum wrote:

> Am Montag, 18. Dezember 2006 20:11 schrieb Enrico Forestieri:
> 
> > The attached patch solves this problem and also fixes the following bug:
> > if you try to load a file named "foo.bar.lyx" and give "foo.bar" on the
> > command line, LyX tries to load "foo.lyx", instead.
> > 
> > I'll commit it later if I don't get objections.
> 
> I don't understand from a quick glance what is going on here and don't have 
> the time to investigate further, but fileSearch is supposed to do exactly 
> what you do now manually. Therefore I think you should fix fileSearch, and 
> leave the code you changed alone. That would have the added benefit that 
> the same problem will be fixed at other places where fileSearch is used, 
> too.

Been there, done that. The attached would be the patch you are looking
for, but it only fixes the assertion, not the other bug I mention.
This is because fileSearch is designed to replace an extension, not to
add one. Of course, it would be possible to modify fileSearch such that
it adds the extension when must_be_readable is false, but I find this
approach rather ugly.

-- 
Enrico
Index: src/support/filetools.C
===================================================================
--- src/support/filetools.C     (revision 16318)
+++ src/support/filetools.C     (working copy)
@@ -250,7 +250,7 @@ vector<string> const dirList(FileName co
 // Returns the real name of file name in directory path, with optional
 // extension ext.
 FileName const fileSearch(string const & path, string const & name,
-                       string const & ext)
+                       string const & ext, bool must_be_readable)
 {
        // if `name' is an absolute path, we ignore the setting of `path'
        // Expand Environmentvariables in 'name'
@@ -260,9 +260,11 @@ FileName const fileSearch(string const &
        if (isFileReadable(fullname))
                return fullname;
        if (ext.empty())
-               return FileName();
+               return must_be_readable ? FileName() : fullname;
        fullname = FileName(changeExtension(fullname.absFilename(), ext));
-       return isFileReadable(fullname) ? fullname : FileName();
+       if (must_be_readable)
+               return isFileReadable(fullname) ? fullname : FileName();
+       return fullname;
 }
 
 
Index: src/support/filetools.h
===================================================================
--- src/support/filetools.h     (revision 16318)
+++ src/support/filetools.h     (working copy)
@@ -57,7 +57,8 @@ FileName const fileOpenSearch(std::strin
   */
 FileName const fileSearch(std::string const & path,
                             std::string const & name,
-                            std::string const & ext = std::string());
+                            std::string const & ext = std::string(),
+                            bool must_be_readable = true);
 
 /// Returns a vector of all files in directory dir having extension ext.
 std::vector<std::string> const dirList(FileName const & dir,
Index: src/lyx_main.C
===================================================================
--- src/lyx_main.C      (revision 16318)
+++ src/lyx_main.C      (working copy)
@@ -480,7 +480,8 @@ int LyX::init(int & argc, char * argv[])
                // get absolute path of file and add ".lyx" to
                // the filename if necessary
                pimpl_->files_to_load_.push_back(fileSearch(string(),
-                       os::internal_path(to_utf8(from_local8bit(argv[argi]))), 
"lyx"));
+                       os::internal_path(to_utf8(from_local8bit(argv[argi]))),
+                       "lyx", false));
        }
 
        if (first_start)

Reply via email to