X-Git-Url: https://git.octo.it/?p=collectd.git;a=blobdiff_plain;f=src%2Futils_parse_option.c;h=005715c9b1b4c81e7fa2a83e5441970255799ab0;hp=3652a666c2a73ef99a9c5563d712937cf88ffec0;hb=1159cb5d383c55a80a0db100b8f7aadcf44740a5;hpb=9c962b99a3acd77f1d6e2499052b47356819511a diff --git a/src/utils_parse_option.c b/src/utils_parse_option.c index 3652a666..005715c9 100644 --- a/src/utils_parse_option.c +++ b/src/utils_parse_option.c @@ -28,8 +28,7 @@ #include "utils_parse_option.h" -int parse_string (char **ret_buffer, char **ret_string) -{ +int parse_string(char **ret_buffer, char **ret_string) { char *buffer; char *string; @@ -37,31 +36,28 @@ int parse_string (char **ret_buffer, char **ret_string) /* Eat up leading spaces. */ string = buffer; - while (isspace ((int) *string)) + while (isspace((int)*string)) string++; if (*string == 0) - return (1); + return 1; /* A quoted string */ - if (*string == '"') - { + if (*string == '"') { char *dst; string++; if (*string == 0) - return (1); + return 1; dst = string; buffer = string; - while ((*buffer != '"') && (*buffer != 0)) - { + while ((*buffer != '"') && (*buffer != 0)) { /* Un-escape backslashes */ - if (*buffer == '\\') - { + if (*buffer == '\\') { buffer++; /* Catch a backslash at the end of buffer */ if (*buffer == 0) - return (-1); + return -1; } *dst = *buffer; buffer++; @@ -69,7 +65,7 @@ int parse_string (char **ret_buffer, char **ret_string) } /* No quote sign has been found */ if (*buffer == 0) - return (-1); + return -1; *dst = 0; dst++; @@ -77,29 +73,27 @@ int parse_string (char **ret_buffer, char **ret_string) buffer++; /* Check for trailing spaces. */ - if ((*buffer != 0) && !isspace ((int) *buffer)) - return (-1); - } - else /* an unquoted string */ + if ((*buffer != 0) && !isspace((int)*buffer)) + return -1; + } else /* an unquoted string */ { buffer = string; - while ((*buffer != 0) && !isspace ((int) *buffer)) + while ((*buffer != 0) && !isspace((int)*buffer)) buffer++; - if (*buffer != 0) - { + if (*buffer != 0) { *buffer = 0; buffer++; } } /* Eat up trailing spaces */ - while (isspace ((int) *buffer)) + while (isspace((int)*buffer)) buffer++; *ret_buffer = buffer; *ret_string = string; - return (0); + return 0; } /* int parse_string */ /* @@ -113,8 +107,7 @@ int parse_string (char **ret_buffer, char **ret_string) * However, if the value does *not* contain a space character, you can skip * the quotes. */ -int parse_option (char **ret_buffer, char **ret_key, char **ret_value) -{ +int parse_option(char **ret_buffer, char **ret_key, char **ret_value) { char *buffer; char *key; char *value; @@ -124,26 +117,26 @@ int parse_option (char **ret_buffer, char **ret_key, char **ret_value) /* Eat up leading spaces */ key = buffer; - while (isspace ((int) *key)) + while (isspace((int)*key)) key++; if (*key == 0) - return (1); + return 1; /* Look for the equal sign */ buffer = key; - while (isalnum ((int) *buffer) || *buffer == '_' || *buffer == ':') + while (isalnum((int)*buffer) || *buffer == '_' || *buffer == ':') buffer++; if ((*buffer != '=') || (buffer == key)) - return (1); + return 1; *buffer = 0; buffer++; /* Empty values must be written as "" */ - if (isspace ((int) *buffer) || (*buffer == 0)) - return (-1); + if (isspace((int)*buffer) || (*buffer == 0)) + return -1; - status = parse_string (&buffer, &value); + status = parse_string(&buffer, &value); if (status != 0) - return (-1); + return -1; /* NB: parse_string will have eaten up all trailing spaces. */ @@ -151,7 +144,5 @@ int parse_option (char **ret_buffer, char **ret_key, char **ret_value) *ret_key = key; *ret_value = value; - return (0); + return 0; } /* int parse_option */ - -/* vim: set sw=2 ts=8 tw=78 et : */