From: Jonas Fonseca Date: Tue, 6 Jun 2006 22:43:24 +0000 (+0200) Subject: Factor out set_option_color from set_option X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=bca8fcaa2052031f0275622a2712e6d6d317a862;p=tig.git Factor out set_option_color from set_option --- diff --git a/tig.c b/tig.c index 027a8b7..d9ac165 100644 --- a/tig.c +++ b/tig.c @@ -638,45 +638,55 @@ static int config_lineno; static bool config_errors; static char *config_msg; +/* Reads + * + * object fgcolor bgcolor [attr] + * + * from the value string. */ static int -set_option(char *opt, int optlen, char *value, int valuelen) +set_option_color(char *value, int valuelen) { - /* Reads: "color" object fgcolor bgcolor [attr] */ - if (!strcmp(opt, "color")) { - struct line_info *info; - - value = chomp_string(value); - valuelen = strcspn(value, " \t"); - info = get_line_info(value, valuelen); - if (!info) { - config_msg = "Unknown color name"; - return ERR; - } + struct line_info *info; - value = chomp_string(value + valuelen); - valuelen = strcspn(value, " \t"); - if (set_color(&info->fg, value, valuelen) == ERR) { - config_msg = "Unknown color"; - return ERR; - } + value = chomp_string(value); + valuelen = strcspn(value, " \t"); + info = get_line_info(value, valuelen); + if (!info) { + config_msg = "Unknown color name"; + return ERR; + } - value = chomp_string(value + valuelen); - valuelen = strcspn(value, " \t"); - if (set_color(&info->bg, value, valuelen) == ERR) { - config_msg = "Unknown color"; - return ERR; - } + value = chomp_string(value + valuelen); + valuelen = strcspn(value, " \t"); + if (set_color(&info->fg, value, valuelen) == ERR) { + config_msg = "Unknown color"; + return ERR; + } - value = chomp_string(value + valuelen); - if (*value && - set_attribute(&info->attr, value, strlen(value)) == ERR) { - config_msg = "Unknown attribute"; - return ERR; - } + value = chomp_string(value + valuelen); + valuelen = strcspn(value, " \t"); + if (set_color(&info->bg, value, valuelen) == ERR) { + config_msg = "Unknown color"; + return ERR; + } - return OK; + value = chomp_string(value + valuelen); + if (*value && + set_attribute(&info->attr, value, strlen(value)) == ERR) { + config_msg = "Unknown attribute"; + return ERR; } + return OK; +} + +static int +set_option(char *opt, int optlen, char *value, int valuelen) +{ + if (optlen == STRING_SIZE("color") && + !strncmp(opt, "color", optlen)) + return set_option_color(value, valuelen); + return ERR; }