Source-Changes-HG archive

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

[src/trunk]: src/usr.bin/indent indent: clean up argument handling



details:   https://anonhg.NetBSD.org/src/rev/208e9894b88d
branches:  trunk
changeset: 1023769:208e9894b88d
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Sep 25 22:16:58 2021 +0000

description:
indent: clean up argument handling

No functional change.

diffstat:

 usr.bin/indent/args.c |  32 +++++++++++++++++---------------
 1 files changed, 17 insertions(+), 15 deletions(-)

diffs (101 lines):

diff -r ca7b4bfc7c05 -r 208e9894b88d usr.bin/indent/args.c
--- a/usr.bin/indent/args.c     Sat Sep 25 22:14:21 2021 +0000
+++ b/usr.bin/indent/args.c     Sat Sep 25 22:16:58 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: args.c,v 1.29 2021/09/25 21:42:43 rillig Exp $ */
+/*     $NetBSD: args.c,v 1.30 2021/09/25 22:16:58 rillig Exp $ */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: args.c,v 1.29 2021/09/25 21:42:43 rillig Exp $");
+__RCSID("$NetBSD: args.c,v 1.30 2021/09/25 22:16:58 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/args.c 336318 2018-07-15 21:04:21Z pstef $");
 #endif
@@ -87,7 +87,7 @@
 
 const char *option_source = "?";
 
-void add_typedefs_from_file(const char *str);
+void add_typedefs_from_file(const char *);
 
 #if __STDC_VERSION__ >= 201112L
 #define assert_type(expr, type) _Generic((expr), type : (expr))
@@ -247,13 +247,13 @@
 }
 
 static const char *
-eqin(const char *s1, const char *s2)
+skip_over(const char *s, const char *prefix)
 {
-    while (*s1 != '\0') {
-       if (*s1++ != *s2++)
+    while (*prefix != '\0') {
+       if (*prefix++ != *s++)
            return NULL;
     }
-    return s2;
+    return s;
 }
 
 void
@@ -264,9 +264,11 @@
 
     arg++;                     /* ignore leading "-" */
     for (p = pro; p->p_name[0] != '\0'; p++)
-       if (*p->p_name == *arg && (param_start = eqin(p->p_name, arg)) != NULL)
-           goto found;
+       if (p->p_name[0] == arg[0])
+           if ((param_start = skip_over(arg, p->p_name)) != NULL)
+               goto found;
     errx(1, "%s: unknown parameter \"%s\"", option_source, arg - 1);
+
 found:
     switch (p->p_type) {
 
@@ -277,7 +279,7 @@
            break;
 
        case CLI:
-           if (*param_start == 0)
+           if (param_start[0] == '\0')
                goto need_param;
            opt.case_indent = atof(param_start);
            break;
@@ -290,13 +292,13 @@
            break;
 
        case KEY:
-           if (*param_start == 0)
+           if (param_start[0] == '\0')
                goto need_param;
            add_typename(param_start);
            break;
 
        case KEY_FILE:
-           if (*param_start == 0)
+           if (param_start[0] == '\0')
                goto need_param;
            add_typedefs_from_file(param_start);
            break;
@@ -329,13 +331,13 @@
 }
 
 void
-add_typedefs_from_file(const char *str)
+add_typedefs_from_file(const char *fname)
 {
     FILE *file;
     char line[BUFSIZ];
 
-    if ((file = fopen(str, "r")) == NULL) {
-       fprintf(stderr, "indent: cannot open file %s\n", str);
+    if ((file = fopen(fname, "r")) == NULL) {
+       fprintf(stderr, "indent: cannot open file %s\n", fname);
        exit(1);
     }
     while ((fgets(line, BUFSIZ, file)) != NULL) {



Home | Main Index | Thread Index | Old Index