/* * Break the filename into path components, then let them * be matched individually */ int dfnmatchEx(const char *fnam , const char *pattern , int (*matchfct)(const char *, const char *)) { char n1[DFN_FILENAME_BUFFER_LENGTH], n2[DFN_FILENAME_BUFFER_LENGTH]; int c1, c2; #ifdef SUPPORT_UNC_PATH #define NAME "dfnumatchEx" #else #define NAME "dfnmatchEx" #endif DBG_ENTER(NAME, Suppl_dfn) assert(fnam); assert(pattern); assert(matchfct); DBG_ARGUMENTS( ("fnam=\"%s\", pattern=\"%s\"", fnam, pattern) ) #ifdef SUPPORT_UNC_PATHS if(isUNCpath(fnam) != isUNCpath(pattern)) DBG_RETURN_I( 0) #endif /* 1. Make sure both names start or don't start with a path delimiter */ if(isPathDelim(*fnam)) { if(!isPathDelim(*pattern)) DBG_RETURN_I( 0) while(isPathDelim(*++fnam)); while(isPathDelim(*++pattern)); } else if(isPathDelim(*pattern))
char *dfnsqueeze(const char * const fnam) { char *p, *h, *q; #ifdef SUPPORT_UNC_PATH DBG_ENTER("dfnusqueeze", Suppl_dfn) #else DBG_ENTER("dfnsqueeze", Suppl_dfn) #endif DBG_ARGUMENTS( ("fnam=\"%s\"", fnam) ) if(!fnam || (h = q = eno_strdup(fnam)) == 0) DBG_RETURN_S( 0) #ifdef SUPPORT_UNC_PATH if(isUNCpath(q)) /* keep the two backslashes */ q += 2; #endif p = q; /* where to begin to squeeze */ /* First: Flip the slashes */ while((q = strchr(q, '/')) != 0) *q = '\\'; /* Second: Squeeze & upcase */ q = p; chkHeap do { redo: if(*q == '\\') { /* possibly to be squeezed */ if(q[1] == '\\') { /* Squeeze '\\\\' -> '\\' */ ++q; goto redo; } if(q[1] == '.') { if(q[2] == '\\') { /* squeeze '\\.\\' -> '\\' */ q += 2; goto redo; } #if 0 /* this may lead to confusion -- 2000/06/07 ska*/ if(q[2] == '\0') { /* squeeze '\\.\0' -> '\\' */ *p = '\\'; *++p = NUL; break; } #endif } } } while((*p++ = toFUpper(*q++)) != 0); chkHeap DBG_RETURN_BS( StrTrim(h)) }
char *dfnfullpath(const char * const fnam) { char *fullpath; char *paths; char *q; /* intermediate pointers */ char *nxtDelim; int cnt; #ifdef OS_WIN32 #ifdef SUPPORT_UNC_PATH DBG_ENTER("dfnufullpath2", Suppl_dfn) #else DBG_ENTER("dfnfullpath2", Suppl_dfn) #endif #else #ifdef SUPPORT_UNC_PATH DBG_ENTER("dfnufullpath", Suppl_dfn) #else DBG_ENTER("dfnfullpath", Suppl_dfn) #endif #endif assert(fnam); DBG_ARGUMENTS( ("fnam=\"%s\"", fnam) ) chkHeap if((fullpath = dfnexpand(fnam, 0)) == 0) DBG_RETURN_S( 0) assert(*fullpath); #ifdef SUPPORT_UNC_PATH if(isUNCpath(fullpath)) paths = UNCpath(fullpath); else #endif { assert(*fullpath && fullpath[1] == ':'); paths = &fullpath[2]; } chkHeap assert(*paths == '\\'); q = paths; while(*q == '\\' && *++q) { /* Check for special directories */ if((nxtDelim = strchr(q, '\\')) == 0) nxtDelim = strchr(q, '\0'); if((cnt = strspn(q, ".")) == nxtDelim - q #ifndef FEATURE_LONG_FILENAMES && cnt < 3 /* DOS limits to "." and ".." */ #endif ) { /* all dots --> special directory */ /* Relocate "q" (cnt-1) path components to the left */ while(--q > paths && --cnt) { /* search next '\' to the left */ while(*--q != '\\'); ++q; } if(*nxtDelim) { /* some components left, move them up */ /* Note: *nxtDelim == *q == '\\', but by copying over this single character one needs not implement a special handling if nxtDelim[1] == '\0' */ memmove(q, nxtDelim, strlen(nxtDelim) + 1); } else { /* this was the last component, but because this was a special directory, the information must be preserved that it is a directory --> append trailing backslash */ q[1] = '\0'; } } else { q = nxtDelim; } } chkHeap DBG_RETURN_S( StrTrim(fullpath)) }