Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/xlint/lint1 lint: clean up check for getopt



details:   https://anonhg.NetBSD.org/src/rev/1fb16cb6f9f5
branches:  trunk
changeset: 980834:1fb16cb6f9f5
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Feb 20 10:01:27 2021 +0000

description:
lint: clean up check for getopt

The original options string is not needed during the check.  Having only
the unhandled options suffices.

No functional change.

diffstat:

 usr.bin/xlint/lint1/ckgetopt.c |  20 ++++++++------------
 1 files changed, 8 insertions(+), 12 deletions(-)

diffs (73 lines):

diff -r 6f26c0fb71bc -r 1fb16cb6f9f5 usr.bin/xlint/lint1/ckgetopt.c
--- a/usr.bin/xlint/lint1/ckgetopt.c    Sat Feb 20 09:57:02 2021 +0000
+++ b/usr.bin/xlint/lint1/ckgetopt.c    Sat Feb 20 10:01:27 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ckgetopt.c,v 1.4 2021/02/20 09:57:02 rillig Exp $ */
+/* $NetBSD: ckgetopt.c,v 1.5 2021/02/20 10:01:27 rillig Exp $ */
 
 /*-
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: ckgetopt.c,v 1.4 2021/02/20 09:57:02 rillig Exp $");
+__RCSID("$NetBSD: ckgetopt.c,v 1.5 2021/02/20 10:01:27 rillig Exp $");
 #endif
 
 #include <stdbool.h>
@@ -61,12 +61,11 @@
 
        /*
         * The options string from the getopt call.  Whenever an option is
-        * handled by a case label, it is set to ' ' in unhandled_options.
-        * In the end, only ' ' and ':' should remain in unhandled_options.
+        * handled by a case label, it is set to ' '.  In the end, only ' '
+        * and ':' should remain.
         */
        pos_t options_pos;
        char *options;
-       char *unhandled_options;
 
        /*
         * The nesting level of switch statements, is only modified if
@@ -123,9 +122,9 @@
        if (opt == '?')
                return;
 
-       const char *optptr = strchr(ck.options, opt);
+       char *optptr = strchr(ck.options, opt);
        if (optptr != NULL)
-               ck.unhandled_options[optptr - ck.options] = ' ';
+               *optptr = ' ';
        else {
                /* option '%c' should be listed in the options string */
                warning(339, opt);
@@ -136,9 +135,9 @@
 static void
 check_unhandled_option(void)
 {
-       lint_assert(ck.unhandled_options != NULL);
+       lint_assert(ck.options != NULL);
 
-       for (const char *opt = ck.unhandled_options; *opt != '\0'; opt++) {
+       for (const char *opt = ck.options; *opt != '\0'; opt++) {
                if (*opt == ' ' || *opt == ':')
                        continue;
 
@@ -157,7 +156,6 @@
        if (ck.while_level == 0) {
                if (!is_getopt_call(tn, &ck.options))
                        return;
-               ck.unhandled_options = xstrdup(ck.options);
                ck.options_pos = curr_pos;
        }
        ck.while_level++;
@@ -200,7 +198,5 @@
                return;
 
        free(ck.options);
-       free(ck.unhandled_options);
        ck.options = NULL;
-       ck.unhandled_options = NULL;
 }



Home | Main Index | Thread Index | Old Index