diff --git a/src/common/parse_spec.c b/src/common/parse_spec.c index 5160f61ce9e5d186d003d235e13c3d774f33e2aa..eb855a966706690d9aea43596de4061962659a3e 100644 --- a/src/common/parse_spec.c +++ b/src/common/parse_spec.c @@ -43,14 +43,15 @@ #define BUF_SIZE 1024 #define SEPCHARS " \n\t" -static int _load_long (long *destination, char *keyword, char *in_line) ; -static int _load_integer (int *destination, char *keyword, char *in_line) ; -static int _load_float (float *destination, char *keyword, char *in_line) ; -static void _remove_quotes (char **destination) ; +static int _load_long (long *destination, char *keyword, char *in_line) ; +static int _load_integer (int *destination, char *keyword, char *in_line) ; +static int _load_float (float *destination, char *keyword, char *in_line) ; +static void _remove_quotes (char **destination) ; +static char *_strcasestr(char *haystack, char *needle); /* * slurm_parser - parse the supplied specification into keyword/value pairs - * only the keywords supplied will be searched for. the supplied + * only the keywords supplied will be searched for. The supplied * specification is altered, overwriting the keyword and value pairs * with spaces. * spec - pointer to the string of specifications, sets of three values @@ -123,7 +124,7 @@ _load_float (float *destination, char *keyword, char *in_line) char *str_ptr1, *str_ptr2, *str_ptr3; int i, str_len1, str_len2; - str_ptr1 = (char *) strstr (in_line, keyword); + str_ptr1 = (char *) _strcasestr (in_line, keyword); if (str_ptr1 != NULL) { str_len1 = strlen (keyword); strcpy (scratch, str_ptr1 + str_len1); @@ -161,7 +162,7 @@ _load_integer (int *destination, char *keyword, char *in_line) char *str_ptr1, *str_ptr2, *str_ptr3; int i, str_len1, str_len2; - str_ptr1 = (char *) strstr (in_line, keyword); + str_ptr1 = (char *) _strcasestr (in_line, keyword); if (str_ptr1 != NULL) { str_len1 = strlen (keyword); strcpy (scratch, str_ptr1 + str_len1); @@ -218,7 +219,7 @@ _load_long (long *destination, char *keyword, char *in_line) char *str_ptr1, *str_ptr2, *str_ptr3; int i, str_len1, str_len2; - str_ptr1 = (char *) strstr (in_line, keyword); + str_ptr1 = (char *) _strcasestr (in_line, keyword); if (str_ptr1 != NULL) { str_len1 = strlen (keyword); strcpy (scratch, str_ptr1 + str_len1); @@ -275,7 +276,7 @@ load_string (char **destination, char *keyword, char *in_line) char *str_ptr1, *str_ptr2, *str_ptr3; int i, str_len1, str_len2; - str_ptr1 = (char *) strstr (in_line, keyword); + str_ptr1 = (char *) _strcasestr (in_line, keyword); if (str_ptr1 != NULL) { str_len1 = strlen (keyword); strcpy (scratch, str_ptr1 + str_len1); @@ -316,3 +317,26 @@ _remove_quotes (char **destination) } } +/* case insensitve version of strstr() */ +static char * +_strcasestr(char *haystack, char *needle) +{ + int hay_inx, hay_size = strlen(haystack); + int need_inx, need_size = strlen(needle); + char *hay_ptr = haystack; + + for (hay_inx=0; hay_inx<hay_size; hay_inx++) { + for (need_inx=0; need_inx<need_size; need_inx++) { + if (tolower((int) hay_ptr[need_inx]) != + tolower((int) needle [need_inx])) + break; /* mis-match */ + } + + if (need_inx == need_size) /* it matched */ + return hay_ptr; + else /* keep looking */ + hay_ptr++; + } + + return NULL; /* no match anywhere in string */ +}