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

Modified the code so it could accept quoted input. This is required for

multiple word node Reason values.
parent c06d45ea
No related branches found
No related tags found
No related merge requests found
...@@ -46,7 +46,6 @@ ...@@ -46,7 +46,6 @@
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 char *_strcasestr(char *haystack, char *needle); static char *_strcasestr(char *haystack, char *needle);
/* /*
...@@ -278,45 +277,32 @@ load_string (char **destination, char *keyword, char *in_line) ...@@ -278,45 +277,32 @@ load_string (char **destination, char *keyword, char *in_line)
str_ptr1 = (char *) _strcasestr (in_line, keyword); str_ptr1 = (char *) _strcasestr (in_line, keyword);
if (str_ptr1 != NULL) { if (str_ptr1 != NULL) {
int quoted = 0;
str_len1 = strlen (keyword); str_len1 = strlen (keyword);
strcpy (scratch, str_ptr1 + str_len1); if (str_ptr1[str_len1] == '"')
if ((scratch[0] == (char) NULL) || quoted = 1;
(isspace ((int) scratch[0]))) { strcpy (scratch, str_ptr1 + str_len1 + quoted);
/* keyword with no value set */ 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", info ("load_string : keyword %s lacks value",
keyword); keyword);
return EINVAL; return EINVAL;
} }
str_ptr2 = (char *) strtok_r (scratch, SEPCHARS, &str_ptr3); xfree (destination[0]);
str_len2 = strlen (str_ptr2);
if (destination[0] != NULL)
xfree (destination[0]);
destination[0] = (char *) xmalloc (str_len2 + 1); destination[0] = (char *) xmalloc (str_len2 + 1);
strcpy (destination[0], str_ptr2); 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] = ' '; str_ptr1[i] = ' ';
}
if (destination[0][0] == '"')
_remove_quotes (destination) ;
} }
return 0; 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() */ /* case insensitve version of strstr() */
static char * static char *
_strcasestr(char *haystack, char *needle) _strcasestr(char *haystack, char *needle)
......
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