From: Ralph Corderoy Date: Sun, 23 Apr 2017 12:33:57 +0000 (+0100) Subject: tws.h: Remove zero-valued TW_SNIL macro, used once. X-Git-Url: https://diplodocus.org/git/nmh/commitdiff_plain/7ec0c9a0229aa160d7419922d2f4ba7e87480cd6?hp=4db310433eb20ec95643299b0d14fefaea44b8bd tws.h: Remove zero-valued TW_SNIL macro, used once. Macro TW_SNIL was the zero value for a two-bit field. It was only used once, and that is better ordered to check for bits set with none set being the last, else, case, rather than in the middle. Kept the behaviour of undefined value 3 being treated as TW_SIMP, 2. --- diff --git a/h/tws.h b/h/tws.h index 03964b60..66e33613 100644 --- a/h/tws.h +++ b/h/tws.h @@ -25,7 +25,6 @@ struct tws { #define TW_NULL 0x0000 #define TW_SDAY 0x0003 /* how day-of-week was determined */ -#define TW_SNIL 0x0000 /* not given */ #define TW_SEXP 0x0001 /* explicitly given */ #define TW_SIMP 0x0002 /* implicitly given */ diff --git a/sbr/dtime.c b/sbr/dtime.c index d24694ea..53c56578 100644 --- a/sbr/dtime.c +++ b/sbr/dtime.c @@ -249,6 +249,7 @@ dasctime (struct tws *tw, int flags) { char buffer[80]; static char result[80]; + int twf; if (!tw) return NULL; @@ -264,13 +265,13 @@ dasctime (struct tws *tw, int flags) tw->tw_year < 100 ? 2 : 4, tw->tw_year, tw->tw_hour, tw->tw_min, tw->tw_sec, result); - if ((tw->tw_flags & TW_SDAY) == TW_SEXP) - snprintf (result, sizeof(result), "%s, %s", tw_dotw[tw->tw_wday], buffer); - else - if ((tw->tw_flags & TW_SDAY) == TW_SNIL) - strncpy (result, buffer, sizeof(result)); - else - snprintf (result, sizeof(result), "%s (%s)", buffer, tw_dotw[tw->tw_wday]); + if ((twf = tw->tw_flags & TW_SDAY)) { + if (twf == TW_SEXP) + snprintf(result, sizeof(result), "%s, %s", tw_dotw[tw->tw_wday], buffer); + else + snprintf(result, sizeof(result), "%s (%s)", buffer, tw_dotw[tw->tw_wday]); + } else + strncpy(result, buffer, sizeof(result)); return result; }