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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 584 by johnpye, Sat Apr 29 04:19:17 2006 UTC revision 585 by johnpye, Wed May 10 17:02:21 2006 UTC
# Line 27  Line 27 
27    
28      Heavily modified version of C++ code from codeproject.com      Heavily modified version of C++ code from codeproject.com
29      originally written by Simon Parkinson-Bates.      originally written by Simon Parkinson-Bates.
30    
31        @TODO add environment variable expansion here for use in case like
32        "$ASCENDTK/bitmaps" or "ascend-$VERSION$EXESUFFIX"
33    
34        @NOTE this library makes no allowance for fancy escape characters.
35        You better not try to put escaped slashes into your paths, and
36        make sure you've unescaped everything before you send it to
37        ospath.
38  */  */
39    
40  #ifndef OSPATH_H  #ifndef OSPATH_H
41  #define OSPATH_H  #define OSPATH_H
42    
43    #ifdef TEST
44    # define ASC_DLLSPEC(T) T
45    # include "env.h"
46    #else
47    # include <utilities/config.h>
48    # include <utilities/ascConfig.h>
49    # include <utilities/ascMalloc.h>
50    # include "env.h"
51    #endif
52    
53    #if defined(__WIN32__) && !defined(__MINGW32__)
54    # include <direct.h>
55    # include <stdlib.h>
56    #else
57    # ifdef __MINGW32__
58    #  include <io.h>
59    #  include <limits.h>
60    # endif
61    #endif
62    
63  #ifndef PATH_MAX  #ifndef PATH_MAX
64  # define PATH_MAX 1023  # define PATH_MAX 1023
# Line 43  struct FilePath; Line 71  struct FilePath;
71      normalise the path and attempt to add a drive-prefix      normalise the path and attempt to add a drive-prefix
72      if one is missing.      if one is missing.
73  */  */
74  struct FilePath *ospath_new(const char *path);  ASC_DLLSPEC(struct FilePath *) ospath_new(const char *path);
75    
76    ASC_DLLSPEC(struct FilePath *) ospath_new_noclean(const char *path);
77    
78  /**  /**
79      Free an ospath      Free an ospath
80  */  */
81  void ospath_free(struct FilePath *);  ASC_DLLSPEC(void) ospath_free(struct FilePath *);
82    
83    /**
84        Free a string allocated from ospath.
85    */
86    ASC_DLLSPEC(void) ospath_free_str(char *str);
87    
88  /**  /**
89      Create a new ospath object from a string, assuming      Create a new ospath object from a string, assuming
# Line 57  void ospath_free(struct FilePath *); Line 92  void ospath_free(struct FilePath *);
92  struct FilePath *ospath_new_from_posix(const char *posixpath);  struct FilePath *ospath_new_from_posix(const char *posixpath);
93    
94  /**  /**
95        Path with *VERY SIMPLE* environment variable expansion.
96        You must specify what 'getenv' function should be used.
97    */
98    ASC_DLLSPEC(struct FilePath *) ospath_new_expand_env(const char *path, GetEnvFn *getenvptr);
99    
100    /**
101        This function cleans up the path string used to construct the FilePath object:
102        1. Get rid of multiple / 's one after the other...
103    
104           ie. "///usr/bin///hello/////there// --> "/usr/bin/hello/there/"
105    
106        2. Resolve a leading tilde (~) to the current user's HOME path
107    
108        3. Remove redundant /./ in middle of path
109    
110        4. Remove reduncant dir/.. in path
111    
112        5. Environment substitution??
113    
114        6. On windows, drive reference if not specified
115    
116        7. What about \\server\path and URLs, gnomefs, etc?
117    */
118    ASC_DLLSPEC(void) ospath_cleanup(struct FilePath *);
119    
120    /**
121      Check that the created FilePath was valid (i.e. able      Check that the created FilePath was valid (i.e. able
122      to be parsed. Doesn't check that the directory/file      to be parsed. Doesn't check that the directory/file
123      actually exists.)      actually exists.)
# Line 67  int ospath_isvalid(struct FilePath *fp); Line 128  int ospath_isvalid(struct FilePath *fp);
128      Return the FilePath in the form of a string.      Return the FilePath in the form of a string.
129      You must FREE the allocated string when you don't need it any more.      You must FREE the allocated string when you don't need it any more.
130  */  */
131  char *ospath_str(struct FilePath *fp);  ASC_DLLSPEC(char *) ospath_str(struct FilePath *fp);
132    
133  /**  /**
134      Return the FilePath in the string location given.      Return the FilePath in the string location given.
# Line 78  char *ospath_str(struct FilePath *fp); Line 139  char *ospath_str(struct FilePath *fp);
139          will be written.          will be written.
140      @param destsize the amount of allocated string space at dest.      @param destsize the amount of allocated string space at dest.
141  */  */
142  void ospath_strcpy(struct FilePath *fp,char *dest, int destsize);  ASC_DLLSPEC(void) ospath_strcpy(struct FilePath *fp,char *dest, int destsize);
143    
144    /**
145        Append string from FilePath to the already-allocated string 'dest',
146        while ensuring that the 'dest' strings *total* size doesn't exceed
147        destsize.
148    */
149    ASC_DLLSPEC(void) ospath_strcat(struct FilePath *fp,char *dest, int destsize);
150    
151  /**  /**
152      Output the FilePath to a file      Output the FilePath to a file
# Line 118  struct FilePath *ospath_getparentatdepth Line 186  struct FilePath *ospath_getparentatdepth
186  char *ospath_getbasefilename(struct FilePath *fp);  char *ospath_getbasefilename(struct FilePath *fp);
187    
188  /**  /**
189      retrieve the path's bottom level filename without the extension.      Retrieve the path's bottom level filename without the extension.
190      A path that ends in a slash will be assumed to be directory, so the      A path that ends in a slash will be assumed to be directory, so the
191      file stem will be NULL (ie not a file)      file stem will be NULL (ie not a file)
192  */  */
# Line 130  char *ospath_getfilestem(struct FilePath Line 198  char *ospath_getfilestem(struct FilePath
198  char *ospath_getfileext(struct FilePath *fp);  char *ospath_getfileext(struct FilePath *fp);
199    
200  /**  /**
201      retrieve the directory component of the path (everything up the the      Return a new FilePath containing the directory component of the path
202      last slash      (everything up the the last slash).
203  */  */
204  struct FilePath *ospath_getdir(struct FilePath *fp);  ASC_DLLSPEC(struct FilePath *) ospath_getdir(struct FilePath *fp);
205    
206  /**  /**
207      Function returns true if the current path is the root directory, otherwise it returns false.      Function returns true if the current path is the root directory, otherwise it returns false.
# Line 154  struct FilePath *ospath_root(struct File Line 222  struct FilePath *ospath_root(struct File
222    
223  int ospath_cmp(struct FilePath *fp1, struct FilePath *fp2);  int ospath_cmp(struct FilePath *fp1, struct FilePath *fp2);
224    
225  struct FilePath *ospath_concat(struct FilePath *fp1, struct FilePath *fp2);  ASC_DLLSPEC(struct FilePath *) ospath_concat(struct FilePath *fp1, struct FilePath *fp2);
226    
227  void ospath_append(struct FilePath *fp, struct FilePath *fp1);  ASC_DLLSPEC(void) ospath_append(struct FilePath *fp, struct FilePath *fp1);
228    
229  /**  /**
230      File-open function. Simply a wrapper about the 'fopen' call, except      File-open function. Simply a wrapper about the 'fopen' call, except
231      that if the FilePath is not 'valid' it will return NULL without      that if the FilePath is not 'valid' it will return NULL without
232      attempting to open.      attempting to open.
233  */  */
234  FILE *ospath_fopen(struct FilePath *fp, const char *mode);  ASC_DLLSPEC(FILE *) ospath_fopen(struct FilePath *fp, const char *mode);
235    
236  //------------------------  //------------------------
237  // SEARCH PATH FUNCTIONS  // SEARCH PATH FUNCTIONS
# Line 172  struct FilePath **ospath_searchpath_new( Line 240  struct FilePath **ospath_searchpath_new(
240    
241  typedef int (FilePathTestFn)(struct FilePath *,void *);  typedef int (FilePathTestFn)(struct FilePath *,void *);
242    
243    /**
244        @return pointer to path component in which testfn passed, or else
245        NULL if no component passed the test.
246    */
247  struct FilePath *ospath_searchpath_iterate(  struct FilePath *ospath_searchpath_iterate(
248          struct FilePath **searchpath          struct FilePath **searchpath
249          , FilePathTestFn *testfn          , FilePathTestFn *testfn

Legend:
Removed from v.584  
changed lines
  Added in v.585

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