]> git.lyx.org Git - lyx.git/blobdiff - src/support/filetools.h
more unicode filenames
[lyx.git] / src / support / filetools.h
index 7820a01dbe9e1b5a5e241cbd255e785be6887c0a..d6bf08897c95b5149c2332fba26efdca855c7894 100644 (file)
@@ -12,6 +12,9 @@
 #ifndef LYX_FILETOOL_H
 #define LYX_FILETOOL_H
 
+#include "support/docstring.h"
+#include "support/filename.h"
+
 #include <vector>
 #include <utility>
 #include <string>
@@ -34,7 +37,7 @@ 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);
 
 /** Find file by searching several directories.
   Uses a string of paths separated by ";"s to find a file to open.
@@ -43,7 +46,7 @@ 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());
 
@@ -52,7 +55,7 @@ std::string const fileOpenSearch(std::string const & path,
   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());
 
@@ -70,7 +73,7 @@ bool isDirWriteable(std::string 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);
@@ -85,7 +88,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());
 
@@ -93,18 +96,33 @@ 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());
 
-/** Takes a command such as "sh $$s/scripts/convertDefault.sh file.in file.out"
+/// How to quote a filename
+enum quote_style {
+       /** Quote for the (OS dependant) shell. This is needed for command
+           line arguments of subprocesses. */
+       quote_shell,
+       /** Quote for python. Use this if you want to store a filename in a
+           python script. Example: \code
+           os << "infile = " << quoteName(filename) << '\\n';
+           \endcode This uses double quotes, so that you can also use this
+           to quote filenames as part of a string if the string is quoted
+           with single quotes. */
+       quote_python
+};
+
+/** Takes a command such as "python $$s/scripts/convertDefault.py file.in file.out"
  *  and replaces "$$s/" with the path to the LyX support directory containing
  *  this script. If the script is not found, "$$s/" is removed. Executing the
  *  command will still fail, but the error message will make some sort of
  *  sense ;-)
  */
-std::string const libScriptSearch(std::string const & command);
+std::string const libScriptSearch(std::string const & command,
+               quote_style style = quote_shell);
 
 enum latex_path_extension {
        PROTECT_EXTENSION,
@@ -142,8 +160,9 @@ std::string const latex_path(std::string const & path,
 /// Substitutes active latex characters with underscores in filename
 std::string const makeLatexName(std::string const & file);
 
-/// Put the name in quotes suitable for the current shell
-std::string const quoteName(std::string const & file);
+/** Put the name in quotes suitable for the current shell or python,
+    depending on \p style. */
+std::string const quoteName(std::string const & file, quote_style style = quote_shell);
 
 /// Add a filename to a path. Any path from filename is stripped first.
 std::string const addName(std::string const & path, std::string const & fname);
@@ -168,10 +187,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.
@@ -183,8 +202,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);
@@ -202,7 +221,7 @@ std::string const makeAbsPath(std::string const & RelPath = std::string(),
 /** Creates a nice compact path for displaying. The parameter
   threshold, if given, specifies the maximal length of the path.
   */
-std::string const
+docstring const
 makeDisplayPath(std::string const & path, unsigned int threshold = 1000);
 
 /** Makes relative path out of absolute path.
@@ -227,7 +246,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
@@ -244,14 +263,14 @@ bool readLink(std::string const & file,
              bool resolve = false);
 
 /// Uses kpsewhich to find tex files
-std::string const findtexfile(std::string const & fil,
+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,
@@ -260,7 +279,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;