]> git.lyx.org Git - lyx.git/blob - src/support/filetools.h
fix lyxalgo.h, dra pagebreak with text on line, change the math_deco_search a bit
[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-1999, 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 <cstdlib>
15 #include <fcntl.h>
16 #include <cerrno>
17
18 #include "debug.h"
19 #include "LString.h"
20 #include "support/lstrings.h"
21
22
23 ///
24 string CreateBufferTmpDir (string const & pathfor = string());
25
26 /// Creates directory. Returns true on succes.
27 bool createDirectory(string const & name, int permissions);
28
29 ///
30 string CreateLyXTmpDir (string const & deflt);
31
32 ///
33 int DestroyBufferTmpDir (string const & tmpdir);
34
35 ///
36 int DestroyLyXTmpDir (string const & tmpdir);
37
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".
44 */
45 string FileOpenSearch (string const & path, string const & name, 
46                        string const & ext = string());
47
48 /** Returns the real name of file name in directory path, with optional
49   extension ext.
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).
52   */
53 string FileSearch(string const & path, string const & name, 
54                   string const & ext = string());
55
56 /** Is directory read only?
57   returns 
58     1: dir writeable
59     0: not writeable
60    -1: error- couldn't find out, or unsure
61   */
62 int IsDirWriteable (string const & path);
63
64 /** Is a file readable ?
65   Returns true if the file `path' is readable.
66  */
67 bool IsFileReadable (string const & path);
68
69 /** Is file read only?
70   returns
71     1: read-write
72     0: read_only
73    -1: error (doesn't exist, no access, anything else)
74   */
75 int IsFileWriteable (string const & path);
76
77 ///
78 bool IsLyXFilename(string const & filename);
79
80 ///
81 bool IsSGMLFilename(string const & filename);
82
83 /** Returns the path of a library data file.
84   Search the file name.ext in the subdirectory dir of
85   \begin{enumerate}
86     \item user_lyxdir
87     \item build_lyxdir (if not empty)
88     \item system_lyxdir
89   \end{enumerate}
90     The third parameter `ext' is optional.
91 */
92 string LibFileSearch(string const & dir, string const & name, 
93                      string const & ext = string());
94
95 /** Same as LibFileSearch(), but tries first to find an
96   internationalized version of the file by prepending $LANG_ to the
97   name 
98   */
99 string i18nLibFileSearch(string const & dir, string const & name, 
100                          string const & ext = string());
101
102 ///
103 string GetEnv(string const & envname);
104
105 /// A helper function.
106 string GetEnvPath(string const & name);
107
108 ///
109 bool PutEnv(string const & envstr);
110
111 ///
112 bool PutEnvPath(string const & envstr);
113
114 /// Substitutes active latex characters with underscores in filename
115 string MakeLatexName(string const & file);
116
117 /// Put the name in quotes suitable for the current shell
118 string QuoteName(string const & file);
119
120 /** Returns an unique name to be used as a temporary file. If given,
121   'mask' should the prefix to the temporary file, the rest of the
122   temporary filename will be made from the pid and three letters.
123   */
124 string TmpFileName(string const & dir = string(), 
125                    string const & mask = "lyx_tmp");
126
127 /// Is a filename/path absolute?
128 bool AbsolutePath(string const & path);
129
130 /// Add a filename to a path. Any path from filename is stripped first.
131 string AddName(string const & path, string const & fname);
132
133 /// Append sub-directory(ies) to path in an intelligent way
134 string AddPath(string const & path, string const & path2);
135
136 /** Change extension of oldname to extension.
137  If no_path is true, the path is stripped from the filename.
138  If oldname does not have an extension, it is appended.
139  If the extension is empty, any extension is removed from the name.
140  */
141 string ChangeExtension(string const & oldname, string const & extension, 
142                        bool no_path);
143
144 /// Create absolute path. If impossible, don't do anything
145 string ExpandPath(string const & path);
146
147 /// gets current working directory
148 string GetCWD();
149
150
151 /** Convert relative path into absolute path based on a basepath.
152   If relpath is absolute, just use that.
153   If basepath doesn't exist use CWD.
154   */
155 string MakeAbsPath(string const & RelPath = string(), 
156                    string const & BasePath = string());
157
158 /** Creates a nice compact path for displaying. The parameter
159   threshold, if given, specifies the maximal length of the path.
160   */
161 string MakeDisplayPath(string const & path, unsigned int threshold= 1000);
162
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!!!
169   */
170 string MakeRelPath(string const & abspath, string const & basepath);
171
172 /// Strip filename from path name
173 string OnlyPath(string const & fname);
174
175 /// Normalize a path. Constracts path/../path
176 string NormalizePath(string const & path);
177
178 /// Strips path from filename
179 string OnlyFilename(string const & fname);
180
181 /// Cleanup a path if necessary. Currently only useful with OS/2
182 string CleanupPath(string const & path) ;
183
184 /** Check and Replace Environmentvariables ${NAME} in Path.
185     Replaces all occurences of these, if they are found in the
186     environment.
187     Variables are defined by Var := '${' [a-zA-Z_][a-zA-Z_0-9]* '}'
188 */
189 string ReplaceEnvironmentPath(string const & path);
190
191 /* Set Link to the path File Points to as a symbolic link.
192    Return True if succesfull, False other wise */
193 bool LyXReadLink(string const & file, string & Link);
194
195 /* Uses kpsewhich to find tex files */
196 string findtexfile(string const & fil, string const & format);
197
198 #endif