]>
Commit | Line | Data |
---|---|---|
c801d85f KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: filefn.h | |
3 | // Purpose: File- and directory-related functions | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 29/01/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) 1998 Julian Smart | |
45ea509a | 9 | // Licence: wxWindows license |
c801d85f KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifndef __FILEFNH__ | |
13 | #define __FILEFNH__ | |
14 | ||
15 | #ifdef __GNUG__ | |
16 | #pragma interface "filefn.h" | |
17 | #endif | |
18 | ||
e49f47aa GL |
19 | #include <wx/list.h> |
20 | ||
45ea509a VZ |
21 | // ---------------------------------------------------------------------------- |
22 | // constants | |
23 | // ---------------------------------------------------------------------------- | |
c801d85f | 24 | |
45ea509a VZ |
25 | // define off_t |
26 | #include <sys/types.h> | |
27 | ||
28 | #ifdef _MSC_VER | |
29 | #define off_t _off_t | |
30 | #endif | |
31 | ||
1678ad78 GL |
32 | const off_t wxInvalidOffset = (off_t)-1; |
33 | ||
45ea509a VZ |
34 | typedef enum { |
35 | wxFromStart, | |
36 | wxFromCurrent, | |
37 | wxFromEnd | |
38 | } wxSeekMode; | |
39 | ||
40 | // ---------------------------------------------------------------------------- | |
41 | // functions | |
42 | // ---------------------------------------------------------------------------- | |
c801d85f KB |
43 | bool WXDLLEXPORT wxFileExists(const wxString& filename); |
44 | #define FileExists wxFileExists | |
45 | ||
46 | // does the path exist? (may have or not '/' or '\\' at the end) | |
47 | bool WXDLLEXPORT wxPathExists(const char *pszPathName); | |
48 | ||
49 | #define wxDirExists wxPathExists | |
50 | #define DirExists wxDirExists | |
51 | ||
52 | bool WXDLLEXPORT wxIsAbsolutePath(const wxString& filename); | |
53 | #define IsAbsolutePath wxIsAbsolutePath | |
54 | ||
55 | // Get filename | |
56 | char* WXDLLEXPORT wxFileNameFromPath(char *path); | |
57 | wxString WXDLLEXPORT wxFileNameFromPath(const wxString& path); | |
58 | #define FileNameFromPath wxFileNameFromPath | |
59 | ||
60 | // Get directory | |
61 | char* WXDLLEXPORT wxPathOnly(char *path); | |
62 | wxString WXDLLEXPORT wxPathOnly(const wxString& path); | |
63 | #define PathOnly wxPathOnly | |
64 | ||
65 | // wxString version | |
66 | wxString WXDLLEXPORT wxRealPath(const wxString& path); | |
67 | ||
68 | void WXDLLEXPORT wxDos2UnixFilename(char *s); | |
69 | #define Dos2UnixFilename wxDos2UnixFilename | |
70 | ||
71 | void WXDLLEXPORT wxUnix2DosFilename(char *s); | |
72 | #define Unix2DosFilename wxUnix2DosFilename | |
73 | ||
74 | // Strip the extension, in situ | |
75 | void WXDLLEXPORT wxStripExtension(char *buffer); | |
2bb0cd28 | 76 | void WXDLLEXPORT wxStripExtension(wxString& buffer); |
c801d85f KB |
77 | |
78 | // Get a temporary filename, opening and closing the file. | |
79 | char* WXDLLEXPORT wxGetTempFileName(const wxString& prefix, char *buf = NULL); | |
80 | ||
81 | // Expand file name (~/ and ${OPENWINHOME}/ stuff) | |
82 | char* WXDLLEXPORT wxExpandPath(char *dest, const char *path); | |
83 | ||
84 | // Contract w.r.t environment (</usr/openwin/lib, OPENWHOME> -> ${OPENWINHOME}/lib) | |
85 | // and make (if under the home tree) relative to home | |
86 | // [caller must copy-- volatile] | |
87 | char* WXDLLEXPORT wxContractPath (const wxString& filename, | |
88 | const wxString& envname = "", const wxString& user = ""); | |
89 | ||
90 | // Destructive removal of /./ and /../ stuff | |
91 | char* WXDLLEXPORT wxRealPath(char *path); | |
92 | ||
93 | // Allocate a copy of the full absolute path | |
94 | char* WXDLLEXPORT wxCopyAbsolutePath(const wxString& path); | |
95 | ||
96 | // Get first file name matching given wild card. | |
97 | // Flags are reserved for future use. | |
98 | #define wxFILE 1 | |
99 | #define wxDIR 2 | |
100 | char* WXDLLEXPORT wxFindFirstFile(const char *spec, int flags = wxFILE); | |
101 | char* WXDLLEXPORT wxFindNextFile(void); | |
102 | ||
103 | // Does the pattern contain wildcards? | |
104 | bool WXDLLEXPORT wxIsWild(const wxString& pattern); | |
105 | ||
106 | // Does the pattern match the text (usually a filename)? | |
107 | // If dot_special is TRUE, doesn't match * against . (eliminating | |
108 | // `hidden' dot files) | |
109 | bool WXDLLEXPORT wxMatchWild(const wxString& pattern, const wxString& text, bool dot_special = TRUE); | |
110 | ||
111 | // Concatenate two files to form third | |
112 | bool WXDLLEXPORT wxConcatFiles(const wxString& file1, const wxString& file2, const wxString& file3); | |
113 | ||
114 | // Copy file1 to file2 | |
115 | bool WXDLLEXPORT wxCopyFile(const wxString& file1, const wxString& file2); | |
116 | ||
117 | // Remove file | |
118 | bool WXDLLEXPORT wxRemoveFile(const wxString& file); | |
119 | ||
120 | // Rename file | |
121 | bool WXDLLEXPORT wxRenameFile(const wxString& file1, const wxString& file2); | |
122 | ||
123 | // Get current working directory. | |
124 | // If buf is NULL, allocates space using new, else | |
125 | // copies into buf. | |
126 | // IMPORTANT NOTE getcwd is know not to work under some releases | |
127 | // of Win32s 1.3, according to MS release notes! | |
128 | char* WXDLLEXPORT wxGetWorkingDirectory(char *buf = NULL, int sz = 1000); | |
129 | ||
130 | // Set working directory | |
131 | bool WXDLLEXPORT wxSetWorkingDirectory(const wxString& d); | |
132 | ||
133 | // Make directory | |
134 | bool WXDLLEXPORT wxMkdir(const wxString& dir); | |
135 | ||
136 | // Remove directory. Flags reserved for future use. | |
137 | bool WXDLLEXPORT wxRmdir(const wxString& dir, int flags = 0); | |
138 | ||
139 | // separators in file names | |
140 | #define FILE_SEP_EXT '.' | |
141 | #define FILE_SEP_DSK ':' | |
142 | #define FILE_SEP_PATH_DOS '\\' | |
143 | #define FILE_SEP_PATH_UNIX '/' | |
144 | ||
145 | // separator in the path list (as in PATH environment variable) | |
146 | // NB: these are strings and not characters on purpose! | |
147 | #define PATH_SEP_DOS ";" | |
148 | #define PATH_SEP_UNIX ":" | |
149 | ||
150 | // platform independent versions | |
151 | #ifdef __UNIX__ | |
152 | #define FILE_SEP_PATH FILE_SEP_PATH_UNIX | |
153 | #define PATH_SEP PATH_SEP_UNIX | |
154 | #else // Windows | |
155 | #define FILE_SEP_PATH FILE_SEP_PATH_DOS | |
156 | #define PATH_SEP PATH_SEP_DOS | |
157 | #endif // Unix/Windows | |
158 | ||
92abb45d VZ |
159 | // this is useful for wxString::IsSameAs(): to compare two file names use |
160 | // filename1.IsSameAs(filename2, wxARE_FILENAMES_CASE_SENSITIVE) | |
161 | #ifdef __UNIX__ | |
162 | #define wxARE_FILENAMES_CASE_SENSITIVE TRUE | |
163 | #else // Windows | |
164 | #define wxARE_FILENAMES_CASE_SENSITIVE FALSE | |
165 | #endif // Unix/Windows | |
166 | ||
c801d85f KB |
167 | // is the char a path separator? |
168 | inline bool wxIsPathSeparator(char c) | |
169 | { return c == FILE_SEP_PATH_DOS || c == FILE_SEP_PATH_UNIX; } | |
170 | ||
171 | // does the string ends with path separator? | |
172 | bool WXDLLEXPORT wxEndsWithPathSeparator(const char *pszFileName); | |
173 | ||
92abb45d VZ |
174 | // split the full path into path (including drive for DOS), name and extension |
175 | // (understands both '/' and '\\') | |
176 | void WXDLLEXPORT wxSplitPath(const char *pszFileName, | |
177 | wxString *pstrPath, | |
178 | wxString *pstrName, | |
179 | wxString *pstrExt); | |
180 | ||
c801d85f KB |
181 | // find a file in a list of directories, returns false if not found |
182 | bool WXDLLEXPORT wxFindFileInPath(wxString *pStr, const char *pszPath, const char *pszFile); | |
183 | ||
45ea509a VZ |
184 | // ---------------------------------------------------------------------------- |
185 | // classes | |
186 | // ---------------------------------------------------------------------------- | |
187 | ||
c801d85f KB |
188 | // Path searching |
189 | class WXDLLEXPORT wxPathList: public wxStringList | |
190 | { | |
191 | DECLARE_DYNAMIC_CLASS(wxPathList) | |
192 | ||
193 | public: | |
194 | void AddEnvList(const wxString& envVariable); // Adds all paths in environment variable | |
195 | void Add(const wxString& path); | |
196 | wxString FindValidPath(const wxString& filename); // Find the first full path | |
197 | // for which the file exists | |
198 | wxString FindAbsoluteValidPath(const wxString& filename); // Find the first full path | |
199 | // for which the file exists; ensure it's an absolute | |
200 | // path that gets returned. | |
201 | void EnsureFileAccessible(const wxString& path); // Given full path and filename, | |
202 | // add path to list | |
203 | bool Member(const wxString& path); | |
204 | }; | |
205 | ||
206 | #endif | |
207 | // __FILEFNH__ | |
208 |