4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
16 /// remove directory and all contents, returns 0 on success
17 int destroyDir(string const & tmpdir);
20 string const CreateBufferTmpDir(string const & pathfor = string());
22 /// Creates directory. Returns true on success
23 bool createDirectory(string const & name, int permissions);
26 string const CreateLyXTmpDir(string const & deflt);
28 /** Find file by searching several directories.
29 Uses a string of paths separated by ";"s to find a file to open.
30 Can't cope with pathnames with a ';' in them. Returns full path to file.
31 If path entry begins with $$LyX/, use system_lyxdir.
32 If path entry begins with $$User/, use user_lyxdir.
33 Example: "$$User/doc;$$LyX/doc".
35 string const FileOpenSearch(string const & path, string const & name,
36 string const & ext = string());
38 /** Returns the real name of file name in directory path, with optional
40 The file is searched in the given path (unless it is an absolute
41 file name), first directly, and then with extension .ext (if given).
43 string const FileSearch(string const & path, string const & name,
44 string const & ext = string());
46 /// Returns a vector of all files in directory dir having extension ext.
47 std::vector<string> const DirList(string const & dir,
48 string const & ext = string());
50 /** Is directory read only?
55 bool IsDirWriteable (string const & path);
57 /** Is a file readable ?
58 Returns true if the file `path' is readable.
60 bool IsFileReadable (string const & path);
62 /** Is file read only?
66 -1: error (doesn't exist, no access, anything else)
68 int IsFileWriteable (string const & path);
71 bool IsLyXFilename(string const & filename);
74 bool IsSGMLFilename(string const & filename);
76 /** Returns the path of a library data file.
77 Search the file name.ext in the subdirectory dir of
80 \item build_lyxdir (if not empty)
83 The third parameter `ext' is optional.
85 string const LibFileSearch(string const & dir, string const & name,
86 string const & ext = string());
88 /** Same as LibFileSearch(), but tries first to find an
89 internationalized version of the file by prepending $LANG_ to the
93 i18nLibFileSearch(string const & dir, string const & name,
94 string const & ext = string());
96 /** Takes a command with arguments as input and tries to see whether
97 the command itself can be found in one of the scripts/ directories.
98 If it is found, return the command with fully qualified script name,
99 either return it unchanged */
100 string const LibScriptSearch(string const & command);
103 string const GetEnv(string const & envname);
105 /// A helper function.
106 string const GetEnvPath(string const & name);
108 /// Substitutes active latex characters with underscores in filename
109 string const MakeLatexName(string const & file);
111 /// Put the name in quotes suitable for the current shell
112 string const QuoteName(string const & file);
114 /// Add a filename to a path. Any path from filename is stripped first.
115 string const AddName(string const & path, string const & fname);
117 /// Append sub-directory(ies) to path in an intelligent way
118 string const AddPath(string const & path, string const & path2);
120 /** Change extension of oldname to extension.
121 If oldname does not have an extension, it is appended.
122 If the extension is empty, any extension is removed from the name.
125 ChangeExtension(string const & oldname, string const & extension);
127 /// Return the extension of the file (not including the .)
128 string const GetExtension(string const & name);
130 /// Return the type of the file as an extension from contents
131 string const getExtFromContents(string const & name);
133 /// check for zipped file
134 bool zippedFile(string const & name);
137 string const unzipFile(string const & zipped_file);
139 /// Returns true is path is absolute
140 bool AbsolutePath(string const & path);
142 /// Create absolute path. If impossible, don't do anything
143 string const ExpandPath(string const & path);
145 /** Convert relative path into absolute path based on a basepath.
146 If relpath is absolute, just use that.
147 If basepath doesn't exist use CWD.
149 string const MakeAbsPath(string const & RelPath = string(),
150 string const & BasePath = string());
152 /** Creates a nice compact path for displaying. The parameter
153 threshold, if given, specifies the maximal length of the path.
156 MakeDisplayPath(string const & path, unsigned int threshold = 1000);
158 /** Makes relative path out of absolute path.
159 If it is deeper than basepath,
160 it's easy. If basepath and abspath share something (they are all deeper
161 than some directory), it'll be rendered using ..'s. If they are completely
162 different, then the absolute path will be used as relative path
163 WARNING: the absolute path and base path must really be absolute paths!!!
166 MakeRelPath(string const & abspath, string const & basepath);
168 /// Strip filename from path name
169 string const OnlyPath(string const & fname);
171 /// Normalize a path. Constracts path/../path
172 string const NormalizePath(string const & path);
174 /// Strips path from filename
175 string const OnlyFilename(string const & fname);
177 /// Get the contents of a file as a huge string
178 string const GetFileContents(string const & fname);
180 /** Check and Replace Environmentvariables ${NAME} in Path.
181 Replaces all occurences of these, if they are found in the
183 Variables are defined by Var := '${' [a-zA-Z_][a-zA-Z_0-9]* '}'
185 string const ReplaceEnvironmentPath(string const & path);
187 /* Set \c link to the path \c file points to as a symbolic link.
188 If \c resolve is true, then \c link is an absolute path
189 Returns true if successful */
190 bool LyXReadLink(string const & file, string & link, bool resolve = false);
192 /// Uses kpsewhich to find tex files
193 string const findtexfile(string const & fil, string const & format);
195 /// remove the autosave-file and give a Message if it can't be done
196 void removeAutosaveFile(string const & filename);
198 /// read the BoundingBox entry from a ps/eps/pdf-file
199 string const readBB_from_PSFile(string const & file);
201 typedef std::pair<int, string> cmd_ret;
203 cmd_ret const RunCommand(string const & cmd);