/[ascend]/trunk/base/generic/general/ospath.h
ViewVC logotype

Contents of /trunk/base/generic/general/ospath.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 551 - (show annotations) (download) (as text)
Sat Apr 29 04:19:17 2006 UTC (14 years, 5 months ago) by johnpye
File MIME type: text/x-chdr
File size: 5202 byte(s)
Added LICENSE.txt to root directory
Fixed a 'const' problem in ospath
Fixed up some variable names and key errors in SConstruct
Modified License-Warranty.tcl in accordance with the recommendations in the GPL.
1 /* ASCEND modelling environment
2 Copyright (C) 2006 Carnegie Mellon University
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2, or (at your option)
7 any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330,
17 Boston, MA 02111-1307, USA.
18 *//**
19 @file
20 A C-language class for simple file-path manipulations alla python os.path.
21 Attempts to handle windows 'drive' prefixes (eg "C:") and automatic
22 substitution of forward slashes with appropriate platform-specific
23 path separators.
24
25 Has the goal of providing path-search functionality to ASCEND for
26 modules (a4c) and external library (.dll) files, etc.
27
28 Heavily modified version of C++ code from codeproject.com
29 originally written by Simon Parkinson-Bates.
30 */
31
32 #ifndef OSPATH_H
33 #define OSPATH_H
34
35 #ifndef PATH_MAX
36 # define PATH_MAX 1023
37 #endif
38
39 struct FilePath;
40
41 /**
42 Create a new ospath object from a string. This will
43 normalise the path and attempt to add a drive-prefix
44 if one is missing.
45 */
46 struct FilePath *ospath_new(const char *path);
47
48 /**
49 Free an ospath
50 */
51 void ospath_free(struct FilePath *);
52
53 /**
54 Create a new ospath object from a string, assuming
55 that standard forward-slash paths are used.
56 */
57 struct FilePath *ospath_new_from_posix(const char *posixpath);
58
59 /**
60 Check that the created FilePath was valid (i.e. able
61 to be parsed. Doesn't check that the directory/file
62 actually exists.)
63 */
64 int ospath_isvalid(struct FilePath *fp);
65
66 /**
67 Return the FilePath in the form of a string.
68 You must FREE the allocated string when you don't need it any more.
69 */
70 char *ospath_str(struct FilePath *fp);
71
72 /**
73 Return the FilePath in the string location given.
74 If the user has allocated a local array before calling ospath_strcpy,
75 then this allows the FREE(dest) call to be avoided.
76
77 @param dest the location of allocated storage space where the FilePath
78 will be written.
79 @param destsize the amount of allocated string space at dest.
80 */
81 void ospath_strcpy(struct FilePath *fp,char *dest, int destsize);
82
83 /**
84 Output the FilePath to a file
85 */
86 void ospath_fwrite(struct FilePath *fp, FILE *dest);
87
88 /**
89 Write out the internal structure of the FilePath object
90 to stderr.
91 */
92 void ospath_debug(struct FilePath *fp);
93
94 /**
95 Return length of path string
96 */
97 unsigned int ospath_length(struct FilePath *fp);
98
99 /**
100 Create a new path that is the direct parent of this one.
101 */
102 struct FilePath *ospath_getparent(struct FilePath *fp);
103
104 /**
105 Return a new path object which is a parent path of the current path up to the specified depth.
106 If the specifed depth is >= to the current path's depth, then a copy of the current path object is returned.
107
108 ie.
109 FilePath("/lev1/lev2/lev3/lev4/lev5").GetParentAtDepthN(3).c_str()
110 returns
111 "/lev1/lev2/lev3/"
112 */
113 struct FilePath *ospath_getparentatdepthn(struct FilePath *fp, unsigned nDepth);
114
115 /**
116 Return then name of the bottom most level path entry (includes any extension)
117 */
118 char *ospath_getbasefilename(struct FilePath *fp);
119
120 /**
121 retrieve the path's bottom level filename without the extension.
122 A path that ends in a slash will be assumed to be directory, so the
123 file stem will be NULL (ie not a file)
124 */
125 char *ospath_getfilestem(struct FilePath *fp);
126
127 /**
128 retrieve the paths extension (if it has one) does not include the dot
129 */
130 char *ospath_getfileext(struct FilePath *fp);
131
132 /**
133 retrieve the directory component of the path (everything up the the
134 last slash
135 */
136 struct FilePath *ospath_getdir(struct FilePath *fp);
137
138 /**
139 Function returns true if the current path is the root directory, otherwise it returns false.
140 */
141 int ospath_isroot(struct FilePath *fp);
142
143 /**
144 Return the current paths' depth
145 ie. "/usr/some directory with spaces in it/hello"
146 returns a depth value of 3
147 */
148 unsigned ospath_depth(struct FilePath *fp);
149
150 /**
151 Return the root path
152 */
153 struct FilePath *ospath_root(struct FilePath *fp);
154
155 int ospath_cmp(struct FilePath *fp1, struct FilePath *fp2);
156
157 struct FilePath *ospath_concat(struct FilePath *fp1, struct FilePath *fp2);
158
159 void ospath_append(struct FilePath *fp, struct FilePath *fp1);
160
161 /**
162 File-open function. Simply a wrapper about the 'fopen' call, except
163 that if the FilePath is not 'valid' it will return NULL without
164 attempting to open.
165 */
166 FILE *ospath_fopen(struct FilePath *fp, const char *mode);
167
168 //------------------------
169 // SEARCH PATH FUNCTIONS
170
171 struct FilePath **ospath_searchpath_new(const char *path);
172
173 typedef int (FilePathTestFn)(struct FilePath *,void *);
174
175 struct FilePath *ospath_searchpath_iterate(
176 struct FilePath **searchpath
177 , FilePathTestFn *testfn
178 , void *searchdata
179 );
180
181 #endif

john.pye@anu.edu.au
ViewVC Help
Powered by ViewVC 1.1.22