From 6b14d2ef1e932b68ea94a7a89b2dedc797a6ea0f Mon Sep 17 00:00:00 2001 From: Moe Jette <jette1@llnl.gov> Date: Wed, 9 Jul 2003 21:49:48 +0000 Subject: [PATCH] Modified the code so it could accept quoted input. This is required for multiple word node Reason values. --- src/common/parse_spec.c | 42 ++++++++++++++--------------------------- 1 file changed, 14 insertions(+), 28 deletions(-) diff --git a/src/common/parse_spec.c b/src/common/parse_spec.c index eb855a96670..3340cd1cda6 100644 --- a/src/common/parse_spec.c +++ b/src/common/parse_spec.c @@ -46,7 +46,6 @@ 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); /* @@ -278,45 +277,32 @@ load_string (char **destination, char *keyword, char *in_line) str_ptr1 = (char *) _strcasestr (in_line, keyword); if (str_ptr1 != NULL) { + int quoted = 0; str_len1 = strlen (keyword); - strcpy (scratch, str_ptr1 + str_len1); - if ((scratch[0] == (char) NULL) || - (isspace ((int) scratch[0]))) { - /* keyword with no value set */ + if (str_ptr1[str_len1] == '"') + quoted = 1; + strcpy (scratch, str_ptr1 + str_len1 + quoted); + if (quoted) + str_ptr2 = strtok_r (scratch, "\042\n", &str_ptr3); + else + str_ptr2 = strtok_r (scratch, SEPCHARS, &str_ptr3); + if ((str_ptr2 == NULL) || + ((str_len2 = strlen (str_ptr2))== 0)){ info ("load_string : keyword %s lacks value", keyword); return EINVAL; } - str_ptr2 = (char *) strtok_r (scratch, SEPCHARS, &str_ptr3); - str_len2 = strlen (str_ptr2); - if (destination[0] != NULL) - xfree (destination[0]); + xfree (destination[0]); destination[0] = (char *) xmalloc (str_len2 + 1); strcpy (destination[0], str_ptr2); - for (i = 0; i < (str_len1 + str_len2); i++) { + for (i = 0; i < (str_len1 + str_len2 + quoted); i++) + str_ptr1[i] = ' '; + if (quoted && (str_ptr1[i] == '"')) str_ptr1[i] = ' '; - } - if (destination[0][0] == '"') - _remove_quotes (destination) ; } return 0; } -/* give a string starting and ending with '"', remove the quotes */ -static void -_remove_quotes (char **destination) -{ - int i; - - for (i=0; ; i++) { - destination[0][i] = destination[0][i+1]; - if (destination[0][i] == '"') - destination[0][i] = '\0'; - if (destination[0][i] == '\0') - break; - } -} - /* case insensitve version of strstr() */ static char * _strcasestr(char *haystack, char *needle) -- GitLab