X-Git-Url: http://git.openpandora.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=lib%2Fpnd_pathiter.h;h=5e13aa853abb9e3c750ba0769839df0c0afe34a0;hb=3b8680635554d605276eb489f298b6427d371027;hp=e91a40842bd492d2d37c3378ebc1eeefc9b004ab;hpb=29847dbecdfd3887a750191bb37f61c81412b3c9;p=pandora-libraries.git diff --git a/lib/pnd_pathiter.h b/lib/pnd_pathiter.h index e91a408..5e13aa8 100644 --- a/lib/pnd_pathiter.h +++ b/lib/pnd_pathiter.h @@ -22,6 +22,9 @@ #if 1 // globbing is performed +// only iterates actual existing paths; if you want to return +// non-matching paths, see below + #define SEARCHPATH_PRE \ char *end, *colon; \ char *head = searchpath; \ @@ -74,6 +77,47 @@ \ } // while + +// the following will return even non-matching chunks, but is not doing wordexp() expansion on it + +#define SEARCHCHUNK_PRE \ + char *end, *colon; \ + char *head = searchpath; \ + char chunk [ FILENAME_MAX ]; \ + \ + /*fprintf ( stderr, "sp %s\n", searchpath );*/ \ + \ + while ( 1 ) { \ + colon = strchr ( head, ':' ); \ + end = strchr ( head, '\0' ); \ + \ + if ( colon && colon < end ) { \ + memset ( chunk, '\0', FILENAME_MAX ); \ + strncpy ( chunk, head, colon - head ); \ + } else { \ + strncpy ( chunk, head, FILENAME_MAX - 1 ); \ + } \ + \ + /*fprintf ( stderr, "-> %s\n", chunk ); */ \ + \ + char buffer [ FILENAME_MAX ]; \ + \ + strcpy ( buffer, chunk ); \ + /*fprintf ( stderr, "glob %s\n", buffer );*/ \ + { /* user code */ + +#define SEARCHCHUNK_POST \ + } /* user code */ \ + /* next search path */ \ + if ( colon && colon < end ) { \ + head = colon + 1; \ + } else { \ + break; /* done! */ \ + } \ + \ + } // while + + #endif // globbing is done