#ifndef LYX_FILETOOL_H
#define LYX_FILETOOL_H
+#include "support/docstring.h"
+#include "support/filename.h"
+
#include <vector>
#include <utility>
#include <string>
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.
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());
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());
/** 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);
-# 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());
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());
+/// 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,
/// 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);
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.
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);
/** 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.
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
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,
* 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;