#define LYX_FILETOOL_H
#include "support/docstring.h"
-#include "support/filename.h"
+#include "support/FileName.h"
#include <vector>
#include <utility>
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
*/
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.
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.
*/
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(FileName const & dir,
+std::vector<FileName> const dirList(FileName const & dir,
std::string const & ext = std::string());
/** Is directory read only?
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 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
/// 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);
Will overwrite an already existing unzipped file without warning.
*/
FileName const unzipFile(FileName const & zipped_file,
- std::string const & unzipped_file = std::string());
+ std::string const & unzipped_file = std::string());
/// Returns true is path is absolute
bool absolutePath(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
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);
*/
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
+/**
+ * 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);