4611e9977e2782ae9eca48eb25b5a7b71d0efad4
[pandora-libraries.git] / lib / pnd_pathiter.h
1
2 #ifndef h_pnd_pathiter_h
3 #define h_png_pathiter_h
4
5 // man don'y you wish it was python, perl or c++ right about now?
6 // perl: foreach i ( split ( ':', path ) ) would be sauce right now
7
8 // this really should be replaced by a function pair .. one to
9 // start a new search and one to go to next, bailing when done. Maybe
10 // a state struct. Like we have time. OR perhaps just a single
11 // func with a callback. Whatever.
12
13 #define SEARCHPATH_PRE                            \
14   char *end, *colon;                              \
15   char *head = searchpath;                        \
16   char buffer [ FILENAME_MAX ];                   \
17                                                   \
18   while ( 1 ) {                                   \
19     colon = strchr ( head, ':' );                 \
20     end = strchr ( head, '\0' );                  \
21                                                   \
22     if ( colon && colon < end ) {                 \
23       memset ( buffer, '\0', FILENAME_MAX );      \
24       strncpy ( buffer, head, colon - head );     \
25     } else {                                      \
26       strncpy ( buffer, head, FILENAME_MAX - 1 ); \
27     }                                             \
28                                                   \
29     //printf ( "Path to search: '%s'\n", buffer );
30
31 #define SEARCHPATH_POST                           \
32     /* next search path */                        \
33     if ( colon && colon < end ) {                 \
34       head = colon + 1;                           \
35     } else {                                      \
36       break; /* done! */                          \
37     }                                             \
38                                                   \
39   } // while
40
41 #endif