librnr  1.14.5
RoadNarrows Robotics Common Library 1
path.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 /*! \file
3  *
4  * \brief General file name and file path utility declarations.
5  *
6  * Boths posix (the world) and Microsoft's file and path syntax are
7  * supported.
8  *
9  * \par Supported Search Path Backus-Naur Form:
10  * \verbatim
11  * search_path ::=
12  * path
13  * | path path_sep search_path
14  *
15  * path ::=
16  * root rel_path
17  * | rel_path
18  *
19  * root :: =
20  * std_dir_sep
21  * | win_dir_sep
22  * | win_drive win_dir_sep
23  *
24  * rel_path ::=
25  * fname
26  * | fname dir_sep rel_path
27  *
28  * fname ::=
29  * '.'
30  * | '.' '.'
31  * | '~'
32  * | '~' OSLEGAL_USERNAME
33  * | '$' indentifier
34  * | '$' '{' indentifier '}'
35  * | OSLEGAL_FILENAME
36  *
37  * path_sep ::= std_path_sep | win_path_sep
38  *
39  * std_path_sep ::= ':'
40  * win_path_sep ::= ';'
41  *
42  * dir_sep ::= std_dir_sep | win_dir_sep
43  *
44  * std_dir_sep ::= '/'
45  * win_dir_sep ::= '\\'
46  *
47  * win_drive ::= a-zA-Z ':'
48  * \endverbatim
49  *
50  * \pkgsynopsis
51  * RoadNarrows Robotics Common Library 1
52  *
53  * \pkgcomponent{Library}
54  * librnr
55  *
56  * \pkgfile{rnr/path.h}
57  *
58  * \author Robin Knight (robin.knight@roadnarrows.com)
59  *
60  * \pkgcopyright{2005-2018,RoadNarrows LLC.,http://www.roadnarrows.com}
61  *
62  * \license{MIT}
63  *
64  * \EulaBegin
65  * See the README and EULA files for any copyright and licensing information.
66  * \EulaEnd
67  */
68 ////////////////////////////////////////////////////////////////////////////////
69 
70 #ifndef _RNR_PATH_H
71 #define _RNR_PATH_H
72 
73 #include <ctype.h>
74 
75 #include "rnr/rnrconfig.h"
76 
78 
79 /*!
80  * Search Path Iterator Structure
81  */
82 typedef struct path_iter PathIter_T;
83 
84 /*!
85  * \brief Check if the given path is an absolute path.
86  *
87  * \param sPath Path name.
88  *
89  * \return Returnes true or false
90  */
91 INLINE_IN_H bool_t PathIsAbsolute(const char *sPath)
92 {
93  if( sPath == NULL )
94  {
95  return false;
96  }
97  else if( *sPath == DIR_SEP_CHAR )
98  {
99  return true;
100  }
101 #if defined(__windows__)
102  else if( isalpha(*sPath) && (*(sPath+1) == ':') &&
103  (*(sPath+2) == DIR_SEP_CHAR) )
104  {
105  return true;
106  }
107 #endif // __windwos__
108  else
109  {
110  return false;
111  }
112 }
113 
114 extern char *NewExpandTilde(const char *sTildeExpr);
115 
116 extern char *NewSearchPathExpanded(const char *sSearchPath);
117 
118 extern char *NewSearchPathCanonicalized(const char *sSearchPath);
119 
120 extern PathIter_T *SearchPathIterNew(const char *sSearchPath);
121 
122 extern void SearchPathIterDelete(PathIter_T *pIter);
123 
124 extern char *SearchPathIterFirst(PathIter_T *pIter, const char *sSearchFile);
125 
126 extern char *SearchPathIterNext(PathIter_T *pIter);
127 
128 extern char *NewNormPath(const char *sPath);
129 
130 extern char *NewRealPath(const char *sPath);
131 
132 extern char *NewJoinedPath(const char *sPath1, const char *sPath2);
133 
135 
136 
137 #endif // _RNR_PATH_H
#define DIR_SEP_CHAR
directory component separator (char version)
Definition: rnrconfig.h:238
INLINE_IN_H bool_t PathIsAbsolute(const char *sPath)
Check if the given path is an absolute path.
Definition: path.h:91
char * SearchPathIterNext(PathIter_T *pIter)
Construct next file path from search path and search file name.
Definition: path.c:526
char * NewRealPath(const char *sPath)
Expands and canonicalizes a real path.
Definition: path.c:778
#define NULL
null pointer
Definition: rnrconfig.h:199
PathIter_T * SearchPathIterNew(const char *sSearchPath)
Allocates and initilized a new search path iterator.
Definition: path.c:398
char * NewNormPath(const char *sPath)
Normalize path.
Definition: path.c:572
char * SearchPathIterFirst(PathIter_T *pIter, const char *sSearchFile)
Get the first concatenated file path.
Definition: path.c:452
char * NewSearchPathCanonicalized(const char *sSearchPath)
Expands and canonicalizes a search path.
Definition: path.c:331
#define C_DECLS_BEGIN
C declaration block begin in C.
Definition: rnrconfig.h:71
char * NewJoinedPath(const char *sPath1, const char *sPath2)
Join two file paths.
Definition: path.c:802
int bool_t
"boolean" T/F
Definition: rnrconfig.h:187
RoadNarrows Robotics common configuration file.
#define INLINE_IN_H
inline C funtion in C header
Definition: rnrconfig.h:157
#define C_DECLS_END
C declaration block end in C.
Definition: rnrconfig.h:72
Definition: path.c:76
void SearchPathIterDelete(PathIter_T *pIter)
Deletes search path iterator.
Definition: path.c:422
char * NewSearchPathExpanded(const char *sSearchPath)
Expands search path.
Definition: path.c:227
char * NewExpandTilde(const char *sTildeExpr)
Expand tilde expression.
Definition: path.c:157