]> diplodocus.org Git - nmh/commitdiff
mhparam: exit(3) zero if all components found, else one.
authorRalph Corderoy <ralph@inputplus.co.uk>
Sun, 27 Aug 2017 19:04:42 +0000 (20:04 +0100)
committerRalph Corderoy <ralph@inputplus.co.uk>
Sun, 27 Aug 2017 19:04:42 +0000 (20:04 +0100)
The exit status used to be a count of the number missing, clipped to
120.  That doesn't seem useful, and is overhead to document, read, and
test.  Use the normal Unix 0 or 1 instead.

man/mhparam.man
test/mhparam/test-mhparam
uip/mhparam.c

index b4ee532..346417f 100644 (file)
@@ -143,11 +143,8 @@ is also useful in backquoted operations:
 % fgrep cornell.edu `mhpath +`/`mhparam aliasfile`
 .fi
 .SH "EXIT STATUS"
 % fgrep cornell.edu `mhpath +`/`mhparam aliasfile`
 .fi
 .SH "EXIT STATUS"
-.B mhparam
-returns the number of components that were not found,
-but limits the return value to 120 to avoid ambiguity,
-e.g.\& 127 is used by shells to indicate `command not found',
-and 256 would wrap to 0, falsely indicating success.
+The exit status is zero if all components are found,
+or one if any are missing.
 .
 .SH FILES
 .fc ^ ~
 .
 .SH FILES
 .fc ^ ~
index e2b9719..b532183 100755 (executable)
@@ -172,27 +172,15 @@ aliases"
 start_test "nonexistent component"
 run_test 'mhparam nonexistent' ''
 
 start_test "nonexistent component"
 run_test 'mhparam nonexistent' ''
 
-# check that return status counts nonexistent components
-start_test "return status counts nonexistent components"
-set +e
-mhparam path context nonexistent1 nonexistent2 nonexistent3 >/dev/null
-run_test "echo $?" 3
-set -e
-
-# And clips their numbers to avoid a misleading exit value.
-start_test "clips their numbers to avoid a misleading exit value"
-while read use want; do
-    r=0
-    #### Heirloom shell can't handle the backquote expression as the
-    #### argument:   with set -e, it exits immediately.
-    textlines=`yes nonexistent | sed ${use}q`
-    mhparam $textlines || r=$?
-    run_test "echo $r" $want
-done <<\E
-119 119
-120 120
-121 120
-E
+# check that exit status notes nonexistent components
+start_test "exit status notes nonexistent components"
+for c in 'missing' 'path missing' 'missing path' 'missing missing'; do
+    set +e
+    mhparam $c >/dev/null
+    e=$?
+    set -e
+    run_test "echo $e" 1
+done
 
 # mhparam -debug
 start_test "-debug"
 
 # mhparam -debug
 start_test "-debug"
index 1a392bb..3fc381b 100644 (file)
@@ -137,7 +137,8 @@ static char *p_find(char *) PURE;
 int
 main(int argc, char **argv)
 {
 int
 main(int argc, char **argv)
 {
-    int i, compp = 0, missed = 0;
+    int i, compp = 0;
+    bool missed;
     int all = 0, debug = 0;
     int components = -1;
     char *cp, buf[BUFSIZ], **argp;
     int all = 0, debug = 0;
     int components = -1;
     char *cp, buf[BUFSIZ], **argp;
@@ -232,6 +233,7 @@ main(int argc, char **argv)
 
     }
 
 
     }
 
+    missed = false;
     if (! all) {
         if (components < 0)
            components = compp > 1;
     if (! all) {
         if (components < 0)
            components = compp > 1;
@@ -252,13 +254,12 @@ main(int argc, char **argv)
                    printf("%s: ", comps[i]);
 
                puts(value);
                    printf("%s: ", comps[i]);
 
                puts(value);
-           } else if (missed < MAX_EXIT)
-               missed++;
+           } else
+                missed = true;
        }
     }
 
        }
     }
 
-    done (missed);
-    return 1;
+    done(missed);
 }
 
 
 }