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: clean up colon handling



details:   https://anonhg.NetBSD.org/src/rev/abc772d759f7
branches:  trunk
changeset: 988615:abc772d759f7
user:      rillig <rillig%NetBSD.org@localhost>
date:      Thu Oct 07 19:35:50 2021 +0000

description:
indent: clean up colon handling

No functional change.

diffstat:

 usr.bin/indent/indent.c       |  25 +++++++++++--------------
 usr.bin/indent/indent_globs.h |   7 +++----
 usr.bin/indent/io.c           |   8 ++++----
 3 files changed, 18 insertions(+), 22 deletions(-)

diffs (133 lines):

diff -r f4c096e8bf5d -r abc772d759f7 usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c   Thu Oct 07 19:17:07 2021 +0000
+++ b/usr.bin/indent/indent.c   Thu Oct 07 19:35:50 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: indent.c,v 1.112 2021/10/07 19:17:07 rillig Exp $      */
+/*     $NetBSD: indent.c,v 1.113 2021/10/07 19:35:50 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.112 2021/10/07 19:17:07 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.113 2021/10/07 19:35:50 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -448,7 +448,7 @@
     ps.in_or_st = false;
     ps.want_blank = ps.in_stmt = ps.ind_stmt = false;
 
-    ps.pcase = false;
+    ps.is_case_label = false;
     sc_end = NULL;
     bp_save = NULL;
     be_save = NULL;
@@ -760,7 +760,7 @@
 static void
 process_colon(int *seen_quest, bool *force_nl, bool *seen_case)
 {
-    if (*seen_quest > 0) {     /* it is part of the <c>?<n>: <n> construct */
+    if (*seen_quest > 0) {     /* part of a '?:' operator */
        --*seen_quest;
        if (ps.want_blank)
            *code.e++ = ' ';
@@ -768,24 +768,21 @@
        ps.want_blank = true;
        return;
     }
-    if (ps.in_or_st) {
+
+    if (ps.in_or_st) {         /* bit-field */
        *code.e++ = ':';
        ps.want_blank = false;
        return;
     }
-    ps.in_stmt = false;                /* seeing a label does not imply we are in a
-                                * stmt */
 
-    /* turn everything so far into a label */
-    buf_add_buf(&lab, &code);
+    buf_add_buf(&lab, &code);  /* 'case' or 'default' or named label */
     buf_add_char(&lab, ':');
     buf_terminate(&lab);
     buf_reset(&code);
 
-    ps.pcase = *seen_case;     /* will be used by dump_line to decide how to
-                                * indent the label. */
-    *force_nl = *seen_case;    /* will force a 'case n:' to be on a
-                                * line by itself */
+    ps.in_stmt = false;
+    ps.is_case_label = *seen_case;
+    *force_nl = *seen_case;
     *seen_case = false;
     ps.want_blank = false;
 }
@@ -1172,7 +1169,7 @@
            debug_println("switched buf_ptr to save_com");
        }
        buf_terminate(&lab);
-       ps.pcase = false;
+       ps.is_case_label = false;
     }
 
     if (strncmp(lab.s, "#if", 3) == 0) {       /* also ifdef, ifndef */
diff -r f4c096e8bf5d -r abc772d759f7 usr.bin/indent/indent_globs.h
--- a/usr.bin/indent/indent_globs.h     Thu Oct 07 19:17:07 2021 +0000
+++ b/usr.bin/indent/indent_globs.h     Thu Oct 07 19:35:50 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: indent_globs.h,v 1.42 2021/10/05 18:50:42 rillig Exp $ */
+/*     $NetBSD: indent_globs.h,v 1.43 2021/10/07 19:35:50 rillig Exp $ */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -240,9 +240,8 @@
     short       paren_indents[20]; /* indentation of the operand/argument of
                                 * each level of parentheses or brackets,
                                 * relative to the enclosing statement */
-    bool       pcase;          /* whether the current line label is a
-                                * case.  It is printed differently from a
-                                * regular label */
+    bool       is_case_label;  /* 'case' and 'default' labels are indented
+                                * differently from regular labels */
     bool       search_brace;   /* whether it is necessary
                                 * to buffer up all info up to the start of a
                                 * stmt after an if, while, etc */
diff -r f4c096e8bf5d -r abc772d759f7 usr.bin/indent/io.c
--- a/usr.bin/indent/io.c       Thu Oct 07 19:17:07 2021 +0000
+++ b/usr.bin/indent/io.c       Thu Oct 07 19:35:50 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: io.c,v 1.74 2021/10/07 18:32:09 rillig Exp $   */
+/*     $NetBSD: io.c,v 1.75 2021/10/07 19:35:50 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.74 2021/10/07 18:32:09 rillig Exp $");
+__RCSID("$NetBSD: io.c,v 1.75 2021/10/07 19:35:50 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/io.c 334927 2018-06-10 16:44:18Z pstef $");
 #endif
@@ -181,7 +181,7 @@
        } else
            cur_col = 1;        /* there is no label section */
 
-       ps.pcase = false;
+       ps.is_case_label = false;
 
        if (code.s != code.e) { /* print code section, if any */
            if (comment_open) {
@@ -318,7 +318,7 @@
 int
 compute_label_indent(void)
 {
-    if (ps.pcase)
+    if (ps.is_case_label)
        return (int)(case_ind * (float)opt.indent_size);
     if (lab.s[0] == '#')
        return 0;



Home | Main Index | Thread Index | Old Index