From: Max Kellermann Date: Thu, 25 Dec 2008 13:31:00 +0000 (+0100) Subject: conf: simplified parse_key_value() X-Git-Tag: release-0.13~34 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=c2bb3eb2148fd88fe7a18af29a65251f20231fb8;p=ncmpc.git conf: simplified parse_key_value() Removed the state machine stuff, and use strtol() if the first character is not a single quote. strtol() will do the error checking. --- diff --git a/src/conf.c b/src/conf.c index e3875e3..3411ed8 100644 --- a/src/conf.c +++ b/src/conf.c @@ -72,14 +72,6 @@ #define CONF_VISIBLE_BITRATE "visible-bitrate" #define CONF_WELCOME_SCREEN_LIST "welcome-screen-list" -typedef enum { - KEY_PARSER_UNKNOWN, - KEY_PARSER_CHAR, - KEY_PARSER_DEC, - KEY_PARSER_HEX, - KEY_PARSER_DONE -} key_parser_state_t; - static bool str2bool(char *str) { @@ -98,69 +90,23 @@ print_error(const char *msg, const char *input) static int parse_key_value(char *str, char **end) { - size_t len = strlen(str); - size_t i; - int value; - key_parser_state_t state; - - i=0; - value=0; - state=KEY_PARSER_UNKNOWN; - *end = str; - - while (i < len && state != KEY_PARSER_DONE) { - int next = 0; - int c = str[i]; - - if( i+1 str+len ) - *end = str+len; + *end = str + 3; + return str[1]; + } else { + long value = strtol(str, end, 0); + if (*end == str) { + print_error(_("Unsupported key definition"), str); + return -1; + } - return value; + return (int)value; + } } static int