]> git.lyx.org Git - lyx.git/blob - src/support/filetools.h
parselog fixes, i18n fix, menu separator fix
[lyx.git] / src / support / filetools.h
1 // -*- C++-*-
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
5 */
6
7 #ifndef LYX_FILETOOL_H
8 #define LYX_FILETOOL_H
9
10 #ifdef __GNUG__
11 #pragma interface
12 #endif
13
14 #include <vector>
15 #include "LString.h"
16
17
18 ///
19 string const CreateBufferTmpDir (string const & pathfor = string());
20
21 /// Creates directory. Returns true on succes.
22 bool createDirectory(string const & name, int permissions);
23
24 ///
25 string const CreateLyXTmpDir (string const & deflt);
26
27 ///
28 int DestroyBufferTmpDir (string const & tmpdir);
29
30 ///
31 int DestroyLyXTmpDir (string const & tmpdir);
32
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".
39 */
40 string const FileOpenSearch (string const & path, string const & name,
41                        string const & ext = string());
42
43 /** Returns the real name of file name in directory path, with optional
44   extension ext.
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).
47   */
48 string const FileSearch(string const & path, string const & name,
49                   string const & ext = string());
50
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());
54
55 /** Is directory read only?
56   returns
57     true: dir writeable
58     false: not writeable
59 */
60 bool IsDirWriteable (string const & path);
61
62 /** Is a file readable ?
63   Returns true if the file `path' is readable.
64  */
65 bool IsFileReadable (string const & path);
66
67 /** Is file read only?
68   returns
69     1: read-write
70     0: read_only
71    -1: error (doesn't exist, no access, anything else)
72   */
73 int IsFileWriteable (string const & path);
74
75 ///
76 bool IsLyXFilename(string const & filename);
77
78 ///
79 bool IsSGMLFilename(string const & filename);
80
81 /** Returns the path of a library data file.
82   Search the file name.ext in the subdirectory dir of
83   \begin{enumerate}
84     \item user_lyxdir
85     \item build_lyxdir (if not empty)
86     \item system_lyxdir
87   \end{enumerate}
88     The third parameter `ext' is optional.
89 */
90 string const LibFileSearch(string const & dir, string const & name,
91                      string const & ext = string());
92
93 /** Same as LibFileSearch(), but tries first to find an
94   internationalized version of the file by prepending $LANG_ to the
95   name
96   */
97 string const
98 i18nLibFileSearch(string const & dir, string const & name,
99                   string const & ext = string());
100
101 /** Takes a command with arguments as input and tries to see whether
102   the command itself can be found in one of the scripts/ directories.
103   If it is found, return the command with fully qualified script name,
104   either return it unchanged */
105 string const LibScriptSearch(string const & command);
106
107 ///
108 string const GetEnv(string const & envname);
109
110 /// A helper function.
111 string const GetEnvPath(string const & name);
112
113 ///
114 bool PutEnv(string const & envstr);
115
116 ///
117 bool PutEnvPath(string const & envstr);
118
119 /// Substitutes active latex characters with underscores in filename
120 string const MakeLatexName(string const & file);
121
122 /// Put the name in quotes suitable for the current shell
123 string const QuoteName(string const & file);
124
125 /// Add a filename to a path. Any path from filename is stripped first.
126 string const AddName(string const & path, string const & fname);
127
128 /// Append sub-directory(ies) to path in an intelligent way
129 string const AddPath(string const & path, string const & path2);
130
131 /** Change extension of oldname to extension.
132  If oldname does not have an extension, it is appended.
133  If the extension is empty, any extension is removed from the name.
134  */
135 string const
136 ChangeExtension(string const & oldname, string const & extension);
137
138 /// Return the extension of the file (not including the .)
139 string const GetExtension(string const & name);
140
141 /// Return the type of the file as an extension from contents
142 string const getExtFromContents(string const & name);
143
144 /// check for zipped file
145 bool zippedFile(string const & name);
146
147 /// unzip a file
148 string const unzipFile(string const & zipped_file);
149
150 /// Returns true is path is absolute
151 bool AbsolutePath(string const & path);
152
153 /// Create absolute path. If impossible, don't do anything
154 string const ExpandPath(string const & path);
155
156 /** Convert relative path into absolute path based on a basepath.
157   If relpath is absolute, just use that.
158   If basepath doesn't exist use CWD.
159   */
160 string const MakeAbsPath(string const & RelPath = string(),
161                          string const & BasePath = string());
162
163 /** Creates a nice compact path for displaying. The parameter
164   threshold, if given, specifies the maximal length of the path.
165   */
166 string const
167 MakeDisplayPath(string const & path,
168                 unsigned int threshold = 1000);
169
170 /** Makes relative path out of absolute path.
171   If it is deeper than basepath,
172   it's easy. If basepath and abspath share something (they are all deeper
173   than some directory), it'll be rendered using ..'s. If they are completely
174   different, then the absolute path will be used as relative path
175   WARNING: the absolute path and base path must really be absolute paths!!!
176   */
177 string const
178 MakeRelPath(string const & abspath, string const & basepath);
179
180 /// Strip filename from path name
181 string const OnlyPath(string const & fname);
182
183 /// Normalize a path. Constracts path/../path
184 string const NormalizePath(string const & path);
185
186 /// Strips path from filename
187 string const OnlyFilename(string const & fname);
188
189 /// Get the contents of a file as a huge string
190 string const GetFileContents(string const & fname);
191
192 /** Check and Replace Environmentvariables ${NAME} in Path.
193     Replaces all occurences of these, if they are found in the
194     environment.
195     Variables are defined by Var := '${' [a-zA-Z_][a-zA-Z_0-9]* '}'
196 */
197 string const ReplaceEnvironmentPath(string const & path);
198
199 /* Set Link to the path file points to as a symbolic link.
200    Returns true if successful */
201 bool LyXReadLink(string const & file, string & Link);
202
203 /// Uses kpsewhich to find tex files
204 string const findtexfile(string const & fil, string const & format);
205
206 /// remove the autosave-file and give a Message if it can't be done
207 void removeAutosaveFile(string const & filename);
208
209
210 #endif