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);
127 /// Is a filename/path absolute?
128 bool AbsolutePath(string const & path);
130 /// Add a filename to a path. Any path from filename is stripped first.
131 string const AddName(string const & path, string const & fname);
133 /// Append sub-directory(ies) to path in an intelligent way
134 string const AddPath(string const & path, string const & path2);
136 /** Change extension of oldname to extension.
137 If oldname does not have an extension, it is appended.
138 If the extension is empty, any extension is removed from the name.
141 ChangeExtension(string const & oldname, string const & extension);
143 /// Return the extension of the file (not including the .)
144 string const GetExtension(string const & name);
146 /// Create absolute path. If impossible, don't do anything
147 string const ExpandPath(string const & path);
149 /** Convert relative path into absolute path based on a basepath.
150 If relpath is absolute, just use that.
151 If basepath doesn't exist use CWD.
153 string const MakeAbsPath(string const & RelPath = string(),
154 string const & BasePath = string());
156 /** Creates a nice compact path for displaying. The parameter
157 threshold, if given, specifies the maximal length of the path.
160 MakeDisplayPath(string const & path,
161 unsigned int threshold = 1000);
163 /** Makes relative path out of absolute path.
164 If it is deeper than basepath,
165 it's easy. If basepath and abspath share something (they are all deeper
166 than some directory), it'll be rendered using ..'s. If they are completely
167 different, then the absolute path will be used as relative path
168 WARNING: the absolute path and base path must really be absolute paths!!!
171 MakeRelPath(string const & abspath, string const & basepath);
173 /// Strip filename from path name
174 string const OnlyPath(string const & fname);
176 /// Normalize a path. Constracts path/../path
177 string const NormalizePath(string const & path);
179 /// Strips path from filename
180 string const OnlyFilename(string const & fname);
182 /// Strips filename from path
183 string const BasePath(string const & fname);
185 /// Get the contents of a file as a huge string
186 string const GetFileContents(string const & fname);
188 /// Cleanup a path if necessary. Currently only useful with OS/2
189 string const CleanupPath(string const & path);
191 /** Check and Replace Environmentvariables ${NAME} in Path.
192 Replaces all occurences of these, if they are found in the
194 Variables are defined by Var := '${' [a-zA-Z_][a-zA-Z_0-9]* '}'
196 string const ReplaceEnvironmentPath(string const & path);
198 /* Set Link to the path file points to as a symbolic link.
199 Returns true if successful */
200 bool LyXReadLink(string const & file, string & Link);
202 /// Uses kpsewhich to find tex files
203 string const findtexfile(string const & fil, string const & format);
205 /// remove the autosave-file and give a Message if it can't be done
206 void removeAutosaveFile(string const & filename);