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-2001, Matthias Ettrich and the LyX Team
19 string const CreateBufferTmpDir (string const & pathfor = string());
21 /// Creates directory. Returns true on succes.
22 bool createDirectory(string const & name, int permissions);
25 string const CreateLyXTmpDir (string const & deflt);
28 int DestroyBufferTmpDir (string const & tmpdir);
31 int DestroyLyXTmpDir (string const & tmpdir);
33 /** Find file by searching several directories.
34 Uses a string of paths separated by ";"s to find a file to open.
35 Can't cope with pathnames with a ';' in them. Returns full path to file.
36 If path entry begins with $$LyX/, use system_lyxdir.
37 If path entry begins with $$User/, use user_lyxdir.
38 Example: "$$User/doc;$$LyX/doc".
40 string const FileOpenSearch (string const & path, string const & name,
41 string const & ext = string());
43 /** Returns the real name of file name in directory path, with optional
45 The file is searched in the given path (unless it is an absolute
46 file name), first directly, and then with extension .ext (if given).
48 string const FileSearch(string const & path, string const & name,
49 string const & ext = string());
51 /// Returns a vector of all files in directory dir having extension ext.
52 std::vector<string> const DirList(string const & dir,
53 string const & ext = string());
55 /** Is directory read only?
60 bool IsDirWriteable (string const & path);
62 /** Is a file readable ?
63 Returns true if the file `path' is readable.
65 bool IsFileReadable (string const & path);
67 /** Is file read only?
71 -1: error (doesn't exist, no access, anything else)
73 int IsFileWriteable (string const & path);
76 bool IsLyXFilename(string const & filename);
79 bool IsSGMLFilename(string const & filename);
81 /** Returns the path of a library data file.
82 Search the file name.ext in the subdirectory dir of
85 \item build_lyxdir (if not empty)
88 The third parameter `ext' is optional.
90 string const LibFileSearch(string const & dir, string const & name,
91 string const & ext = string());
93 /** Same as LibFileSearch(), but tries first to find an
94 internationalized version of the file by prepending $LANG_ to the
98 i18nLibFileSearch(string const & dir, string const & name,
99 string const & ext = string());
102 string const GetEnv(string const & envname);
104 /// A helper function.
105 string const GetEnvPath(string const & name);
108 bool PutEnv(string const & envstr);
111 bool PutEnvPath(string const & envstr);
113 /// Substitutes active latex characters with underscores in filename
114 string const MakeLatexName(string const & file);
116 /// Put the name in quotes suitable for the current shell
117 string const QuoteName(string const & file);
119 /// Add a filename to a path. Any path from filename is stripped first.
120 string const AddName(string const & path, string const & fname);
122 /// Append sub-directory(ies) to path in an intelligent way
123 string const AddPath(string const & path, string const & path2);
125 /** Change extension of oldname to extension.
126 If oldname does not have an extension, it is appended.
127 If the extension is empty, any extension is removed from the name.
130 ChangeExtension(string const & oldname, string const & extension);
132 /// Return the extension of the file (not including the .)
133 string const GetExtension(string const & name);
135 /// Returns true is path is absolute
136 bool AbsolutePath(string const & path);
138 /// Create absolute path. If impossible, don't do anything
139 string const ExpandPath(string const & path);
141 /** Convert relative path into absolute path based on a basepath.
142 If relpath is absolute, just use that.
143 If basepath doesn't exist use CWD.
145 string const MakeAbsPath(string const & RelPath = string(),
146 string const & BasePath = string());
148 /** Creates a nice compact path for displaying. The parameter
149 threshold, if given, specifies the maximal length of the path.
152 MakeDisplayPath(string const & path,
153 unsigned int threshold = 1000);
155 /** Makes relative path out of absolute path.
156 If it is deeper than basepath,
157 it's easy. If basepath and abspath share something (they are all deeper
158 than some directory), it'll be rendered using ..'s. If they are completely
159 different, then the absolute path will be used as relative path
160 WARNING: the absolute path and base path must really be absolute paths!!!
163 MakeRelPath(string const & abspath, string const & basepath);
165 /// Strip filename from path name
166 string const OnlyPath(string const & fname);
168 /// Normalize a path. Constracts path/../path
169 string const NormalizePath(string const & path);
171 /// Strips path from filename
172 string const OnlyFilename(string const & fname);
174 /// Get the contents of a file as a huge string
175 string const GetFileContents(string const & fname);
177 /** Check and Replace Environmentvariables ${NAME} in Path.
178 Replaces all occurences of these, if they are found in the
180 Variables are defined by Var := '${' [a-zA-Z_][a-zA-Z_0-9]* '}'
182 string const ReplaceEnvironmentPath(string const & path);
184 /* Set Link to the path file points to as a symbolic link.
185 Returns true if successful */
186 bool LyXReadLink(string const & file, string & Link);
188 /// Uses kpsewhich to find tex files
189 string const findtexfile(string const & fil, string const & format);
191 /// remove the autosave-file and give a Message if it can't be done
192 void removeAutosaveFile(string const & filename);