From: Daniel Mueller Date: Fri, 17 Nov 2017 14:58:12 +0000 (-0800) Subject: i3bar: replace magic numbers with more meaningful constructs X-Git-Tag: 4.15~38^2 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=refs%2Fpull%2F3052%2Fhead;p=i3%2Fi3 i3bar: replace magic numbers with more meaningful constructs In i3bar/src/config.c we compare string lengths agains magic numbers. This change replaces those numbers with the lengths of the strings they represent. --- diff --git a/i3bar/src/config.c b/i3bar/src/config.c index cbe84d50..b98d4123 100644 --- a/i3bar/src/config.c +++ b/i3bar/src/config.c @@ -107,34 +107,34 @@ static int config_string_cb(void *params_, const unsigned char *val, size_t _len if (!strcmp(cur_key, "mode")) { DLOG("mode = %.*s, len = %d\n", len, val, len); - config.hide_on_modifier = (len == 4 && !strncmp((const char *)val, "dock", strlen("dock")) ? M_DOCK - : (len == 4 && !strncmp((const char *)val, "hide", strlen("hide")) ? M_HIDE - : M_INVISIBLE)); + config.hide_on_modifier = (len == strlen("dock") && !strncmp((const char *)val, "dock", strlen("dock")) ? M_DOCK + : (len == strlen("hide") && !strncmp((const char *)val, "hide", strlen("hide")) ? M_HIDE + : M_INVISIBLE)); return 1; } if (!strcmp(cur_key, "hidden_state")) { DLOG("hidden_state = %.*s, len = %d\n", len, val, len); - config.hidden_state = (len == 4 && !strncmp((const char *)val, "hide", strlen("hide")) ? S_HIDE : S_SHOW); + config.hidden_state = (len == strlen("hide") && !strncmp((const char *)val, "hide", strlen("hide")) ? S_HIDE : S_SHOW); return 1; } if (!strcmp(cur_key, "modifier")) { DLOG("modifier = %.*s\n", len, val); - if (len == 4 && !strncmp((const char *)val, "none", strlen("none"))) { + if (len == strlen("none") && !strncmp((const char *)val, "none", strlen("none"))) { config.modifier = XCB_NONE; return 1; } - if (len == 5 && !strncmp((const char *)val, "shift", strlen("shift"))) { + if (len == strlen("shift") && !strncmp((const char *)val, "shift", strlen("shift"))) { config.modifier = ShiftMask; return 1; } - if (len == 4 && !strncmp((const char *)val, "ctrl", strlen("ctrl"))) { + if (len == strlen("ctrl") && !strncmp((const char *)val, "ctrl", strlen("ctrl"))) { config.modifier = ControlMask; return 1; } - if (len == 4 && !strncmp((const char *)val, "Mod", strlen("Mod"))) { + if (len == strlen("Mod") + 1 && !strncmp((const char *)val, "Mod", strlen("Mod"))) { switch (val[3]) { case '1': config.modifier = Mod1Mask; @@ -179,7 +179,7 @@ static int config_string_cb(void *params_, const unsigned char *val, size_t _len if (!strcmp(cur_key, "position")) { DLOG("position = %.*s\n", len, val); - config.position = (len == 3 && !strncmp((const char *)val, "top", strlen("top")) ? POS_TOP : POS_BOT); + config.position = (len == strlen("top") && !strncmp((const char *)val, "top", strlen("top")) ? POS_TOP : POS_BOT); return 1; }