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 for reading from...



details:   https://anonhg.NetBSD.org/src/rev/d464d823b90f
branches:  trunk
changeset: 988230:d464d823b90f
user:      rillig <rillig%NetBSD.org@localhost>
date:      Tue Oct 05 05:39:14 2021 +0000

description:
indent: merge duplicate code for reading from input buffer

No functional change.

diffstat:

 usr.bin/indent/indent.c     |  36 ++++++++++++------------------------
 usr.bin/indent/indent.h     |   4 +++-
 usr.bin/indent/lexi.c       |  10 +++++-----
 usr.bin/indent/pr_comment.c |  27 ++++++++++-----------------
 4 files changed, 30 insertions(+), 47 deletions(-)

diffs (227 lines):

diff -r 49d830426aa7 -r d464d823b90f usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c   Tue Oct 05 04:17:58 2021 +0000
+++ b/usr.bin/indent/indent.c   Tue Oct 05 05:39:14 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: indent.c,v 1.98 2021/10/03 18:44:51 rillig Exp $       */
+/*     $NetBSD: indent.c,v 1.99 2021/10/05 05:39:14 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.98 2021/10/03 18:44:51 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.99 2021/10/05 05:39:14 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -199,9 +199,7 @@
     *sc_end++ = '/';           /* copy in start of comment */
     *sc_end++ = '*';
     for (;;) {                 /* loop until the end of the comment */
-       *sc_end = *buf_ptr++;
-       if (buf_ptr >= buf_end)
-           fill_buffer();
+       *sc_end = inbuf_next();
        if (*sc_end++ == '*' && *buf_ptr == '/')
            break;              /* we are at end of comment */
        if (sc_end >= &save_com[sc_size]) {     /* check for temp buffer
@@ -212,8 +210,7 @@
        }
     }
     *sc_end++ = '/';           /* add ending slash */
-    if (++buf_ptr >= buf_end)  /* get past / in buffer */
-       fill_buffer();
+    inbuf_skip();              /* get past / in buffer */
 }
 
 static bool
@@ -232,8 +229,7 @@
         * resulting from the "{" before, it must be scanned now and ignored.
         */
        while (isspace((unsigned char)*buf_ptr)) {
-           if (++buf_ptr >= buf_end)
-               fill_buffer();
+           inbuf_skip();
            if (*buf_ptr == '\n')
                break;
        }
@@ -334,9 +330,8 @@
                    errx(1, "input too long");
                }
            }
-           if (buf_ptr >= buf_end) {
+           if (buf_ptr >= buf_end)
                fill_buffer();
-           }
        }
 
        struct parser_state transient_state;
@@ -1109,23 +1104,16 @@
        char quote = '\0';
        int com_end = 0;
 
-       while (*buf_ptr == ' ' || *buf_ptr == '\t') {
-           buf_ptr++;
-           if (buf_ptr >= buf_end)
-               fill_buffer();
-       }
+       while (*buf_ptr == ' ' || *buf_ptr == '\t')
+           inbuf_skip();
+
        while (*buf_ptr != '\n' || (in_comment && !had_eof)) {
            check_size_label(2);
-           *lab.e = *buf_ptr++;
-           if (buf_ptr >= buf_end)
-               fill_buffer();
+           *lab.e = inbuf_next();
            switch (*lab.e++) {
            case '\\':
-               if (!in_comment) {
-                   *lab.e++ = *buf_ptr++;
-                   if (buf_ptr >= buf_end)
-                       fill_buffer();
-               }
+               if (!in_comment)
+                   *lab.e++ = inbuf_next();
                break;
            case '/':
                if (*buf_ptr == '*' && !in_comment && quote == '\0') {
diff -r 49d830426aa7 -r d464d823b90f usr.bin/indent/indent.h
--- a/usr.bin/indent/indent.h   Tue Oct 05 04:17:58 2021 +0000
+++ b/usr.bin/indent/indent.h   Tue Oct 05 05:39:14 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: indent.h,v 1.27 2021/10/03 18:44:51 rillig Exp $       */
+/*     $NetBSD: indent.h,v 1.28 2021/10/05 05:39:14 rillig Exp $       */
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -57,6 +57,8 @@
 #define                debug_println(fmt, ...) do { } while (false)
 #define                debug_vis_range(prefix, s, e, suffix) do { } while (false)
 #endif
+void           inbuf_skip(void);
+char           inbuf_next(void);
 token_type     lexi(struct parser_state *);
 void           diag(int, const char *, ...) __printflike(2, 3);
 void           dump_line(void);
diff -r 49d830426aa7 -r d464d823b90f usr.bin/indent/lexi.c
--- a/usr.bin/indent/lexi.c     Tue Oct 05 04:17:58 2021 +0000
+++ b/usr.bin/indent/lexi.c     Tue Oct 05 05:39:14 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lexi.c,v 1.65 2021/10/03 20:35:59 rillig Exp $ */
+/*     $NetBSD: lexi.c,v 1.66 2021/10/05 05:39:14 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.65 2021/10/03 20:35:59 rillig Exp $");
+__RCSID("$NetBSD: lexi.c,v 1.66 2021/10/05 05:39:14 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/lexi.c 337862 2018-08-15 18:19:45Z pstef $");
 #endif
@@ -180,7 +180,7 @@
     return *buf_ptr;
 }
 
-static void
+void
 inbuf_skip(void)
 {
     buf_ptr++;
@@ -188,7 +188,7 @@
        fill_buffer();
 }
 
-static char
+char
 inbuf_next(void)
 {
     char ch = inbuf_peek();
@@ -392,7 +392,7 @@
            return lexi_end(string_prefix);
 
        while (*buf_ptr == ' ' || *buf_ptr == '\t')     /* get rid of blanks */
-           inbuf_next();
+           inbuf_skip();
        state->keyword = kw_0;
 
        if (state->last_token == keyword_struct_union_enum &&
diff -r 49d830426aa7 -r d464d823b90f usr.bin/indent/pr_comment.c
--- a/usr.bin/indent/pr_comment.c       Tue Oct 05 04:17:58 2021 +0000
+++ b/usr.bin/indent/pr_comment.c       Tue Oct 05 05:39:14 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pr_comment.c,v 1.47 2021/09/26 19:37:11 rillig Exp $   */
+/*     $NetBSD: pr_comment.c,v 1.48 2021/10/05 05:39:14 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.47 2021/09/26 19:37:11 rillig Exp $");
+__RCSID("$NetBSD: pr_comment.c,v 1.48 2021/10/05 05:39:14 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/pr_comment.c 334927 2018-06-10 16:44:18Z pstef $");
 #endif
@@ -219,8 +219,7 @@
                while (*++buf_ptr == ' ' || *buf_ptr == '\t')
                    ;
            } else {
-               if (++buf_ptr >= buf_end)
-                   fill_buffer();
+               inbuf_skip();
                *com.e++ = 014;
            }
            break;
@@ -260,28 +259,24 @@
                int nstar = 1;
                do {            /* flush any blanks and/or tabs at start of
                                 * next line */
-                   if (++buf_ptr >= buf_end)
-                       fill_buffer();
+                   inbuf_skip();
                    if (*buf_ptr == '*' && --nstar >= 0) {
-                       if (++buf_ptr >= buf_end)
-                           fill_buffer();
+                       inbuf_skip();
                        if (*buf_ptr == '/')
                            goto end_of_comment;
                    }
                } while (*buf_ptr == ' ' || *buf_ptr == '\t');
-           } else if (++buf_ptr >= buf_end)
-               fill_buffer();
+           } else
+               inbuf_skip();
            break;              /* end of case for newline */
 
        case '*':               /* must check for possibility of being at end
                                 * of comment */
-           if (++buf_ptr >= buf_end)   /* get to next char after * */
-               fill_buffer();
+           inbuf_skip();
            check_size_comment(4);
            if (*buf_ptr == '/') {      /* it is the end!!! */
        end_of_comment:
-               if (++buf_ptr >= buf_end)
-                   fill_buffer();
+               inbuf_skip();
                if (break_delim) {
                    if (com.e > com.s + 3)
                        dump_line();
@@ -305,9 +300,7 @@
            int now_len = indentation_after_range(ps.com_col - 1, com.s, com.e);
            do {
                check_size_comment(1);
-               *com.e = *buf_ptr++;
-               if (buf_ptr >= buf_end)
-                   fill_buffer();
+               *com.e = inbuf_next();
                if (*com.e == ' ' || *com.e == '\t')
                    last_blank = com.e - com.buf;       /* remember we saw a
                                                         * blank */



Home | Main Index | Thread Index | Old Index