Skip to content
Snippets Groups Projects
Commit ccf592bf authored by Moe Jette's avatar Moe Jette
Browse files

Support case insensitive parsing of the slurm configuration file.

parent e2df5978
No related branches found
No related tags found
No related merge requests found
...@@ -43,14 +43,15 @@ ...@@ -43,14 +43,15 @@
#define BUF_SIZE 1024 #define BUF_SIZE 1024
#define SEPCHARS " \n\t" #define SEPCHARS " \n\t"
static int _load_long (long *destination, char *keyword, char *in_line) ; 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_integer (int *destination, char *keyword, char *in_line) ;
static int _load_float (float *destination, char *keyword, char *in_line) ; static int _load_float (float *destination, char *keyword, char *in_line) ;
static void _remove_quotes (char **destination) ; static void _remove_quotes (char **destination) ;
static char *_strcasestr(char *haystack, char *needle);
/* /*
* slurm_parser - parse the supplied specification into keyword/value pairs * 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 * specification is altered, overwriting the keyword and value pairs
* with spaces. * with spaces.
* spec - pointer to the string of specifications, sets of three values * spec - pointer to the string of specifications, sets of three values
...@@ -123,7 +124,7 @@ _load_float (float *destination, char *keyword, char *in_line) ...@@ -123,7 +124,7 @@ _load_float (float *destination, char *keyword, char *in_line)
char *str_ptr1, *str_ptr2, *str_ptr3; char *str_ptr1, *str_ptr2, *str_ptr3;
int i, str_len1, str_len2; int i, str_len1, str_len2;
str_ptr1 = (char *) strstr (in_line, keyword); str_ptr1 = (char *) _strcasestr (in_line, keyword);
if (str_ptr1 != NULL) { if (str_ptr1 != NULL) {
str_len1 = strlen (keyword); str_len1 = strlen (keyword);
strcpy (scratch, str_ptr1 + str_len1); strcpy (scratch, str_ptr1 + str_len1);
...@@ -161,7 +162,7 @@ _load_integer (int *destination, char *keyword, char *in_line) ...@@ -161,7 +162,7 @@ _load_integer (int *destination, char *keyword, char *in_line)
char *str_ptr1, *str_ptr2, *str_ptr3; char *str_ptr1, *str_ptr2, *str_ptr3;
int i, str_len1, str_len2; int i, str_len1, str_len2;
str_ptr1 = (char *) strstr (in_line, keyword); str_ptr1 = (char *) _strcasestr (in_line, keyword);
if (str_ptr1 != NULL) { if (str_ptr1 != NULL) {
str_len1 = strlen (keyword); str_len1 = strlen (keyword);
strcpy (scratch, str_ptr1 + str_len1); strcpy (scratch, str_ptr1 + str_len1);
...@@ -218,7 +219,7 @@ _load_long (long *destination, char *keyword, char *in_line) ...@@ -218,7 +219,7 @@ _load_long (long *destination, char *keyword, char *in_line)
char *str_ptr1, *str_ptr2, *str_ptr3; char *str_ptr1, *str_ptr2, *str_ptr3;
int i, str_len1, str_len2; int i, str_len1, str_len2;
str_ptr1 = (char *) strstr (in_line, keyword); str_ptr1 = (char *) _strcasestr (in_line, keyword);
if (str_ptr1 != NULL) { if (str_ptr1 != NULL) {
str_len1 = strlen (keyword); str_len1 = strlen (keyword);
strcpy (scratch, str_ptr1 + str_len1); strcpy (scratch, str_ptr1 + str_len1);
...@@ -275,7 +276,7 @@ load_string (char **destination, char *keyword, char *in_line) ...@@ -275,7 +276,7 @@ load_string (char **destination, char *keyword, char *in_line)
char *str_ptr1, *str_ptr2, *str_ptr3; char *str_ptr1, *str_ptr2, *str_ptr3;
int i, str_len1, str_len2; int i, str_len1, str_len2;
str_ptr1 = (char *) strstr (in_line, keyword); str_ptr1 = (char *) _strcasestr (in_line, keyword);
if (str_ptr1 != NULL) { if (str_ptr1 != NULL) {
str_len1 = strlen (keyword); str_len1 = strlen (keyword);
strcpy (scratch, str_ptr1 + str_len1); strcpy (scratch, str_ptr1 + str_len1);
...@@ -316,3 +317,26 @@ _remove_quotes (char **destination) ...@@ -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 */
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment