Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/bin/sh sh: make find_command simpler



details:   https://anonhg.NetBSD.org/src/rev/2bc81b248155
branches:  trunk
changeset: 1024104:2bc81b248155
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Oct 10 08:19:02 2021 +0000

description:
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.

diffstat:

 bin/sh/exec.c |  46 +++++++++++++++++++---------------------------
 1 files changed, 19 insertions(+), 27 deletions(-)

diffs (67 lines):

diff -r ce359c440f07 -r 2bc81b248155 bin/sh/exec.c
--- a/bin/sh/exec.c     Sun Oct 10 07:50:53 2021 +0000
+++ b/bin/sh/exec.c     Sun Oct 10 08:19:02 2021 +0000
@@ -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 @@
 
        /* 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 */



Home | Main Index | Thread Index | Old Index