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: inline macro 'token'



details:   https://anonhg.NetBSD.org/src/rev/19a8ded4672f
branches:  trunk
changeset: 987368:19a8ded4672f
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Sep 25 07:59:52 2021 +0000

description:
indent: inline macro 'token'

No functional change.

diffstat:

 usr.bin/indent/indent.c       |  40 ++++++++++++++++++++--------------------
 usr.bin/indent/indent_globs.h |   3 +--
 usr.bin/indent/lexi.c         |  14 +++++++-------
 usr.bin/indent/parse.c        |   4 ++--
 4 files changed, 30 insertions(+), 31 deletions(-)

diffs (258 lines):

diff -r 205051c26863 -r 19a8ded4672f usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c   Sat Sep 25 07:55:24 2021 +0000
+++ b/usr.bin/indent/indent.c   Sat Sep 25 07:59:52 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: indent.c,v 1.65 2021/09/25 07:55:24 rillig Exp $       */
+/*     $NetBSD: indent.c,v 1.66 2021/09/25 07:59:52 rillig Exp $       */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -46,7 +46,7 @@
 #include <sys/cdefs.h>
 #ifndef lint
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: indent.c,v 1.65 2021/09/25 07:55:24 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.66 2021/09/25 07:59:52 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -259,11 +259,11 @@
 
            remove_newlines =
                    /* "} else" */
-                   (*inout_ttype == keyword_do_else && *token == 'e' &&
+                   (*inout_ttype == keyword_do_else && *s_token == 'e' &&
                     code.e != code.s && code.e[-1] == '}')
                    /* "else if" */
                    || (*inout_ttype == keyword_for_if_while &&
-                       *token == 'i' && *inout_last_else && opt.else_if);
+                       *s_token == 'i' && *inout_last_else && opt.else_if);
            if (remove_newlines)
                *inout_force_nl = false;
            if (sc_end == NULL) {       /* ignore buffering if
@@ -292,7 +292,7 @@
                                 * not already broken */
                    diag(0, "Line broken");
            }
-           for (const char *t_ptr = token; *t_ptr; ++t_ptr)
+           for (const char *t_ptr = s_token; *t_ptr; ++t_ptr)
                *sc_end++ = *t_ptr;
 
            sw_buffer:
@@ -616,7 +616,7 @@
            nitems(ps.paren_indents));
        ps.p_l_follow--;
     }
-    if (*token == '[')
+    if (*s_token == '[')
        /* not a function pointer declaration or a function call */;
     else if (ps.in_decl && !ps.block_init && !ps.dumped_decl_indent &&
        ps.procname[0] == '\0' && ps.paren_level == 0) {
@@ -630,7 +630,7 @@
            ps.keyword != rw_0 && ps.keyword != rw_offsetof)))
        *code.e++ = ' ';
     ps.want_blank = false;
-    *code.e++ = token[0];
+    *code.e++ = s_token[0];
 
     ps.paren_indents[ps.p_l_follow - 1] =
        indentation_after_range(0, code.s, code.e);
@@ -642,7 +642,7 @@
        ps.paren_indents[0] = 2 * opt.indent_size;
        debug_println("paren_indent[0] is now %d", ps.paren_indents[0]);
     }
-    if (ps.in_or_st && *token == '(' && ps.tos <= 2) {
+    if (ps.in_or_st && *s_token == '(' && ps.tos <= 2) {
        /*
         * this is a kluge to make sure that declarations will be
         * aligned right if proc decl has an explicit type on it, i.e.
@@ -671,13 +671,13 @@
 
     if (--ps.p_l_follow < 0) {
        ps.p_l_follow = 0;
-       diag(0, "Extra %c", *token);
+       diag(0, "Extra %c", *s_token);
     }
 
     if (code.e == code.s)      /* if the paren starts the line */
        ps.paren_level = ps.p_l_follow; /* then indent it */
 
-    *code.e++ = token[0];
+    *code.e++ = s_token[0];
 
     if (*inout_sp_sw && (ps.p_l_follow == 0)) {        /* check for end of if
                                 * (...), or some such */
@@ -706,7 +706,7 @@
         * this token
         */
        int i;
-       for (i = 0; token[i]; ++i)
+       for (i = 0; s_token[i]; ++i)
            /* find length of token */;
        indent_declaration(dec_ind - i, tabs_to_var);
        ps.dumped_decl_indent = true;
@@ -717,7 +717,7 @@
        size_t len = e_token - s_token;
 
        check_size_code(len);
-       memcpy(code.e, token, len);
+       memcpy(code.e, s_token, len);
        code.e += len;
     }
     ps.want_blank = false;
@@ -731,7 +731,7 @@
     check_size_code(len + 1);
     if (ps.want_blank)
        *code.e++ = ' ';
-    memcpy(code.e, token, len);
+    memcpy(code.e, s_token, len);
     code.e += len;
 
     ps.want_blank = true;
@@ -740,8 +740,8 @@
 static void
 process_postfix_op(void)
 {
-    *code.e++ = token[0];
-    *code.e++ = token[1];
+    *code.e++ = s_token[0];
+    *code.e++ = s_token[1];
     ps.want_blank = true;
 }
 
@@ -966,7 +966,7 @@
 process_keyword_do_else(int *inout_force_nl, int *inout_last_else)
 {
     ps.in_stmt = false;
-    if (*token == 'e') {
+    if (*s_token == 'e') {
        if (code.e != code.s && (!opt.cuddle_else || code.e[-1] != '}')) {
            if (opt.verbose)
                diag(0, "Line broken");
@@ -1010,7 +1010,7 @@
        ps.just_saw_decl = 2;
     prefix_blankline_requested = 0;
     int i;
-    for (i = 0; token[i++];);  /* get length of token */
+    for (i = 0; s_token[i++];);        /* get length of token */
 
     if (ps.ind_level == 0 || ps.dec_nest > 0) {
        /* global variable or struct member in local variable */
@@ -1073,7 +1073,7 @@
     check_size_code(len + 1);
     if (ps.want_blank)
        *code.e++ = ' ';
-    memcpy(code.e, token, len);
+    memcpy(code.e, s_token, len);
     code.e += len;
 
     ps.want_blank = false;
@@ -1379,8 +1379,8 @@
        case keyword_for_if_while:
            sp_sw = true;       /* the interesting stuff is done after the
                                 * expression is scanned */
-           hd_type = (*token == 'i' ? if_expr :
-                      (*token == 'w' ? while_expr : for_exprs));
+           hd_type = (*s_token == 'i' ? if_expr :
+                      (*s_token == 'w' ? while_expr : for_exprs));
 
            /* remember the type of header for later use by parser */
            goto copy_id;       /* copy the token into line */
diff -r 205051c26863 -r 19a8ded4672f usr.bin/indent/indent_globs.h
--- a/usr.bin/indent/indent_globs.h     Sat Sep 25 07:55:24 2021 +0000
+++ b/usr.bin/indent/indent_globs.h     Sat Sep 25 07:59:52 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: indent_globs.h,v 1.24 2021/09/25 07:55:24 rillig Exp $ */
+/*     $NetBSD: indent_globs.h,v 1.25 2021/09/25 07:59:52 rillig Exp $ */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -63,7 +63,6 @@
 extern struct buffer code;             /* code */
 extern struct buffer com;              /* comment */
 
-#define token s_token
 extern char       *tokenbuf;           /* the last token scanned */
 extern char       *s_token;
 extern char       *e_token;
diff -r 205051c26863 -r 19a8ded4672f usr.bin/indent/lexi.c
--- a/usr.bin/indent/lexi.c     Sat Sep 25 07:55:24 2021 +0000
+++ b/usr.bin/indent/lexi.c     Sat Sep 25 07:59:52 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lexi.c,v 1.48 2021/09/25 07:55:24 rillig Exp $ */
+/*     $NetBSD: lexi.c,v 1.49 2021/09/25 07:59:52 rillig Exp $ */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -46,7 +46,7 @@
 #include <sys/cdefs.h>
 #ifndef lint
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: lexi.c,v 1.48 2021/09/25 07:55:24 rillig Exp $");
+__RCSID("$NetBSD: lexi.c,v 1.49 2021/09/25 07:59:52 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/lexi.c 337862 2018-08-15 18:19:45Z pstef $");
 #endif
@@ -323,7 +323,7 @@
 {
     char delim;
 
-    delim = *token;
+    delim = *s_token;
     do {                       /* copy the string */
        for (;;) {              /* move one character or [/<char>]<char> */
            if (*buf_ptr == '\n') {
@@ -463,7 +463,7 @@
            while (tp < buf_end)
                if (*tp++ == ')' && (*tp == ';' || *tp == ','))
                    goto not_proc;
-           strncpy(state->procname, token, sizeof state->procname - 1);
+           strncpy(state->procname, s_token, sizeof state->procname - 1);
            if (state->in_decl)
                state->in_parameter_declaration = 1;
            return lexi_end(funcname);
@@ -497,7 +497,7 @@
                                 * moved here */
     *e_token = '\0';
 
-    switch (*token) {
+    switch (*s_token) {
     case '\n':
        unary_delim = state->last_u_d;
        state->last_nl = true;  /* remember that we just had a newline */
@@ -574,7 +574,7 @@
        ttype = state->last_u_d ? unary_op : binary_op;
        unary_delim = true;
 
-       if (*buf_ptr == token[0]) {
+       if (*buf_ptr == s_token[0]) {
            /* check for doubled character */
            *e_token++ = *buf_ptr++;
            /* buffer overflow will be checked at end of loop */
@@ -650,7 +650,7 @@
        break;
 
     default:
-       if (token[0] == '/' && (*buf_ptr == '*' || *buf_ptr == '/')) {
+       if (s_token[0] == '/' && (*buf_ptr == '*' || *buf_ptr == '/')) {
            /* it is start of comment */
            *e_token++ = inbuf_next();
 
diff -r 205051c26863 -r 19a8ded4672f usr.bin/indent/parse.c
--- a/usr.bin/indent/parse.c    Sat Sep 25 07:55:24 2021 +0000
+++ b/usr.bin/indent/parse.c    Sat Sep 25 07:59:52 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: parse.c,v 1.20 2021/09/25 07:55:24 rillig Exp $        */
+/*     $NetBSD: parse.c,v 1.21 2021/09/25 07:59:52 rillig Exp $        */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -65,7 +65,7 @@
     int         i;
 
 #ifdef debug
-    printf("parse token: '%s' \"%s\"\n", token_type_name(ttype), token);
+    printf("parse token: '%s' \"%s\"\n", token_type_name(ttype), s_token);
 #endif
 
     while (ps.p_stack[ps.tos] == if_expr_stmt && ttype != keyword_else) {



Home | Main Index | Thread Index | Old Index