[1] | 1 | #include <stdio.h> |
---|
| 2 | #include "registry.h" |
---|
| 3 | #include "protos.h" |
---|
| 4 | #include "ctype.h" |
---|
| 5 | |
---|
| 6 | |
---|
| 7 | /* work sort of like strtok but mind quote chars */ |
---|
| 8 | static char * tokpos = NULL ; |
---|
| 9 | char * |
---|
| 10 | my_strtok( char * s1 ) |
---|
| 11 | { |
---|
| 12 | char *p, *retval ; |
---|
| 13 | int state ; |
---|
| 14 | state = 0 ; |
---|
| 15 | retval = NULL ; |
---|
| 16 | if ( s1 == NULL && tokpos == NULL ) return( NULL ) ; |
---|
| 17 | if ( s1 != NULL ) tokpos = s1 ; |
---|
| 18 | for ( p = tokpos ; *p ; p++ ) |
---|
| 19 | { |
---|
| 20 | if ( state == 0 && (*p == ' ' || *p == '\t') ) continue ; |
---|
| 21 | if ( state == 0 && !(*p == ' ' || *p == '\t') ) { state = 1 ; retval = p ; } ; |
---|
| 22 | if ( state == 1 && (*p == '"') ) { state = 2 ; } |
---|
| 23 | else if ( state == 2 && (*p == '"') ) { state = 1 ; } |
---|
| 24 | if ( state == 1 && (*p == ' ' || *p == '\t') ) { *p = '\0' ; p++ ; break ; } |
---|
| 25 | } |
---|
| 26 | tokpos = p ; |
---|
| 27 | return( retval ) ; |
---|
| 28 | } |
---|
| 29 | |
---|
| 30 | |
---|
| 31 | /* posix like rentrant strtok; not quote safe, and not quite strtok -- new version; skips multi delims */ |
---|
| 32 | char * |
---|
| 33 | strtok_rentr( char * s1 , char * s2, char ** tokpos ) |
---|
| 34 | { |
---|
| 35 | char *p, *q, *retval ; |
---|
| 36 | int match ; |
---|
| 37 | retval = NULL ; |
---|
| 38 | if ( s1 == NULL && s2 == NULL ) return( NULL ) ; |
---|
| 39 | if ( s1 != NULL ) { *tokpos = s1 ; } |
---|
| 40 | if ( **tokpos ) retval = *tokpos ; |
---|
| 41 | for ( p = *tokpos ; *p ; p++ ) |
---|
| 42 | { |
---|
| 43 | for ( q = s2 ; *q ; q++ ) |
---|
| 44 | { |
---|
| 45 | if ( *p == *q ) { *p = '\0' ; p++ ; goto foundit ; } |
---|
| 46 | } |
---|
| 47 | } |
---|
| 48 | foundit: |
---|
| 49 | /* skip over multi-delims */ |
---|
| 50 | for ( ; *p ; p++ ) |
---|
| 51 | { |
---|
| 52 | match = 0 ; |
---|
| 53 | for ( q = s2 ; *q ; q++ ) |
---|
| 54 | { |
---|
| 55 | if ( *p == *q ) { *p = '\0' ; match++ ; } |
---|
| 56 | } |
---|
| 57 | if ( match == 0 ) { break ; } |
---|
| 58 | } |
---|
| 59 | *tokpos = p ; |
---|
| 60 | return( retval ) ; |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | #if 0 |
---|
| 64 | /* posix like rentrant strtok; not quote safe, and not quite strtok -- won't skip over multiple delims */ |
---|
| 65 | char * |
---|
| 66 | strtok_rentr( char * s1 , char * s2, char ** tokpos ) |
---|
| 67 | { |
---|
| 68 | char *p, *q, *retval ; |
---|
| 69 | retval = NULL ; |
---|
| 70 | if ( s1 == NULL && s2 == NULL ) return( NULL ) ; |
---|
| 71 | if ( s1 != NULL ) { *tokpos = s1 ; } |
---|
| 72 | if ( **tokpos ) retval = *tokpos ; |
---|
| 73 | for ( p = *tokpos ; *p ; p++ ) |
---|
| 74 | { |
---|
| 75 | for ( q = s2 ; *q ; q++ ) |
---|
| 76 | { |
---|
| 77 | if ( *p == *q ) { *p = '\0' ; p++ ; goto foundit ; } |
---|
| 78 | } |
---|
| 79 | } |
---|
| 80 | foundit: |
---|
| 81 | *tokpos = p ; |
---|
| 82 | return( retval ) ; |
---|
| 83 | } |
---|
| 84 | #endif |
---|
| 85 | |
---|
| 86 | int |
---|
| 87 | make_lower( char * s1 ) |
---|
| 88 | { |
---|
| 89 | char * p ; |
---|
| 90 | int state ; |
---|
| 91 | state = 0 ; |
---|
| 92 | for ( p = s1 ; *p ; p++ ) |
---|
| 93 | { |
---|
| 94 | if ( state == 0 && *p == '"' ) state = 1 ; |
---|
| 95 | else if ( state == 1 && *p == '"' ) state = 0 ; |
---|
| 96 | if ( state == 0 ) |
---|
| 97 | { |
---|
| 98 | *p = tolower(*p) ; |
---|
| 99 | } |
---|
| 100 | } |
---|
| 101 | return(0) ; |
---|
| 102 | } |
---|