]> git.lyx.org Git - lyx.git/blobdiff - src/support/filetools.C
use more explicit on constructors use the pimpl idom to reduce size with about 500k
[lyx.git] / src / support / filetools.C
index 2c816a913c1dc509b101926897ca8a62229acbd4..4847419b498c661bbbf75793bf34a7b0c8a65497 100644 (file)
@@ -19,8 +19,6 @@
 #include <cctype>
 
 #include <utility>
-using std::make_pair;
-using std::pair;
 
 #ifdef __GNUG__
 #pragma implementation "filetools.h"
@@ -52,6 +50,10 @@ using std::pair;
 # endif
 #endif
 
+using std::make_pair;
+using std::pair;
+using std::endl;
+
 extern string system_lyxdir;
 extern string build_lyxdir;
 extern string user_lyxdir;
@@ -64,12 +66,6 @@ bool IsLyXFilename(string const & filename)
 }
 
 
-bool IsSGMLFilename(string const & filename)
-{
-       return contains(filename, ".sgml");
-}
-
-
 // Substitutes spaces with underscores in filename (and path)
 string MakeLatexName(string const & file)
 {
@@ -904,12 +900,10 @@ string ChangeExtension(string const & oldname, string const & extension,
                        bool no_path) 
 {
        string::size_type last_slash = oldname.rfind('/');
-       string::size_type last_dot;
-       if (last_slash != string::npos)
-               last_dot = oldname.find('.', last_slash);
-       else
-               last_dot = oldname.rfind('.');
-
+       string::size_type last_dot = oldname.rfind('.');
+       if (last_dot < last_slash && last_slash != string::npos)
+               last_dot = string::npos;
+       
        string ext;
        // Make sure the extension starts with a dot
        if (!extension.empty() && extension[0] != '.')
@@ -991,7 +985,8 @@ bool LyXReadLink(string const & File, string & Link)
 
 
 typedef pair<int, string> cmdret;
-static cmdret do_popen(string const & cmd)
+static
+cmdret do_popen(string const & cmd)
 {
        // One question is if we should use popen or
        // create our own popen based on fork, exec, pipe
@@ -1010,7 +1005,7 @@ static cmdret do_popen(string const & cmd)
 }
 
 
-string findtexfile(string const & fil, string const & format)
+string findtexfile(string const & fil, string const & /*format*/)
 {
        /* There is no problem to extend this function too use other
           methods to look for files. It could be setup to look
@@ -1021,15 +1016,32 @@ string findtexfile(string const & fil, string const & format)
           Lgb
        */
        
-        // If fil is a file with absolute path we just return it
-        if (AbsolutePath(fil)) return fil;
-       
-        // Check in the current dir.
-        if (FileInfo(OnlyFilename(fil)).exist())
-               return OnlyFilename(fil);
-       
+       // If the file can be found directly, we just return a
+       // absolute path version of it. 
+        if (FileInfo(fil).exist())
+               return MakeAbsPath(fil);
+
         // No we try to find it using kpsewhich.
-        string kpsecmd = "kpsewhich --format=" + format + " " + OnlyFilename(fil);
+       // It seems from the kpsewhich manual page that it is safe to use
+       // kpsewhich without --format: "When the --format option is not
+       // given, the search path used when looking for a file is inferred
+       // from the name given, by looking for a known extension. If no
+       // known extension is found, the search path for TeX source files
+       // is used."
+       // However, we want to take advantage of the format sine almost all
+       // the different formats has environment variables that can be used
+       // to controll which paths to search. f.ex. bib looks in
+       // BIBINPUTS and TEXBIB. Small list follows:
+       // bib - BIBINPUTS, TEXBIB
+       // bst - BSTINPUTS
+       // graphic/figure - TEXPICTS, TEXINPUTS
+       // ist - TEXINDEXSTYLE, INDEXSTYLE
+       // pk - PROGRAMFONTS, PKFONTS, TEXPKS, GLYPHFONTS, TEXFONTS
+       // tex - TEXINPUTS
+       // tfm - TFMFONTS, TEXFONTS
+       // This means that to use kpsewhich in the best possible way we
+       // should help it by setting additional path in the approp. envir.var.
+        string kpsecmd = "kpsewhich " + fil;
 
         cmdret c = do_popen(kpsecmd);