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
20 #include "support/lstrings.h"
24 string CreateBufferTmpDir (string const & pathfor = string());
26 /// Creates directory. Returns true on succes.
27 bool createDirectory(string const & name, int permissions);
30 string CreateLyXTmpDir (string const & deflt);
33 int DestroyBufferTmpDir (string const & tmpdir);
36 int DestroyLyXTmpDir (string const & tmpdir);
38 /** Find file by searching several directories.
39 Uses a string of paths separated by ";"s to find a file to open.
40 Can't cope with pathnames with a ';' in them. Returns full path to file.
41 If path entry begins with $$LyX/, use system_lyxdir.
42 If path entry begins with $$User/, use user_lyxdir.
43 Example: "$$User/doc;$$LyX/doc".
45 string FileOpenSearch (string const & path, string const & name,
46 string const & ext = string());
48 /** Returns the real name of file name in directory path, with optional
50 The file is searched in the given path (unless it is an absolute
51 file name), first directly, and then with extension .ext (if given).
53 string FileSearch(string const & path, string const & name,
54 string const & ext = string());
56 /** Is directory read only?
60 -1: error- couldn't find out, or unsure
62 int IsDirWriteable (string const & path);
64 /** Is a file readable ?
65 Returns true if the file `path' is readable.
67 bool IsFileReadable (string const & path);
69 /** Is file read only?
73 -1: error (doesn't exist, no access, anything else)
75 int IsFileWriteable (string const & path);
78 bool IsLyXFilename(string const & filename);
80 /** Returns the path of a library data file.
81 Search the file name.ext in the subdirectory dir of
84 \item build_lyxdir (if not empty)
87 The third parameter `ext' is optional.
89 string LibFileSearch(string const & dir, string const & name,
90 string const & ext = string());
92 /** Same as LibFileSearch(), but tries first to find an
93 internationalized version of the file by prepending $LANG_ to the
96 string i18nLibFileSearch(string const & dir, string const & name,
97 string const & ext = string());
100 string GetEnv(string const & envname);
102 /// A helper function.
103 string GetEnvPath(string const & name);
106 bool PutEnv(string const & envstr);
109 bool PutEnvPath(string const & envstr);
111 /// Substitutes active latex characters with underscores in filename
112 string MakeLatexName(string const & file);
114 /// Put the name in quotes suitable for the current shell
115 string QuoteName(string const & file);
117 /** Returns an unique name to be used as a temporary file. If given,
118 'mask' should the prefix to the temporary file, the rest of the
119 temporary filename will be made from the pid and three letters.
121 string TmpFileName(string const & dir = string(),
122 string const & mask = "lyx_tmp");
124 /// Is a filename/path absolute?
125 bool AbsolutePath(string const & path);
127 /// Add a filename to a path. Any path from filename is stripped first.
128 string AddName(string const & path, string const & fname);
130 /// Append sub-directory(ies) to path in an intelligent way
131 string AddPath(string const & path, string const & path2);
133 /** Change extension of oldname to extension.
134 If no_path is true, the path is stripped from the filename.
135 If oldname does not have an extension, it is appended.
136 If the extension is empty, any extension is removed from the name.
138 string ChangeExtension(string const & oldname, string const & extension,
141 /// Create absolute path. If impossible, don't do anything
142 string ExpandPath(string const & path);
144 /// gets current working directory
148 /** Convert relative path into absolute path based on a basepath.
149 If relpath is absolute, just use that.
150 If basepath doesn't exist use CWD.
152 string MakeAbsPath(string const & RelPath = string(),
153 string const & BasePath = string());
155 /** Creates a nice compact path for displaying. The parameter
156 threshold, if given, specifies the maximal length of the path.
158 string MakeDisplayPath(string const & path, unsigned int threshold= 1000);
160 /** Makes relative path out of absolute path.
161 If it is deeper than basepath,
162 it's easy. If basepath and abspath share something (they are all deeper
163 than some directory), it'll be rendered using ..'s. If they are completely
164 different, then the absolute path will be used as relative path
165 WARNING: the absolute path and base path must really be absolute paths!!!
167 string MakeRelPath(string const & abspath, string const & basepath);
169 /// Strip filename from path name
170 string OnlyPath(string const & fname);
172 /// Normalize a path. Constracts path/../path
173 string NormalizePath(string const & path);
175 /// Strips path from filename
176 string OnlyFilename(string const & fname);
178 /// Cleanup a path if necessary. Currently only useful with OS/2
179 string CleanupPath(string const & path) ;
181 /** Check and Replace Environmentvariables ${NAME} in Path.
182 Replaces all occurences of these, if they are found in the
184 Variables are defined by Var := '${' [a-zA-Z_][a-zA-Z_0-9]* '}'
186 string ReplaceEnvironmentPath(string const & path);
188 /* Set Link to the path File Points to as a symbolic link.
189 Return True if succesfull, False other wise */
190 bool LyXReadLink(string const & file, string & Link);
192 /* Uses kpsewhich to find tex files */
193 string findtexfile(string const & fil, string const & format);