2 /* lyx-filetool.h : tools functions for file/path handling
3 this file is part of LyX, the High Level Word Processor
4 Copyright 1995-2000, Matthias Ettrich and the LyX Team
22 #include "support/lstrings.h"
26 string const CreateBufferTmpDir (string const & pathfor = string());
28 /// Creates directory. Returns true on succes.
29 bool createDirectory(string const & name, int permissions);
32 string const CreateLyXTmpDir (string const & deflt);
35 int DestroyBufferTmpDir (string const & tmpdir);
38 int DestroyLyXTmpDir (string const & tmpdir);
40 /** Find file by searching several directories.
41 Uses a string of paths separated by ";"s to find a file to open.
42 Can't cope with pathnames with a ';' in them. Returns full path to file.
43 If path entry begins with $$LyX/, use system_lyxdir.
44 If path entry begins with $$User/, use user_lyxdir.
45 Example: "$$User/doc;$$LyX/doc".
47 string const FileOpenSearch (string const & path, string const & name,
48 string const & ext = string());
50 /** Returns the real name of file name in directory path, with optional
52 The file is searched in the given path (unless it is an absolute
53 file name), first directly, and then with extension .ext (if given).
55 string const FileSearch(string const & path, string const & name,
56 string const & ext = string());
58 /// Returns a vector of all files in directory dir having extension ext.
59 std::vector<string> const DirList(string const & dir,
60 string const & ext = string());
62 /** Is directory read only?
66 -1: error- couldn't find out, or unsure
68 int IsDirWriteable (string const & path);
70 /** Is a file readable ?
71 Returns true if the file `path' is readable.
73 bool IsFileReadable (string const & path);
75 /** Is file read only?
79 -1: error (doesn't exist, no access, anything else)
81 int IsFileWriteable (string const & path);
84 bool IsLyXFilename(string const & filename);
86 /** Returns the path of a library data file.
87 Search the file name.ext in the subdirectory dir of
90 \item build_lyxdir (if not empty)
93 The third parameter `ext' is optional.
95 string const LibFileSearch(string const & dir, string const & name,
96 string const & ext = string());
98 /** Same as LibFileSearch(), but tries first to find an
99 internationalized version of the file by prepending $LANG_ to the
103 i18nLibFileSearch(string const & dir, string const & name,
104 string const & ext = string());
107 string const GetEnv(string const & envname);
109 /// A helper function.
110 string const GetEnvPath(string const & name);
113 bool PutEnv(string const & envstr);
116 bool PutEnvPath(string const & envstr);
118 /// Substitutes active latex characters with underscores in filename
119 string const MakeLatexName(string const & file);
121 /// Put the name in quotes suitable for the current shell
122 string const QuoteName(string const & file);
125 /** Returns an unique name to be used as a temporary file. If given,
126 'mask' should the prefix to the temporary file, the rest of the
127 temporary filename will be made from the pid and three letters.
130 TmpFileName(string const & dir = string(),
131 string const & mask = "lyx_tmp");
134 /// Is a filename/path absolute?
135 bool AbsolutePath(string const & path);
137 /// Add a filename to a path. Any path from filename is stripped first.
138 string const AddName(string const & path, string const & fname);
140 /// Append sub-directory(ies) to path in an intelligent way
141 string const AddPath(string const & path, string const & path2);
143 /** Change extension of oldname to extension.
144 If oldname does not have an extension, it is appended.
145 If the extension is empty, any extension is removed from the name.
148 ChangeExtension(string const & oldname, string const & extension);
150 /// Return the extension of the file (not including the .)
151 string const GetExtension(string const & name);
153 /// Create absolute path. If impossible, don't do anything
154 string const ExpandPath(string const & path);
157 /// gets current working directory
158 string const GetCWD();
161 /** Convert relative path into absolute path based on a basepath.
162 If relpath is absolute, just use that.
163 If basepath doesn't exist use CWD.
165 string const MakeAbsPath(string const & RelPath = string(),
166 string const & BasePath = string());
168 /** Creates a nice compact path for displaying. The parameter
169 threshold, if given, specifies the maximal length of the path.
172 MakeDisplayPath(string const & path,
173 unsigned int threshold = 1000);
175 /** Makes relative path out of absolute path.
176 If it is deeper than basepath,
177 it's easy. If basepath and abspath share something (they are all deeper
178 than some directory), it'll be rendered using ..'s. If they are completely
179 different, then the absolute path will be used as relative path
180 WARNING: the absolute path and base path must really be absolute paths!!!
183 MakeRelPath(string const & abspath, string const & basepath);
185 /// Strip filename from path name
186 string const OnlyPath(string const & fname);
188 /// Normalize a path. Constracts path/../path
189 string const NormalizePath(string const & path);
191 /// Strips path from filename
192 string const OnlyFilename(string const & fname);
194 /// Get the contents of a file as a huge string
195 string const GetFileContents(string const & fname);
197 /// Cleanup a path if necessary. Currently only useful with OS/2
198 string const CleanupPath(string const & path);
200 /** Check and Replace Environmentvariables ${NAME} in Path.
201 Replaces all occurences of these, if they are found in the
203 Variables are defined by Var := '${' [a-zA-Z_][a-zA-Z_0-9]* '}'
205 string const ReplaceEnvironmentPath(string const & path);
207 /* Set Link to the path file points to as a symbolic link.
208 Returns true if successful */
209 bool LyXReadLink(string const & file, string & Link);
211 /* Uses kpsewhich to find tex files */
212 string const findtexfile(string const & fil, string const & format);
214 /* remove the autosave-file and give a Message if it can't be done */
215 void removeAutosaveFile(string const & filename);