From bca8fcaa2052031f0275622a2712e6d6d317a862 Mon Sep 17 00:00:00 2001 From: Jonas Fonseca Date: Wed, 7 Jun 2006 00:43:24 +0200 Subject: [PATCH] Factor out set_option_color from set_option --- tig.c | 72 ++++++++++++++++++++++++++++++++++------------------------- 1 file changed, 41 insertions(+), 31 deletions(-) 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; } -- 2.30.2