Doxygen Source Code Documentation
Main Page Alphabetical List Data Structures File List Data Fields Globals Search
thd_strfunc.c
Go to the documentation of this file.00001 #include "mrilib.h"
00002
00003
00004
00005
00006
00007 char * ig_strstr( char *haystack , char *needle , char *ignore )
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
00016
00017 hs = strdup(haystack) ; jj = strlen(hs) ;
00018 for( ii=0 ; ii < jj ; ii++ ) hs[ii] = toupper(hs[ii]) ;
00019
00020
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
00029
00030 ne = strdup(needle) ; jj = strlen(ne) ;
00031 for( ii=0 ; ii < jj ; ii++ ) ne[ii] = toupper(ne[ii]) ;
00032
00033
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
00042
00043 cp = strstr( hs , ne ) ;
00044
00045
00046
00047 if( cp != NULL ){
00048 jj = cp-hs ;
00049 cp = haystack + jj ;
00050 }
00051
00052
00053
00054 free(ne); free(hs); return cp;
00055 }
00056
00057
00058
00059
00060
00061 void freeup_strings( int n , char **sar )
00062 {
00063 int ii ;
00064 if( sar == NULL ) return ;
00065 for( ii=0 ; ii < n ; ii++ )
00066 if( sar[ii] != NULL ) free(sar[ii]) ;
00067 free(sar) ;
00068 return ;
00069 }
00070
00071
00072
00073
00074
00075
00076
00077 #define DQUOT '"'
00078 #define SQUOT '\''
00079 #define NUL '\0'
00080
00081 int breakup_string( char *sin , char ***stok )
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' ){
00094
00095
00096
00097 while( isspace(*cpt) ) cpt++ ;
00098 if( *cpt == NUL ) break ;
00099
00100
00101
00102 if( *cpt == SQUOT || *cpt == DQUOT ){
00103 quote = 1 ; qch = *cpt ; cpt++ ;
00104 if( *cpt == NUL ) break ;
00105 } else {
00106 quote = 0 ;
00107 }
00108
00109
00110
00111 sss = cpt ;
00112 if( quote ){
00113 while( *cpt != NUL && *cpt != qch ) cpt++ ;
00114 } else {
00115 while( *cpt != NUL && !isspace(*cpt) ) cpt++ ;
00116 }
00117
00118
00119
00120 ll = cpt - sss ;
00121
00122
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
00131
00132 if( *cpt == NUL ) break ;
00133 cpt++ ;
00134 }
00135
00136 *stok = s_tok ; return n_tok ;
00137 }