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 in lexer



details:   https://anonhg.NetBSD.org/src/rev/323310f10028
branches:  trunk
changeset: 988678:323310f10028
user:      rillig <rillig%NetBSD.org@localhost>
date:      Fri Oct 08 23:55:44 2021 +0000

description:
indent: merge duplicate code in lexer

No functional change.

diffstat:

 usr.bin/indent/lexi.c |  35 +++++++++++++++++------------------
 1 files changed, 17 insertions(+), 18 deletions(-)

diffs (97 lines):

diff -r c4ef0d13915f -r 323310f10028 usr.bin/indent/lexi.c
--- a/usr.bin/indent/lexi.c     Fri Oct 08 23:53:37 2021 +0000
+++ b/usr.bin/indent/lexi.c     Fri Oct 08 23:55:44 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lexi.c,v 1.86 2021/10/08 23:43:33 rillig Exp $ */
+/*     $NetBSD: lexi.c,v 1.87 2021/10/08 23:55:44 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.86 2021/10/08 23:43:33 rillig Exp $");
+__RCSID("$NetBSD: lexi.c,v 1.87 2021/10/08 23:55:44 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/lexi.c 337862 2018-08-15 18:19:45Z pstef $");
 #endif
@@ -204,6 +204,13 @@
        buf_expand(&token, desired_size);
 }
 
+static void
+token_add_char(char ch)
+{
+    check_size_token(1);
+    *token.e++ = ch;
+}
+
 static int
 cmp_keyword_by_name(const void *key, const void *elem)
 {
@@ -276,8 +283,7 @@
        }
 
        s = lex_number_state[row][s - 'A'];
-       check_size_token(1);
-       *token.e++ = inbuf_next();
+       token_add_char(inbuf_next());
     }
 }
 
@@ -297,8 +303,7 @@
                break;
        }
 
-       check_size_token(1);
-       *token.e++ = inbuf_next();
+       token_add_char(inbuf_next());
     }
 }
 
@@ -311,15 +316,14 @@
            return;
        }
 
-       check_size_token(2);
-       *token.e++ = inbuf_next();
+       token_add_char(inbuf_next());
        if (token.e[-1] == delim)
            return;
 
        if (token.e[-1] == '\\') {
            if (*inp.s == '\n')
                ++line_no;
-           *token.e++ = inbuf_next();
+           token_add_char(inbuf_next());
        }
     }
 }
@@ -647,10 +651,8 @@
        }
 
        while (*inp.s == '*' || isspace((unsigned char)*inp.s)) {
-           if (*inp.s == '*') {
-               check_size_token(1);
-               *token.e++ = *inp.s;
-           }
+           if (*inp.s == '*')
+               token_add_char('*');
            inbuf_skip();
        }
 
@@ -680,11 +682,8 @@
        }
 
        while (token.e[-1] == *inp.s || *inp.s == '=') {
-           /*
-            * handle ||, &&, etc, and also things as in int *****i
-            */
-           check_size_token(1);
-           *token.e++ = inbuf_next();
+           /* handle '||', '&&', etc., and also things as in 'int *****i' */
+           token_add_char(inbuf_next());
        }
 
        ttype = state->last_u_d ? unary_op : binary_op;



Home | Main Index | Thread Index | Old Index