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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 541 - (hide annotations) (download) (as text)
Wed Apr 26 07:32:13 2006 UTC (18 years, 2 months ago) by johnpye
File MIME type: text/x-chdr
File size: 4281 byte(s)
More work on the ospath.c file, trying to iron out some windows-specific issues
Fixed McGraw-Hill URL in TCL files.
Created platform-specific TCL_LIBPATH so that c:\Tcl\bin is used instead of c:\Tcl\lib for .dlls.
1 johnpye 534 /* 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 johnpye 541 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 johnpye 534
25 johnpye 541 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 johnpye 534 */
31    
32     #ifndef OSPATH_H
33     #define OSPATH_H
34    
35     struct FilePath;
36    
37 johnpye 541 /**
38     Create a new ospath object from a string. This will
39     normalise the path and attempt to add a drive-prefix
40     if one is missing.
41     */
42 johnpye 534 struct FilePath *ospath_new(const char *path);
43    
44 johnpye 541 /**
45     Free an ospath
46     */
47     void ospath_free(struct FilePath *);
48    
49     /**
50     Create a new ospath object from a string, assuming
51     that standard forward-slash paths are used.
52     */
53 johnpye 535 struct FilePath *ospath_new_from_posix(char *posixpath);
54    
55 johnpye 534 /**
56 johnpye 541 Check that the created FilePath was valid (i.e. able
57     to be parsed. Doesn't check that the directory/file
58     actually exists.)
59 johnpye 534 */
60     int ospath_isvalid(struct FilePath *fp);
61    
62     /**
63 johnpye 541 Return the FilePath in the form of a string.
64     You must FREE the allocated string when you don't need it any more.
65 johnpye 534 */
66     char *ospath_str(struct FilePath *fp);
67    
68     /**
69 johnpye 541 Output the FilePath to a file
70 johnpye 534 */
71     void ospath_fwrite(struct FilePath *fp, FILE *dest);
72    
73 johnpye 541 /**
74     Write out the internal structure of the FilePath object
75     to stderr.
76     */
77     void ospath_debug(struct FilePath *fp);
78 johnpye 534
79     /**
80     Return length of path string
81     */
82     unsigned int ospath_length(struct FilePath *fp);
83    
84     /**
85 johnpye 541 Create a new path that is the direct parent of this one.
86 johnpye 534 */
87     struct FilePath *ospath_getparent(struct FilePath *fp);
88    
89     /**
90     Return a new path object which is a parent path of the current path up to the specified depth.
91     If the specifed depth is >= to the current path's depth, then a copy of the current path object is returned.
92    
93     ie.
94     FilePath("/lev1/lev2/lev3/lev4/lev5").GetParentAtDepthN(3).c_str()
95     returns
96     "/lev1/lev2/lev3/"
97     */
98     struct FilePath *ospath_getparentatdepthn(struct FilePath *fp, unsigned nDepth);
99    
100     /**
101     Return then name of the bottom most level path entry (includes any extension)
102     */
103     char *ospath_getbasefilename(struct FilePath *fp);
104    
105     /**
106     retrieve the path's bottom level filename with out the extension
107     */
108     char *ospath_getbasefiletitle(struct FilePath *fp);
109    
110     /**
111     retrieve the paths extension (if it has one) does not include the dot
112     */
113     char *ospath_getbasefileextension(struct FilePath *fp);
114    
115     /**
116     Function returns true if the current path is the root directory, otherwise it returns false.
117     */
118     int ospath_isroot(struct FilePath *fp);
119    
120     /**
121     Return the current paths' depth
122     ie. "/usr/some directory with spaces in it/hello"
123     returns a depth value of 3
124     */
125     unsigned ospath_depth(struct FilePath *fp);
126    
127     /**
128     Return the root path
129     */
130     struct FilePath *ospath_root(struct FilePath *fp);
131    
132     int ospath_cmp(struct FilePath *fp1, struct FilePath *fp2);
133    
134     struct FilePath *ospath_concat(struct FilePath *fp1, struct FilePath *fp2);
135    
136     void ospath_append(struct FilePath *fp, struct FilePath *fp1);
137    
138 johnpye 541 //------------------------
139     // SEARCH PATH FUNCTIONS
140 johnpye 534
141 johnpye 541 struct FilePath **ospath_searchpath_new(char *path);
142    
143     typedef int (FilePathTestFn)(struct FilePath *,void *);
144    
145     struct FilePath *ospath_searchpath_iterate(
146     struct FilePath **searchpath
147     , FilePathTestFn *testfn
148     , void *searchdata
149     );
150    
151 johnpye 534 #endif

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