Module Name: src Committed By: rillig Date: Sun Nov 15 09:54:16 UTC 2020
Modified Files: src/usr.bin/make: main.c Log Message: make(1): clean up ParseBoolean To generate a diff of this commit: cvs rdiff -u -r1.473 -r1.474 src/usr.bin/make/main.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.bin/make/main.c diff -u src/usr.bin/make/main.c:1.473 src/usr.bin/make/main.c:1.474 --- src/usr.bin/make/main.c:1.473 Sun Nov 15 09:38:44 2020 +++ src/usr.bin/make/main.c Sun Nov 15 09:54:16 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: main.c,v 1.473 2020/11/15 09:38:44 rillig Exp $ */ +/* $NetBSD: main.c,v 1.474 2020/11/15 09:54:16 rillig Exp $ */ /* * Copyright (c) 1988, 1989, 1990, 1993 @@ -109,7 +109,7 @@ #include "trace.h" /* "@(#)main.c 8.3 (Berkeley) 3/19/94" */ -MAKE_RCSID("$NetBSD: main.c,v 1.473 2020/11/15 09:38:44 rillig Exp $"); +MAKE_RCSID("$NetBSD: main.c,v 1.474 2020/11/15 09:54:16 rillig Exp $"); #if defined(MAKE_NATIVE) && !defined(lint) __COPYRIGHT("@(#) Copyright (c) 1988, 1989, 1990, 1993 " "The Regents of the University of California. " @@ -2225,27 +2225,19 @@ mkTempFile(const char *pattern, char **o } /* - * Convert a string representation of a boolean. - * Anything that looks like "No", "False", "Off", "0" etc, - * is FALSE, otherwise TRUE. + * Convert a string representation of a boolean into a boolean value. + * Anything that looks like "No", "False", "Off", "0" etc. is FALSE, + * the empty string is the fallback, everything else is TRUE. */ Boolean -ParseBoolean(const char *s, Boolean bf) +ParseBoolean(const char *s, Boolean fallback) { - switch (s[0]) { - case '\0': /* not set - the default wins */ - break; - case '0': - case 'F': - case 'f': - case 'N': - case 'n': + char ch = ch_tolower(s[0]); + if (ch == '\0') + return fallback; + if (ch == '0' || ch == 'f' || ch == 'n') return FALSE; - case 'O': - case 'o': - return s[1] != 'F' && s[1] != 'f'; - default: - return TRUE; - } - return bf; + if (ch == 'o') + return ch_tolower(s[1]) != 'f'; + return TRUE; }