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: merge duplicate code into is_hspace



details:   https://anonhg.NetBSD.org/src/rev/70e0db66f283
branches:  trunk
changeset: 988232:70e0db66f283
user:      rillig <rillig%NetBSD.org@localhost>
date:      Tue Oct 05 06:09:42 2021 +0000

description:
indent: merge duplicate code into is_hspace

No functional change.

diffstat:

 usr.bin/indent/indent.c     |  12 ++++++------
 usr.bin/indent/indent.h     |   8 +++++++-
 usr.bin/indent/io.c         |  10 +++++-----
 usr.bin/indent/lexi.c       |  11 +++++------
 usr.bin/indent/pr_comment.c |  23 ++++++++++++-----------
 5 files changed, 35 insertions(+), 29 deletions(-)

diffs (250 lines):

diff -r 6fec03e3bdf1 -r 70e0db66f283 usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c   Tue Oct 05 05:56:49 2021 +0000
+++ b/usr.bin/indent/indent.c   Tue Oct 05 06:09:42 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: indent.c,v 1.100 2021/10/05 05:56:49 rillig Exp $      */
+/*     $NetBSD: indent.c,v 1.101 2021/10/05 06:09:42 rillig Exp $      */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: indent.c,v 1.100 2021/10/05 05:56:49 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.101 2021/10/05 06:09:42 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -324,7 +324,7 @@
         * into the buffer so that the later lexi() call will read them.
         */
        if (sc_end != NULL) {
-           while (*buf_ptr == ' ' || *buf_ptr == '\t') {
+           while (is_hspace(*buf_ptr)) {
                *sc_end++ = *buf_ptr++;
                if (sc_end >= &save_com[sc_size]) {
                    errx(1, "input too long");
@@ -1103,7 +1103,7 @@
        char quote = '\0';
        int com_end = 0;
 
-       while (*buf_ptr == ' ' || *buf_ptr == '\t')
+       while (is_hspace(*buf_ptr))
            inbuf_skip();
 
        while (*buf_ptr != '\n' || (in_comment && !had_eof)) {
@@ -1143,7 +1143,7 @@
            }
        }
 
-       while (lab.e > lab.s && (lab.e[-1] == ' ' || lab.e[-1] == '\t'))
+       while (lab.e > lab.s && is_hspace(lab.e[-1]))
            lab.e--;
        if (lab.e - lab.s == com_end && bp_save == NULL) {
            /* comment on preprocessor line */
@@ -1161,7 +1161,7 @@
            memmove(sc_end, lab.s + com_start, (size_t)(com_end - com_start));
            sc_end += com_end - com_start;
            lab.e = lab.s + com_start;
-           while (lab.e > lab.s && (lab.e[-1] == ' ' || lab.e[-1] == '\t'))
+           while (lab.e > lab.s && is_hspace(lab.e[-1]))
                lab.e--;
            bp_save = buf_ptr;  /* save current input buffer */
            be_save = buf_end;
diff -r 6fec03e3bdf1 -r 70e0db66f283 usr.bin/indent/indent.h
--- a/usr.bin/indent/indent.h   Tue Oct 05 05:56:49 2021 +0000
+++ b/usr.bin/indent/indent.h   Tue Oct 05 06:09:42 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: indent.h,v 1.28 2021/10/05 05:39:14 rillig Exp $       */
+/*     $NetBSD: indent.h,v 1.29 2021/10/05 06:09:42 rillig Exp $       */
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -73,3 +73,9 @@
 char           *xstrdup(const char *);
 
 void           buf_expand(struct buffer *, size_t);
+
+static inline bool
+is_hspace(char ch)
+{
+    return ch == ' ' || ch == '\t';
+}
diff -r 6fec03e3bdf1 -r 70e0db66f283 usr.bin/indent/io.c
--- a/usr.bin/indent/io.c       Tue Oct 05 05:56:49 2021 +0000
+++ b/usr.bin/indent/io.c       Tue Oct 05 06:09:42 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: io.c,v 1.68 2021/09/26 21:23:31 rillig Exp $   */
+/*     $NetBSD: io.c,v 1.69 2021/10/05 06:09:42 rillig Exp $   */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: io.c,v 1.68 2021/09/26 21:23:31 rillig Exp $");
+__RCSID("$NetBSD: io.c,v 1.69 2021/10/05 06:09:42 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/io.c 334927 2018-06-10 16:44:18Z pstef $");
 #endif
@@ -151,7 +151,7 @@
                comment_open = false;
                output_string(".*/\n");
            }
-           while (lab.e > lab.s && (lab.e[-1] == ' ' || lab.e[-1] == '\t'))
+           while (lab.e > lab.s && is_hspace(lab.e[-1]))
                lab.e--;
            *lab.e = '\0';
            cur_col = 1 + output_indent(0, compute_label_indent());
@@ -163,7 +163,7 @@
                do {
                    output_char(*s++);
                } while (s < lab.e && 'a' <= *s && *s <= 'z');
-               while ((*s == ' ' || *s == '\t') && s < lab.e)
+               while (s < lab.e && is_hspace(*s))
                    s++;
                if (s < lab.e) {
                    if (s[0] == '/' && s[1] == '*') {
@@ -328,7 +328,7 @@
 static void
 skip_hspace(const char **pp)
 {
-    while (**pp == ' ' || **pp == '\t')
+    while (is_hspace(**pp))
        (*pp)++;
 }
 
diff -r 6fec03e3bdf1 -r 70e0db66f283 usr.bin/indent/lexi.c
--- a/usr.bin/indent/lexi.c     Tue Oct 05 05:56:49 2021 +0000
+++ b/usr.bin/indent/lexi.c     Tue Oct 05 06:09:42 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lexi.c,v 1.67 2021/10/05 05:56:49 rillig Exp $ */
+/*     $NetBSD: lexi.c,v 1.68 2021/10/05 06:09:42 rillig Exp $ */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: lexi.c,v 1.67 2021/10/05 05:56:49 rillig Exp $");
+__RCSID("$NetBSD: lexi.c,v 1.68 2021/10/05 06:09:42 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/lexi.c 337862 2018-08-15 18:19:45Z pstef $");
 #endif
@@ -367,9 +367,8 @@
                                         * scanned was a newline */
     state->last_nl = false;
 
-    while (*buf_ptr == ' ' || *buf_ptr == '\t') {      /* get rid of blanks */
-       state->col_1 = false;   /* leading blanks imply token is not in column
-                                * 1 */
+    while (is_hspace(*buf_ptr)) {
+       state->col_1 = false;
        inbuf_skip();
     }
 
@@ -391,7 +390,7 @@
            (*buf_ptr == '"' || *buf_ptr == '\''))
            return lexi_end(string_prefix);
 
-       while (*buf_ptr == ' ' || *buf_ptr == '\t')     /* get rid of blanks */
+       while (is_hspace(inbuf_peek()))
            inbuf_skip();
        state->keyword = kw_0;
 
diff -r 6fec03e3bdf1 -r 70e0db66f283 usr.bin/indent/pr_comment.c
--- a/usr.bin/indent/pr_comment.c       Tue Oct 05 05:56:49 2021 +0000
+++ b/usr.bin/indent/pr_comment.c       Tue Oct 05 06:09:42 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pr_comment.c,v 1.49 2021/10/05 05:56:49 rillig Exp $   */
+/*     $NetBSD: pr_comment.c,v 1.50 2021/10/05 06:09:42 rillig Exp $   */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: pr_comment.c,v 1.49 2021/10/05 05:56:49 rillig Exp $");
+__RCSID("$NetBSD: pr_comment.c,v 1.50 2021/10/05 06:09:42 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/pr_comment.c 334927 2018-06-10 16:44:18Z pstef $");
 #endif
@@ -160,7 +160,7 @@
        ps.n_comment_delta = -indentation_after_range(0, start, buf_ptr - 2);
     } else {
        ps.n_comment_delta = 0;
-       while (*buf_ptr == ' ' || *buf_ptr == '\t')
+       while (is_hspace(*buf_ptr))
            buf_ptr++;
     }
     ps.comment_delta = 0;
@@ -216,8 +216,9 @@
                last_blank = -1;
                if (!ps.box_com && opt.star_comment_cont)
                    *com.e++ = ' ', *com.e++ = '*', *com.e++ = ' ';
-               while (*++buf_ptr == ' ' || *buf_ptr == '\t')
-                   ;
+               buf_ptr++;
+               while (is_hspace(*buf_ptr))
+                   buf_ptr++;
            } else {
                inbuf_skip();
                *com.e++ = 014;
@@ -250,7 +251,7 @@
                    *com.e++ = ' ', *com.e++ = '*', *com.e++ = ' ';
            } else {
                ps.last_nl = true;
-               if (!(com.e[-1] == ' ' || com.e[-1] == '\t'))
+               if (!is_hspace(com.e[-1]))
                    *com.e++ = ' ';
                last_blank = com.e - 1 - com.buf;
            }
@@ -265,7 +266,7 @@
                        if (*buf_ptr == '/')
                            goto end_of_comment;
                    }
-               } while (*buf_ptr == ' ' || *buf_ptr == '\t');
+               } while (is_hspace(*buf_ptr));
            } else
                inbuf_skip();
            break;              /* end of case for newline */
@@ -284,7 +285,7 @@
                        com.s = com.e;
                    *com.e++ = ' ';
                }
-               if (com.e[-1] != ' ' && com.e[-1] != '\t' && !ps.box_com)
+               if (!is_hspace(com.e[-1]) && !ps.box_com)
                    *com.e++ = ' ';     /* ensure blank before end */
                if (token.e[-1] == '/')
                    *com.e++ = '\n', *com.e = '\0';
@@ -301,7 +302,7 @@
            do {
                check_size_comment(1);
                char ch = inbuf_next();
-               if (ch == ' ' || ch == '\t')
+               if (is_hspace(ch))
                    last_blank = com.e - com.buf;
                *com.e++ = ch;
                now_len++;
@@ -326,7 +327,7 @@
                if (!ps.box_com && opt.star_comment_cont)
                    *com.e++ = ' ', *com.e++ = '*', *com.e++ = ' ';
                for (t_ptr = com.buf + last_blank + 1;
-                    *t_ptr == ' ' || *t_ptr == '\t'; t_ptr++)
+                    is_hspace(*t_ptr); t_ptr++)
                    continue;
                last_blank = -1;
                /*
@@ -335,7 +336,7 @@
                 * com.e without any check_size_comment().
                 */
                while (*t_ptr != '\0') {
-                   if (*t_ptr == ' ' || *t_ptr == '\t')
+                   if (is_hspace(*t_ptr))
                        last_blank = com.e - com.buf;
                    *com.e++ = *t_ptr++;
                }



Home | Main Index | Thread Index | Old Index