Module Name: src Committed By: rillig Date: Sun Oct 10 08:19:02 UTC 2021
Modified Files: src/bin/sh: exec.c Log Message: sh: make find_command simpler Lint complained about the do-while-0 loop that contained a continue. It didn't state the reason for it, but indeed the code looked complicated. Rewrite the code to be less verbose and to use common coding patterns. No functional change. To generate a diff of this commit: cvs rdiff -u -r1.55 -r1.56 src/bin/sh/exec.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/bin/sh/exec.c diff -u src/bin/sh/exec.c:1.55 src/bin/sh/exec.c:1.56 --- src/bin/sh/exec.c:1.55 Tue Feb 16 15:30:12 2021 +++ src/bin/sh/exec.c Sun Oct 10 08:19:02 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: exec.c,v 1.55 2021/02/16 15:30:12 kre Exp $ */ +/* $NetBSD: exec.c,v 1.56 2021/10/10 08:19:02 rillig Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)exec.c 8.4 (Berkeley) 6/8/95"; #else -__RCSID("$NetBSD: exec.c,v 1.55 2021/02/16 15:30:12 kre Exp $"); +__RCSID("$NetBSD: exec.c,v 1.56 2021/10/10 08:19:02 rillig Exp $"); #endif #endif /* not lint */ @@ -548,31 +548,23 @@ find_command(char *name, struct cmdentry /* If name is in the table, check answer will be ok */ if ((cmdp = cmdlookup(name, 0)) != NULL) { - do { - switch (cmdp->cmdtype) { - case CMDNORMAL: - if (act & DO_ALTPATH) { - cmdp = NULL; - continue; - } - break; - case CMDFUNCTION: - if (act & DO_NOFUNC) { - cmdp = NULL; - continue; - } - break; - case CMDBUILTIN: - if ((act & DO_ALTBLTIN) || builtinloc >= 0) { - cmdp = NULL; - continue; - } - break; - } - /* if not invalidated by cd, we're done */ - if (cmdp->rehash == 0) - goto success; - } while (0); + switch (cmdp->cmdtype) { + case CMDNORMAL: + if (act & DO_ALTPATH) + cmdp = NULL; + break; + case CMDFUNCTION: + if (act & DO_NOFUNC) + cmdp = NULL; + break; + case CMDBUILTIN: + if ((act & DO_ALTBLTIN) || builtinloc >= 0) + cmdp = NULL; + break; + } + /* if not invalidated by cd, we're done */ + if (cmdp != NULL && cmdp->rehash == 0) + goto success; } /* If %builtin not in path, check for builtin next */