Code

Factor out set_option_color from set_option
authorJonas Fonseca <fonseca@diku.dk>
Tue, 6 Jun 2006 22:43:24 +0000 (00:43 +0200)
committerJonas Fonseca Madsen <fonseca@ask.diku.dk>
Tue, 6 Jun 2006 22:43:24 +0000 (00:43 +0200)
tig.c

diff --git a/tig.c b/tig.c
index 027a8b766395e1cea6151b223ad8e50a5a8640db..d9ac165ade6e05b4b528cea7226464bbbe3bef12 100644 (file)
--- 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;
 }