4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
17 /// remove directory and all contents, returns 0 on success
18 int destroyDir(string const & tmpdir);
21 string const CreateBufferTmpDir(string const & pathfor = string());
23 /// Creates directory. Returns true on success
24 bool createDirectory(string const & name, int permissions);
27 string const CreateLyXTmpDir(string const & deflt);
29 /** Find file by searching several directories.
30 Uses a string of paths separated by ";"s to find a file to open.
31 Can't cope with pathnames with a ';' in them. Returns full path to file.
32 If path entry begins with $$LyX/, use system_lyxdir.
33 If path entry begins with $$User/, use user_lyxdir.
34 Example: "$$User/doc;$$LyX/doc".
36 string const FileOpenSearch(string const & path, string const & name,
37 string const & ext = string());
39 /** Returns the real name of file name in directory path, with optional
41 The file is searched in the given path (unless it is an absolute
42 file name), first directly, and then with extension .ext (if given).
44 string const FileSearch(string const & path, string const & name,
45 string const & ext = string());
47 /// Returns a vector of all files in directory dir having extension ext.
48 std::vector<string> const DirList(string const & dir,
49 string const & ext = string());
51 /** Is directory read only?
56 bool IsDirWriteable (string const & path);
58 /** Is a file readable ?
59 Returns true if the file `path' is readable.
61 bool IsFileReadable (string const & path);
63 /** Is file read only?
67 -1: error (doesn't exist, no access, anything else)
69 int IsFileWriteable (string const & path);
72 bool IsLyXFilename(string const & filename);
75 bool IsSGMLFilename(string const & filename);
77 /** Returns the path of a library data file.
78 Search the file name.ext in the subdirectory dir of
81 \item build_lyxdir (if not empty)
84 The third parameter `ext' is optional.
86 string const LibFileSearch(string const & dir, string const & name,
87 string const & ext = string());
89 /** Same as LibFileSearch(), but tries first to find an
90 internationalized version of the file by prepending $LANG_ to the
94 i18nLibFileSearch(string const & dir, string const & name,
95 string const & ext = string());
97 /** Takes a command such as "sh $$s/convertDefault.sh file.in file.out"
98 * and replaces "$$s/" with the path to the "most important" of LyX's
99 * script directories containing this script. If the script is not found,
100 * "$$s/" is removed. Executing the command will still fail, but the
101 * error message will make some sort of sense ;-)
103 string const LibScriptSearch(string const & command);
106 string const GetEnv(string const & envname);
108 /// A helper function.
109 string const GetEnvPath(string const & name);
111 /// Substitutes active latex characters with underscores in filename
112 string const MakeLatexName(string const & file);
114 /// Put the name in quotes suitable for the current shell
115 string const QuoteName(string const & file);
117 /// Add a filename to a path. Any path from filename is stripped first.
118 string const AddName(string const & path, string const & fname);
120 /// Append sub-directory(ies) to path in an intelligent way
121 string const AddPath(string const & path, string const & path2);
123 /** Change extension of oldname to extension.
124 If oldname does not have an extension, it is appended.
125 If the extension is empty, any extension is removed from the name.
128 ChangeExtension(string const & oldname, string const & extension);
130 /// Return the extension of the file (not including the .)
131 string const GetExtension(string const & name);
133 /// Return the type of the file as an extension from contents
134 string const getExtFromContents(string const & name);
136 /// check for zipped file
137 bool zippedFile(string const & name);
140 string const unzipFile(string const & zipped_file);
142 /// Returns true is path is absolute
143 bool AbsolutePath(string const & path);
145 /// Create absolute path. If impossible, don't do anything
146 string const ExpandPath(string const & path);
148 /** Convert relative path into absolute path based on a basepath.
149 If relpath is absolute, just use that.
150 If basepath doesn't exist use CWD.
152 string const MakeAbsPath(string const & RelPath = string(),
153 string const & BasePath = string());
155 /** Creates a nice compact path for displaying. The parameter
156 threshold, if given, specifies the maximal length of the path.
159 MakeDisplayPath(string const & path, unsigned int threshold = 1000);
161 /** Makes relative path out of absolute path.
162 If it is deeper than basepath,
163 it's easy. If basepath and abspath share something (they are all deeper
164 than some directory), it'll be rendered using ..'s. If they are completely
165 different, then the absolute path will be used as relative path
166 WARNING: the absolute path and base path must really be absolute paths!!!
169 MakeRelPath(string const & abspath, string const & basepath);
171 /// Strip filename from path name
172 string const OnlyPath(string const & fname);
174 /// Normalize a path. Constracts path/../path
175 string const NormalizePath(string const & path);
177 /// Strips path from filename
178 string const OnlyFilename(string const & fname);
180 /// Get the contents of a file as a huge string
181 string const GetFileContents(string const & fname);
183 /** Check and Replace Environmentvariables ${NAME} in Path.
184 Replaces all occurences of these, if they are found in the
186 Variables are defined by Var := '${' [a-zA-Z_][a-zA-Z_0-9]* '}'
188 string const ReplaceEnvironmentPath(string const & path);
190 /* Set \c link to the path \c file points to as a symbolic link.
191 If \c resolve is true, then \c link is an absolute path
192 Returns true if successful */
193 bool LyXReadLink(string const & file, string & link, bool resolve = false);
195 /// Uses kpsewhich to find tex files
196 string const findtexfile(string const & fil, string const & format);
198 /// remove the autosave-file and give a Message if it can't be done
199 void removeAutosaveFile(string const & filename);
201 /// read the BoundingBox entry from a ps/eps/pdf-file
202 string const readBB_from_PSFile(string const & file);
204 /** Copy \param file to directory \param path. The file name is manipulated
205 so that eg some/path/to/file becomes some_path_to_file.
206 \returns this file name if the file is copied successfully, else
207 \returns an empty string.
209 string copyFileToDir(string const & path, string const & file);
211 typedef std::pair<int, string> cmd_ret;
213 cmd_ret const RunCommand(string const & cmd);