aboutsummaryrefslogtreecommitdiffstats
path: root/colorize.c
diff options
context:
space:
mode:
authorGravatar Steven Schubiger <stsc@refcnt.org> 2020-03-25 23:22:28 +0100
committerGravatar Steven Schubiger <stsc@refcnt.org> 2020-03-25 23:22:28 +0100
commiteace71293190208f443973a9e385ca69da504863 (patch)
tree4843109306cd7c50faacb71277a2efc759243b25 /colorize.c
parentd7c84d2ae897eb414a8d0de03852bbb8a9204068 (diff)
downloadcolorize-eace71293190208f443973a9e385ca69da504863.tar.gz
colorize-eace71293190208f443973a9e385ca69da504863.tar.bz2
assign_conf(): reduce code duplication
Diffstat (limited to 'colorize.c')
-rw-r--r--colorize.c25
1 files changed, 9 insertions, 16 deletions
diff --git a/colorize.c b/colorize.c
index 1638f5f..50011e2 100644
--- a/colorize.c
+++ b/colorize.c
@@ -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");
}