Doxygen Source Code Documentation
thd_strfunc.c File Reference
#include "mrilib.h"Go to the source code of this file.
Defines | |
| #define | DQUOT '"' |
| #define | SQUOT '\'' |
| #define | NUL '\0' |
Functions | |
| char * | ig_strstr (char *haystack, char *needle, char *ignore) |
| void | freeup_strings (int n, char **sar) |
| int | breakup_string (char *sin, char ***stok) |
Define Documentation
|
|
Definition at line 77 of file thd_strfunc.c. Referenced by breakup_string(). |
|
|
Definition at line 79 of file thd_strfunc.c. Referenced by breakup_string(). |
|
|
Definition at line 78 of file thd_strfunc.c. Referenced by breakup_string(). |
Function Documentation
|
||||||||||||
|
Definition at line 81 of file thd_strfunc.c. References DQUOT, malloc, NUL, realloc, and SQUOT. Referenced by AFNI_drive_addto_graph_1D(), AFNI_drive_addto_graph_xy(), AFNI_drive_clear_graph_1D(), AFNI_drive_clear_graph_xy(), AFNI_drive_close_graph_xy(), AFNI_drive_geom_graph(), AFNI_drive_open_graph_1D(), AFNI_drive_open_graph_xy(), and TTRR_load_file().
00082 {
00083 int n_tok , quote , ll ;
00084 char **s_tok , *cpt , *sss , qch=NUL ;
00085
00086 if( stok == NULL || sin == NULL || sin[0] == NUL ) return -1 ;
00087
00088 n_tok = 0 ;
00089 s_tok = NULL ;
00090
00091 cpt = sin ;
00092
00093 while( *cpt != '\0' ){ /* loop until we use up the input string */
00094
00095 /* skip whitespace */
00096
00097 while( isspace(*cpt) ) cpt++ ;
00098 if( *cpt == NUL ) break ; /* reached end */
00099
00100 /* if starts with a quote, note that factoid */
00101
00102 if( *cpt == SQUOT || *cpt == DQUOT ){
00103 quote = 1 ; qch = *cpt ; cpt++ ; /* qch = quote character */
00104 if( *cpt == NUL ) break ;
00105 } else {
00106 quote = 0 ;
00107 }
00108
00109 /* scan until end of sub-string (next quote, or next nonblank) */
00110
00111 sss = cpt ; /* start of sub-string */
00112 if( quote ){
00113 while( *cpt != NUL && *cpt != qch ) cpt++ ; /* scan to next quote */
00114 } else {
00115 while( *cpt != NUL && !isspace(*cpt) ) cpt++ ; /* to next non-blank */
00116 }
00117
00118 /* cpt now points to character after end of sub-string */
00119
00120 ll = cpt - sss ; /* number of characters in sub-string (may be zero) */
00121
00122 /* make a new entry in the string table */
00123
00124 s_tok = (char **) realloc( s_tok , sizeof(char *) * (n_tok+1) ) ;
00125 s_tok[n_tok] = (char *) malloc(ll+4) ;
00126 if( ll > 0 ) memcpy( s_tok[n_tok] , sss , ll ) ;
00127 s_tok[n_tok][ll] = NUL ;
00128 n_tok++ ;
00129
00130 /* skip the character after the end of sub-string */
00131
00132 if( *cpt == NUL ) break ; /* end of the line, baby [14 Apr 2005] */
00133 cpt++ ;
00134 } /* end of loop over input string */
00135
00136 *stok = s_tok ; return n_tok ;
00137 }
|
|
||||||||||||
|
Definition at line 61 of file thd_strfunc.c. References free. Referenced by AFNI_drive_addto_graph_1D(), AFNI_drive_addto_graph_xy(), AFNI_drive_clear_graph_1D(), AFNI_drive_clear_graph_xy(), AFNI_drive_close_graph_xy(), AFNI_drive_geom_graph(), AFNI_drive_open_graph_1D(), AFNI_drive_open_graph_xy(), and TTRR_load_file().
|
|
||||||||||||||||
|
Find if needle is in haystack, ignoring case and ignoring any characters in ignore. Definition at line 7 of file thd_strfunc.c. References free. Referenced by TTRR_load_file().
00008 {
00009 char *hs, *ne , *cp ;
00010 int ii, jj ;
00011
00012 if( haystack == NULL || haystack[0] == '\0' ||
00013 needle == NULL || needle[0] == '\0' ) return NULL ;
00014
00015 /* make uppercase copy of haystack */
00016
00017 hs = strdup(haystack) ; jj = strlen(hs) ;
00018 for( ii=0 ; ii < jj ; ii++ ) hs[ii] = toupper(hs[ii]) ;
00019
00020 /* replace all ignore characters in hs with a period */
00021
00022 if( ignore != NULL && ignore[0] != '\0' ){
00023 for( ii=0 ; ii < jj ; ii++ ){
00024 if( strchr(ignore,hs[ii]) != NULL ) hs[ii] = '.' ;
00025 }
00026 }
00027
00028 /* make uppercase copy of needle */
00029
00030 ne = strdup(needle) ; jj = strlen(ne) ;
00031 for( ii=0 ; ii < jj ; ii++ ) ne[ii] = toupper(ne[ii]) ;
00032
00033 /* replace all ignore characters in ne with a period */
00034
00035 if( ignore != NULL && ignore[0] != '\0' ){
00036 for( ii=0 ; ii < jj ; ii++ ){
00037 if( strchr(ignore,ne[ii]) != NULL ) ne[ii] = '.' ;
00038 }
00039 }
00040
00041 /* now find if mangled needle is in the mangled haystack */
00042
00043 cp = strstr( hs , ne ) ;
00044
00045 /* if it is, then find corresponding location in original haystack */
00046
00047 if( cp != NULL ){
00048 jj = cp-hs ; /* pointer arithmetic */
00049 cp = haystack + jj ; /* ditto */
00050 }
00051
00052 /* we're outta here */
00053
00054 free(ne); free(hs); return cp;
00055 }
|