]> git.lyx.org Git - lyx.git/blobdiff - src/support/filetools.h
remove lyxrc dependence from support/*
[lyx.git] / src / support / filetools.h
index 9c550cb18262b2271b430382620938ffd53f6848..6d717a58c66783794d9fe45b66f36377c4713fdc 100644 (file)
@@ -13,6 +13,7 @@
 #define LYX_FILETOOL_H
 
 #include "support/docstring.h"
+#include "support/FileName.h"
 
 #include <vector>
 #include <utility>
@@ -22,13 +23,13 @@ namespace lyx {
 namespace support {
 
 /// remove directory and all contents, returns true on success
-bool destroyDir(std::string const & tmpdir);
+bool destroyDir(FileName const & tmpdir);
 
 /// Creates the per buffer temporary directory
 std::string const createBufferTmpDir();
 
 /// Creates directory. Returns true on success
-bool createDirectory(std::string const & name, int permissions);
+bool createDirectory(FileName const & name, int permissions);
 
 /** Creates the global LyX temp dir.
   \p deflt can be an existing directory name. In this case a new directory
@@ -36,8 +37,10 @@ bool createDirectory(std::string const & name, int permissions);
   created and used as the temporary directory.
   \return the tmp dir name or string() if something went wrong.
  */
-std::string const createLyXTmpDir(std::string const & deflt);
+FileName const createLyXTmpDir(FileName const & deflt);
 
+#if 0
+// FIXME unused. Should this be deleted or resurrected?
 /** Find file by searching several directories.
   Uses a string of paths separated by ";"s to find a file to open.
     Can't cope with pathnames with a ';' in them. Returns full path to file.
@@ -45,21 +48,32 @@ std::string const createLyXTmpDir(std::string const & deflt);
     If path entry begins with $$User/, use user_lyxdir.
     Example: "$$User/doc;$$LyX/doc".
 */
-std::string const fileOpenSearch(std::string const & path,
+FileName const fileOpenSearch(std::string const & path,
                                 std::string const & name,
                                 std::string const & ext = std::string());
+#endif
+
+/// How to search files
+enum search_mode {
+       // The file must exist (return an empty file name otherwise)
+       standard_mode,
+       /// Only do file name expansion, return the complete name even if
+       /// the file does not exist
+       allow_unreadable
+};
 
 /** Returns the real name of file name in directory path, with optional
   extension ext.
   The file is searched in the given path (unless it is an absolute
   file name), first directly, and then with extension .ext (if given).
   */
-std::string const fileSearch(std::string const & path,
+FileName const fileSearch(std::string const & path,
                             std::string const & name,
-                            std::string const & ext = std::string());
+                            std::string const & ext = std::string(),
+                            search_mode mode = standard_mode);
 
 /// Returns a vector of all files in directory dir having extension ext.
-std::vector<std::string> const dirList(std::string const & dir,
+std::vector<FileName> const dirList(FileName const & dir,
                                       std::string const & ext = std::string());
 
 /** Is directory read only?
@@ -67,12 +81,12 @@ std::vector<std::string> const dirList(std::string const & dir,
     true: dir writeable
     false: not writeable
 */
-bool isDirWriteable(std::string const & path);
+bool isDirWriteable(FileName const & path);
 
 /** Is a file readable ?
   Returns true if the file `path' is readable.
  */
-bool isFileReadable (std::string const & path);
+bool isFileReadable(FileName const & path);
 
 ///
 bool isLyXFilename(std::string const & filename);
@@ -80,6 +94,9 @@ bool isLyXFilename(std::string const & filename);
 ///
 bool isSGMLFilename(std::string const & filename);
 
+///
+bool isValidLaTeXFilename(std::string const & filename);
+
 /** Returns the path of a library data file.
     Search the file name.ext in the subdirectory dir of
       -# user_lyxdir
@@ -87,7 +104,7 @@ bool isSGMLFilename(std::string const & filename);
       -# system_lyxdir
     The third parameter `ext' is optional.
 */
-std::string const libFileSearch(std::string const & dir,
+FileName const libFileSearch(std::string const & dir,
                                std::string const & name,
                                std::string const & ext = std::string());
 
@@ -95,7 +112,7 @@ std::string const libFileSearch(std::string const & dir,
   internationalized version of the file by prepending $LANG_ to the
   name
   */
-std::string const
+FileName const
 i18nLibFileSearch(std::string const & dir,
                  std::string const & name,
                  std::string const & ext = std::string());
@@ -179,6 +196,14 @@ changeExtension(std::string const & oldname, std::string const & extension);
 /// Remove the extension from \p name
 std::string const removeExtension(std::string const & name);
 
+/** Add the extension \p ext to \p name.
+ Use this instead of changeExtension if you know that \p name is without
+ extension, because changeExtension would wrongly interpret \p name if it
+ contains a dot.
+ */
+std::string const
+addExtension(std::string const & name, std::string const & extension);
+
 /// Return the extension of the file (not including the .)
 std::string const getExtension(std::string const & name);
 
@@ -186,10 +211,10 @@ std::string const getExtension(std::string const & name);
  Normally you don't want to use this directly, but rather
  Formats::getFormatFromFile().
  */
-std::string const getFormatFromContents(std::string const & name);
+std::string const getFormatFromContents(FileName const & name);
 
 /// check for zipped file
-bool zippedFile(std::string const & name);
+bool zippedFile(FileName const & name);
 
 /** \return the name that LyX will give to the unzipped file \p zipped_file
   if the second argument of unzipFile() is empty.
@@ -201,8 +226,8 @@ std::string const unzippedFileName(std::string const & zipped_file);
   empty, and unzippedFileName(\p zipped_file) otherwise.
   Will overwrite an already existing unzipped file without warning.
  */
-std::string const unzipFile(std::string const & zipped_file,
-                           std::string const & unzipped_file = std::string());
+FileName const unzipFile(FileName const & zipped_file,
+                        std::string const & unzipped_file = std::string());
 
 /// Returns true is path is absolute
 bool absolutePath(std::string const & path);
@@ -214,7 +239,7 @@ std::string const expandPath(std::string const & path);
   If relpath is absolute, just use that.
   If basepath doesn't exist use CWD.
   */
-std::string const makeAbsPath(std::string const & RelPath = std::string(),
+FileName const makeAbsPath(std::string const & RelPath = std::string(),
                              std::string const & BasePath = std::string());
 
 /** Creates a nice compact path for displaying. The parameter
@@ -230,8 +255,8 @@ makeDisplayPath(std::string const & path, unsigned int threshold = 1000);
   different, then the absolute path will be used as relative path
   WARNING: the absolute path and base path must really be absolute paths!!!
   */
-std::string const
-makeRelPath(std::string const & abspath, std::string const & basepath);
+docstring const
+makeRelPath(docstring const & abspath, docstring const & basepath);
 
 /// Strip filename from path name
 std::string const onlyPath(std::string const & fname);
@@ -245,7 +270,7 @@ std::string const normalizePath(std::string const & path);
 std::string const onlyFilename(std::string const & fname);
 
 /// Get the contents of a file as a huge std::string
-std::string const getFileContents(std::string const & fname);
+std::string const getFileContents(FileName const & fname);
 
 /** Check and Replace Environmentvariables ${NAME} in Path.
     Replaces all occurences of these, if they are found in the
@@ -254,22 +279,27 @@ std::string const getFileContents(std::string const & fname);
 */
 std::string const replaceEnvironmentPath(std::string const & path);
 
-/* Set \c link to the path \c file points to as a symbolic link.
-   If \c resolve is true, then \c link is an absolute path
-   Returns true if successful */
-bool readLink(std::string const & file,
-             std::string & link,
-             bool resolve = false);
+/** Set \c link to the path \c file points to as a symbolic link.
+    \return true if successful.
+ */
+bool readLink(FileName const & file, FileName & link);
 
-/// Uses kpsewhich to find tex files
-std::string const findtexfile(std::string const & fil,
+/**
+ * Search a TeX file in all locations the latex compiler would search it,
+ * with the help of kpsewhich.
+ * The current working directory must be set correctly, so that relative
+ * names work.
+ * \param fil The filename to search
+ * \param format The file format as used by kpsewhich, e.g. "bib", "bst" etc.
+ */
+FileName const findtexfile(std::string const & fil,
                              std::string const & format);
 
 /// remove the autosave-file and give a Message if it can't be done
 void removeAutosaveFile(std::string const & filename);
 
 /// read the BoundingBox entry from a ps/eps/pdf-file
-std::string const readBB_from_PSFile(std::string const & file);
+std::string const readBB_from_PSFile(FileName const & file);
 
 /** \param file1, file2 the two files to be compared. Must have absolute paths.
  *  \returns 1 if \c file1 has a more recent timestamp than \c file2,
@@ -278,7 +308,7 @@ std::string const readBB_from_PSFile(std::string const & file);
  *  If one of the files does not exist, the return value indicates the file
  *  which does exist. Eg, if \c file1 exists but \c file2 does not, return 1.
  */
-int compare_timestamps(std::string const & file1, std::string const & file2);
+int compare_timestamps(FileName const & file1, FileName const & file2);
 
 typedef std::pair<int, std::string> cmd_ret;