Module Name:    src
Committed By:   rillig
Date:           Thu Oct  7 19:35:50 UTC 2021

Modified Files:
        src/usr.bin/indent: indent.c indent_globs.h io.c

Log Message:
indent: clean up colon handling

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.112 -r1.113 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.42 -r1.43 src/usr.bin/indent/indent_globs.h
cvs rdiff -u -r1.74 -r1.75 src/usr.bin/indent/io.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/indent/indent.c
diff -u src/usr.bin/indent/indent.c:1.112 src/usr.bin/indent/indent.c:1.113
--- src/usr.bin/indent/indent.c:1.112	Thu Oct  7 19:17:07 2021
+++ src/usr.bin/indent/indent.c	Thu Oct  7 19:35:50 2021
@@ -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 @@ static char sccsid[] = "@(#)indent.c	5.1
 
 #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 @@ main_init_globals(void)
     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 @@ process_question(int *seen_quest)
 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 @@ process_colon(int *seen_quest, bool *for
 	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 @@ process_preprocessing(void)
 	    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 */

Index: src/usr.bin/indent/indent_globs.h
diff -u src/usr.bin/indent/indent_globs.h:1.42 src/usr.bin/indent/indent_globs.h:1.43
--- src/usr.bin/indent/indent_globs.h:1.42	Tue Oct  5 18:50:42 2021
+++ src/usr.bin/indent/indent_globs.h	Thu Oct  7 19:35:50 2021
@@ -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 @@ extern struct parser_state {
     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 */

Index: src/usr.bin/indent/io.c
diff -u src/usr.bin/indent/io.c:1.74 src/usr.bin/indent/io.c:1.75
--- src/usr.bin/indent/io.c:1.74	Thu Oct  7 18:32:09 2021
+++ src/usr.bin/indent/io.c	Thu Oct  7 19:35:50 2021
@@ -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 @@ static char sccsid[] = "@(#)io.c	8.1 (Be
 
 #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 @@ dump_line(void)
 	} 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 @@ compute_code_indent(void)
 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;

Reply via email to