]> git.refcnt.org Git - colorize.git/commitdiff
assign_conf(): reduce code duplication
authorSteven Schubiger <stsc@refcnt.org>
Wed, 25 Mar 2020 22:22:28 +0000 (23:22 +0100)
committerSteven Schubiger <stsc@refcnt.org>
Wed, 25 Mar 2020 22:22:28 +0000 (23:22 +0100)
colorize.c

index 1638f5f24ee959099f0e8f5153555717a6ffa117..50011e29615c986320137e200fa33e5ad801d07b 100644 (file)
@@ -745,29 +745,22 @@ parse_conf (const char *conf_file, struct conf *config)
     fclose (conf);
 }
 
+#define ASSIGN_CONF(str,val) do { \
+    free (str);                   \
+    str = val;                    \
+} while (false)
+
 static void
 assign_conf (const char *conf_file, struct conf *config, const char *cfg, char *val)
 {
     if (streq (cfg, "attr"))
-      {
-        free (config->attr);
-        config->attr = val;
-      }
+      ASSIGN_CONF (config->attr, val);
     else if (streq (cfg, "color"))
-      {
-        free (config->color);
-        config->color = val;
-      }
+      ASSIGN_CONF (config->color, val);
     else if (streq (cfg, "exclude-random"))
-      {
-        free (config->exclude_random);
-        config->exclude_random = val;
-      }
+      ASSIGN_CONF (config->exclude_random, val);
     else if (streq (cfg, "omit-color-empty"))
-      {
-        free (config->omit_color_empty);
-        config->omit_color_empty = val;
-      }
+      ASSIGN_CONF (config->omit_color_empty, val);
     else
       vfprintf_fail (formats[FMT_CONF], conf_file, cfg, "not recognized");
 }