49 #include <sys/types.h> 70 #define is1stidentifier(c) (isapha((int)c) || ((c) == '_')) 71 #define isidentifier(c) (isalnum((int)c) || ((c) == '_'))
95 DListStr_T *pSearchPaths;
108 if( (sSearchPath ==
NULL) || (sSearchPath[0] == 0) )
124 if( DListStrAppend(pSearchPaths, sPath) ==
NULL )
126 LOGERROR(
"DListStrAppend() failed");
160 struct passwd *pPassEntry;
162 char *sExpanded =
NULL;
165 if( (sTildeExpr ==
NULL) || (*sTildeExpr !=
'~') )
171 sUser = (
char *)sTildeExpr + 1;
176 if( (sExpanded = getenv(
"HOME")) ==
NULL )
179 if( (pPassEntry = getpwuid(uid)) !=
NULL )
181 sExpanded = pPassEntry->pw_dir;
189 if( (pPassEntry = getpwnam(sUser)) !=
NULL )
191 sExpanded = pPassEntry->pw_dir;
195 if( sExpanded !=
NULL )
238 if( (sSearchPath ==
NULL) || (*sSearchPath == 0) )
243 sExpPath =
NEWSTR(nMaxLen);
245 for(s=sSearchPath, t=sExpPath; *s && nExpLen<nMaxLen; )
257 nNameLen = (size_t)(s - u);
261 if( (sName !=
NULL) && ((sVal = getenv(sName)) !=
NULL) )
263 for(; *sVal && nExpLen<nMaxLen; ++nExpLen)
278 nNameLen = (size_t)(s - u);
284 for(u=sVal; *u && nExpLen<nMaxLen; ++nExpLen)
301 if( nExpLen >= nMaxLen )
303 LOGERROR(
"Expanded search path truncated");
348 len = strlen(sExpPath);
364 len = (n + k + m) * 2;
371 sprintf(sNew+n,
"%s%s", sSep, sNorm);
404 LOGERROR(
"NewSearchPathDlist() failed");
467 if( (sSearchFile ==
NULL) || (*sSearchFile == 0) )
477 LOGERROR(
"NewSearchPathCanonicalized() failed");
538 else if( (sPath = DListStrIterDataNext(&(pIter->
m_iterPaths))) !=
NULL )
587 sNew =
NEWSTR(strlen(sPath));
602 for(i=0, j=0; sPath[i]!=0; )
613 sNew[j++] = sPath[i++];
617 else if( (sPath[i+1] ==
'.') &&
630 for(k=j-1, slashes=0; k>=0 && slashes<2; --k)
646 if( (sNew[k+1] ==
'.') &&
647 (sNew[k+2] ==
'.') &&
665 else if( slashes == 1 )
700 else if( (sPath[i+1] ==
DIR_SEP_CHAR) || (sPath[i+1] == 0) )
708 sNew[j++] = sPath[i++];
722 sNew[j++] = sPath[i++];
730 else if((sNew[j-1] ==
'.') &&
739 sNew[j++] = sPath[i++];
753 sNew[j++] = sPath[i++];
762 strcpy(sNew, sTopDir);
783 t = realpath(s,
NULL);
811 LOGERROR(
"NewSearchPathCanonicalized(\"%s\") failed.", sPath2);
823 LOGERROR(
"NewSearchPathCanonicalized(\"%s\") failed.", sPath1);
#define DIR_SEP_CHAR
directory component separator (char version)
INLINE_IN_H bool_t PathIsAbsolute(const char *sPath)
Check if the given path is an absolute path.
#define DIR_SEP_STR
directory component separator (string version)
bool_t m_bIsEos
is [not] end of search flag
char * new_strndup(const char *s, size_t n)
Duplicate not more than n characters of string.
#define NEWSTR(len)
Allocate new string buffer of length len+1.
size_t m_nFileLen
length of canonical file
char * NewSearchPathExpanded(const char *sSearchPath)
Expands search path.
FILE * LOG_GET_LOGFP()
Get current logging output stream file pointer.
char * new_strdup(const char *s)
Duplicate a string.
Doubly linked list of character strings "inherited" from dlistvoid.
char * NewExpandTilde(const char *sTildeExpr)
Expand tilde expression.
char * m_sFileCanonical
search canonical file
Memory allocation and deallocation declarations.
void SearchPathIterDelete(PathIter_T *pIter)
Deletes search path iterator.
#define isidentifier(c)
id char
#define LOGFUNCNAME
function name
#define LOGERROR(fmt,...)
Standard Error logging.
#define LOGABLE(level)
Test if given level is logable at current threshold.
#define LOGDIAG4(fmt,...)
Standard Diagnostic Level 4 logging.
PathIter_T * SearchPathIterNew(const char *sSearchPath)
Allocates and initilized a new search path iterator.
DListStr_T * m_pSearchPaths
dlist of search paths
#define NEW(T)
Allocate new type.
RoadNarrows Robotics common configuration file.
#define PATH_SEP_STR
path separator (string version)
#define MAX_SEARCH_PATH
Maximum bytes of a PATH_SEP separated search path string (including NULL)
char * m_sFilePath
concatenated file path (output)
General file name and file path utility declarations.
char * NewSearchPathCanonicalized(const char *sSearchPath)
Expands and canonicalizes a search path.
char * SearchPathIterNext(PathIter_T *pIter)
Construct next file path from search path and search file name.
static DListStr_T * DListStrNewDft()
Allocator and initializer new empty string dlist with default callbacks.
static void DListStrDataPrint(FILE *fp, char *sData)
Print node data callback.
char * NewRealPath(const char *sPath)
Expands and canonicalizes a real path.
DListStrIter_T m_iterPaths
dlist iterator over paths
#define PATH_SEP_CHAR
path separator (char version)
char * NewJoinedPath(const char *sPath1, const char *sPath2)
Join two file paths.
char * NewNormPath(const char *sPath)
Normalize path.
#define LOG_LEVEL_DIAG4
diagnostic level 4
char * SearchPathIterFirst(PathIter_T *pIter, const char *sSearchFile)
Get the first concatenated file path.
static DListStr_T * NewSearchPathDList(const char *sSearchPath)
Build a dlist of canonical search paths.