]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/controllers/tex_helpers.C
Add a buffer_path arg to InsetGraphicsMailer's params2string, string2params.
[lyx.git] / src / frontends / controllers / tex_helpers.C
index eb74039082f34b90ab1aa2533b95725a22e1d4f6..ad72098e1558f72551403b14bd2724489b23bc6b 100644 (file)
@@ -1,17 +1,15 @@
 /**
  * \file tex_helpers.C
- * Copyright 1995-2002 the LyX Team
- * Read the file COPYING
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
  *
- * \author Herbert Voss <voss@lyx.org>
+ * \author Herbert Voss
+ *
+ * Full author contact details are available in file CREDITS
  */
 
 #include <config.h>
 
-#ifdef __GNUG__
-#pragma implementation
-#endif
-
 #include "tex_helpers.h"
 
 #include "debug.h"
 #include "support/path.h"
 #include "support/lyxalgo.h"
 
+#include <boost/cregex.hpp>
 #include <vector>
 #include <fstream>
 #include <algorithm>
 
+using namespace lyx::support;
+
 using std::vector;
 using std::endl;
 using std::sort;
@@ -34,18 +35,6 @@ using std::unique;
 
 extern string user_lyxdir; // home of *Files.lst
 
-namespace {
-
-vector<string> listWithoutPath(vector<string> & dbase)
-{
-       vector<string>::iterator it = dbase.begin();
-       vector<string>::iterator end = dbase.end();
-       for (; it != end; ++it) 
-               *it = OnlyFilename(*it);
-       return dbase;
-}
-
-}
 
 // build filelists of all availabe bst/cls/sty-files. done through
 // kpsewhich and an external script, saved in *Files.lst
@@ -56,7 +45,6 @@ void rescanTexStyles()
        Systemcall one;
        one.startscript(Systemcall::Wait,
                        LibFileSearch("scripts", "TeXFiles.sh"));
-       p.pop();
 }
 
 
@@ -67,66 +55,72 @@ void texhash()
 
        //path to texhash through system
        Systemcall one;
-       one.startscript(Systemcall::Wait,"texhash"); 
-       p.pop();
+       one.startscript(Systemcall::Wait,"texhash");
 }
 
-string const getTexFileList(string const & filename, bool withFullPath)
+
+void getTexFileList(string const & filename, std::vector<string> & list)
 {
+       list.clear();
        string const file = LibFileSearch("", filename);
        if (file.empty())
-               return string();
-       vector<string> dbase =
-               getVectorFromString(GetFileContents(file), "\n");
-
-       lyx::eliminate_duplicates(dbase); 
-       string const str_out = withFullPath ?
-               getStringFromVector(dbase, "\n") :
-               getStringFromVector(listWithoutPath(dbase), "\n");
-       return str_out;
+               return;
+
+       list = getVectorFromString(GetFileContents(file), "\n");
+
+       // Normalise paths like /foo//bar ==> /foo/bar
+       boost::RegEx regex("/{2,}");
+       std::vector<string>::iterator it  = list.begin();
+       std::vector<string>::iterator end = list.end();
+       for (; it != end; ++it) {
+               *it = STRCONV(regex.Merge(STRCONV((*it)), "/"));
+       }
+
+       lyx::eliminate_duplicates(list);
 }
 
 
-string const getListOfOptions(string const & classname,
-                           string const & type)
+string const getListOfOptions(string const & classname, string const & type)
 {
        string const filename = getTexFileFromList(classname,type);
        string optionList = string();
        std::ifstream is(filename.c_str());
        while (is) {
-           string s;
-           is >> s;
-           if (contains(s,"DeclareOption")) {
-               s = s.substr(s.find("DeclareOption"));
-               s = split(s,'{');               // cut front
-               s = token(s,'}',0);             // cut end
-               optionList += (s + '\n');
-           }
+               string s;
+               is >> s;
+               if (contains(s,"DeclareOption")) {
+                       s = s.substr(s.find("DeclareOption"));
+                       s = split(s,'{');               // cut front
+                       s = token(s,'}',0);             // cut end
+                       optionList += (s + '\n');
+               }
        }
        return optionList;
 }
 
 
-string const getTexFileFromList(string const & file, 
+string const getTexFileFromList(string const & file,
                            string const & type)
 {
        string const file_ = (type == "cls") ? file + ".cls" : file + ".sty";
+
        lyxerr << "Search for classfile " << file_ << endl;
-       string const lstfile = (type == "cls") ? "clsFiles.lst" : "styFiles.lst";
-       string const allClasses = GetFileContents(LibFileSearch(string(), lstfile));
+
+       string const lstfile =
+               ((type == "cls") ? "clsFiles.lst" : "styFiles.lst");
+       string const allClasses = GetFileContents(LibFileSearch(string(),
+                                                               lstfile));
        int entries = 0;
        string classfile = token(allClasses, '\n', entries);
        int count = 0;
-       while ((!contains(classfile, file) || 
+       while ((!contains(classfile, file) ||
                (OnlyFilename(classfile) != file)) &&
                (++count < 1000)) {
                classfile = token(allClasses, '\n', ++entries);
        }
+
        // now we have filename with full path
        lyxerr << "with full path: " << classfile << endl;
+
        return classfile;
 }