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);
87 bool IsSGMLFilename(string const & filename);
89 /** Returns the path of a library data file.
90 Search the file name.ext in the subdirectory dir of
93 \item build_lyxdir (if not empty)
96 The third parameter `ext' is optional.
98 string const LibFileSearch(string const & dir, string const & name,
99 string const & ext = string());
101 /** Same as LibFileSearch(), but tries first to find an
102 internationalized version of the file by prepending $LANG_ to the
106 i18nLibFileSearch(string const & dir, string const & name,
107 string const & ext = string());
110 string const GetEnv(string const & envname);
112 /// A helper function.
113 string const GetEnvPath(string const & name);
116 bool PutEnv(string const & envstr);
119 bool PutEnvPath(string const & envstr);
121 /// Substitutes active latex characters with underscores in filename
122 string const MakeLatexName(string const & file);
124 /// Put the name in quotes suitable for the current shell
125 string const QuoteName(string const & file);
128 /** Returns an unique name to be used as a temporary file. If given,
129 'mask' should the prefix to the temporary file, the rest of the
130 temporary filename will be made from the pid and three letters.
133 TmpFileName(string const & dir = string(),
134 string const & mask = "lyx_tmp");
137 /// Is a filename/path absolute?
138 bool AbsolutePath(string const & path);
140 /// Add a filename to a path. Any path from filename is stripped first.
141 string const AddName(string const & path, string const & fname);
143 /// Append sub-directory(ies) to path in an intelligent way
144 string const AddPath(string const & path, string const & path2);
146 /** Change extension of oldname to extension.
147 If oldname does not have an extension, it is appended.
148 If the extension is empty, any extension is removed from the name.
151 ChangeExtension(string const & oldname, string const & extension);
153 /// Return the extension of the file (not including the .)
154 string const GetExtension(string const & name);
156 /// Create absolute path. If impossible, don't do anything
157 string const ExpandPath(string const & path);
160 /// gets current working directory
161 string const GetCWD();
164 /** Convert relative path into absolute path based on a basepath.
165 If relpath is absolute, just use that.
166 If basepath doesn't exist use CWD.
168 string const MakeAbsPath(string const & RelPath = string(),
169 string const & BasePath = string());
171 /** Creates a nice compact path for displaying. The parameter
172 threshold, if given, specifies the maximal length of the path.
175 MakeDisplayPath(string const & path,
176 unsigned int threshold = 1000);
178 /** Makes relative path out of absolute path.
179 If it is deeper than basepath,
180 it's easy. If basepath and abspath share something (they are all deeper
181 than some directory), it'll be rendered using ..'s. If they are completely
182 different, then the absolute path will be used as relative path
183 WARNING: the absolute path and base path must really be absolute paths!!!
186 MakeRelPath(string const & abspath, string const & basepath);
188 /// Strip filename from path name
189 string const OnlyPath(string const & fname);
191 /// Normalize a path. Constracts path/../path
192 string const NormalizePath(string const & path);
194 /// Strips path from filename
195 string const OnlyFilename(string const & fname);
197 /// Strips filename from path
198 string const BasePath(string const & fname);
200 /// Get the contents of a file as a huge string
201 string const GetFileContents(string const & fname);
203 /// Cleanup a path if necessary. Currently only useful with OS/2
204 string const CleanupPath(string const & path);
206 /** Check and Replace Environmentvariables ${NAME} in Path.
207 Replaces all occurences of these, if they are found in the
209 Variables are defined by Var := '${' [a-zA-Z_][a-zA-Z_0-9]* '}'
211 string const ReplaceEnvironmentPath(string const & path);
213 /* Set Link to the path file points to as a symbolic link.
214 Returns true if successful */
215 bool LyXReadLink(string const & file, string & Link);
217 /* Uses kpsewhich to find tex files */
218 string const findtexfile(string const & fil, string const & format);
220 /* remove the autosave-file and give a Message if it can't be done */
221 void removeAutosaveFile(string const & filename);