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 outfstrg, which writes fo...



details:   https://anonhg.NetBSD.org/src/rev/3dd7e47d584a
branches:  trunk
changeset: 1023362:3dd7e47d584a
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Sep 04 14:58:42 2021 +0000

description:
lint: clean up outfstrg, which writes format strings

Most characters don't need outqchar, a simple outchar is often enough.

Since '\0' is not a digit, there is no need to check for that.

No functional change.

diffstat:

 usr.bin/xlint/lint1/emit1.c |  43 ++++++++++++++++++++++---------------------
 1 files changed, 22 insertions(+), 21 deletions(-)

diffs (111 lines):

diff -r d3f108e17588 -r 3dd7e47d584a usr.bin/xlint/lint1/emit1.c
--- a/usr.bin/xlint/lint1/emit1.c       Sat Sep 04 14:48:27 2021 +0000
+++ b/usr.bin/xlint/lint1/emit1.c       Sat Sep 04 14:58:42 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: emit1.c,v 1.56 2021/09/04 14:48:27 rillig Exp $ */
+/* $NetBSD: emit1.c,v 1.57 2021/09/04 14:58:42 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: emit1.c,v 1.56 2021/09/04 14:48:27 rillig Exp $");
+__RCSID("$NetBSD: emit1.c,v 1.57 2021/09/04 14:58:42 rillig Exp $");
 #endif
 
 #include "lint1.h"
@@ -488,13 +488,13 @@
 static void
 outfstrg(strg_t *strg)
 {
-       unsigned char c, oc;
+       char c, oc;
        bool    first;
-       unsigned char *cp;
+       const char *cp;
 
        lint_assert(strg->st_tspec == CHAR);
 
-       cp = strg->st_cp;
+       cp = (const char *)strg->st_cp;
 
        outchar('"');
 
@@ -507,44 +507,45 @@
                        continue;
                }
 
-               outqchar('%');
+               outchar('%');
                c = *cp++;
 
                /* flags for printf and scanf and *-fieldwidth for printf */
-               while (c != '\0' && (c == '-' || c == '+' || c == ' ' ||
-                                    c == '#' || c == '0' || c == '*')) {
-                       outqchar(c);
+               while (c == '-' || c == '+' || c == ' ' ||
+                      c == '#' || c == '0' || c == '*') {
+                       outchar(c);
                        c = *cp++;
                }
 
                /* numeric field width */
-               while (c != '\0' && ch_isdigit((char)c)) {
-                       outqchar(c);
+               while (ch_isdigit(c)) {
+                       outchar(c);
                        c = *cp++;
                }
 
                /* precision for printf */
                if (c == '.') {
-                       outqchar(c);
-                       if ((c = *cp++) == '*') {
-                               outqchar(c);
+                       outchar(c);
+                       c = *cp++;
+                       if (c == '*') {
+                               outchar(c);
                                c = *cp++;
                        } else {
-                               while (c != '\0' && ch_isdigit((char)c)) {
-                                       outqchar(c);
+                               while (ch_isdigit(c)) {
+                                       outchar(c);
                                        c = *cp++;
                                }
                        }
                }
 
-               /* h, l, L and q flags fpr printf and scanf */
+               /* h, l, L and q flags for printf and scanf */
                if (c == 'h' || c == 'l' || c == 'L' || c == 'q') {
-                       outqchar(c);
+                       outchar(c);
                        c = *cp++;
                }
 
                /*
-                * The last character. It is always written so we can detect
+                * The last character. It is always written, so we can detect
                 * invalid format specifiers.
                 */
                if (c != '\0') {
@@ -564,13 +565,13 @@
                                while (c != '\0' && c != ']') {
                                        if (c == '-') {
                                                if (!first && *cp != ']')
-                                                       outqchar(c);
+                                                       outchar(c);
                                        }
                                        first = false;
                                        c = *cp++;
                                }
                                if (c == ']') {
-                                       outqchar(c);
+                                       outchar(c);
                                        c = *cp++;
                                }
                        }



Home | Main Index | Thread Index | Old Index