7 /* work sort of like strtok but mind quote chars */
8 static char * tokpos
= NULL
;
10 my_strtok( char * s1
)
16 if ( s1
== NULL
&& tokpos
== NULL
) return( NULL
) ;
17 if ( s1
!= NULL
) tokpos
= s1
;
18 for ( p
= tokpos
; *p
; p
++ )
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 ; }
31 /* posix like rentrant strtok; not quote safe, and not quite strtok -- new version; skips multi delims */
33 strtok_rentr( char * s1
, char * s2
, char ** tokpos
)
35 char *p
, *q
, *retval
;
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
++ )
43 for ( q
= s2
; *q
; q
++ )
45 if ( *p
== *q
) { *p
= '\0' ; p
++ ; goto foundit
; }
49 /* skip over multi-delims */
53 for ( q
= s2
; *q
; q
++ )
55 if ( *p
== *q
) { *p
= '\0' ; match
++ ; }
57 if ( match
== 0 ) { break ; }
64 /* posix like rentrant strtok; not quote safe, and not quite strtok -- won't skip over multiple delims */
66 strtok_rentr( char * s1
, char * s2
, char ** tokpos
)
68 char *p
, *q
, *retval
;
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
++ )
75 for ( q
= s2
; *q
; q
++ )
77 if ( *p
== *q
) { *p
= '\0' ; p
++ ; goto foundit
; }
87 make_lower( char * s1
)
92 for ( p
= s1
; *p
; p
++ )
94 if ( state
== 0 && *p
== '"' ) state
= 1 ;
95 else if ( state
== 1 && *p
== '"' ) state
= 0 ;