Module Name:    src
Committed By:   rillig
Date:           Sun Jun  4 18:58:30 UTC 2023

Modified Files:
        src/tests/usr.bin/indent: edge_cases.c label.c lsym_case_label.c
            lsym_lparen_or_lbracket.c
        src/usr.bin/indent: io.c

Log Message:
indent: force at least one space after the colon of a label


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/tests/usr.bin/indent/edge_cases.c
cvs rdiff -u -r1.8 -r1.9 src/tests/usr.bin/indent/label.c
cvs rdiff -u -r1.7 -r1.8 src/tests/usr.bin/indent/lsym_case_label.c
cvs rdiff -u -r1.12 -r1.13 src/tests/usr.bin/indent/lsym_lparen_or_lbracket.c
cvs rdiff -u -r1.191 -r1.192 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/tests/usr.bin/indent/edge_cases.c
diff -u src/tests/usr.bin/indent/edge_cases.c:1.2 src/tests/usr.bin/indent/edge_cases.c:1.3
--- src/tests/usr.bin/indent/edge_cases.c:1.2	Mon May 22 23:01:27 2023
+++ src/tests/usr.bin/indent/edge_cases.c	Sun Jun  4 18:58:30 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: edge_cases.c,v 1.2 2023/05/22 23:01:27 rillig Exp $ */
+/* $NetBSD: edge_cases.c,v 1.3 2023/06/04 18:58:30 rillig Exp $ */
 
 /*
  * Tests for edge cases in the C programming language that indent does not
@@ -30,10 +30,10 @@ digraphs(void)
 {
 	/* same as 'array[subscript]' */
 // $ Indent interprets everything before the second ':' as a label name,
-// $ therefore the statement is indented that far to the left.
+// $ indenting the "label" 2 levels to the left.
 // $
 // $ The space between 'array' and '<' comes from the binary operator '<'.
-number = array <:subscript:>;
+number = array <:subscript: >;
 
 	/* same as '(int){ initializer }' */
 // $ The opening '<' and '%' are interpreted as unary operators.

Index: src/tests/usr.bin/indent/label.c
diff -u src/tests/usr.bin/indent/label.c:1.8 src/tests/usr.bin/indent/label.c:1.9
--- src/tests/usr.bin/indent/label.c:1.8	Sun Jun  4 13:26:07 2023
+++ src/tests/usr.bin/indent/label.c	Sun Jun  4 18:58:30 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: label.c,v 1.8 2023/06/04 13:26:07 rillig Exp $	*/
+/*	$NetBSD: label.c,v 1.9 2023/06/04 18:58:30 rillig Exp $	*/
 
 /* See FreeBSD r303489 */
 
@@ -61,8 +61,8 @@ L_3:	;
 L__4:	;
 L___5:	;
 L____6:	;
-L_____7:;
-L______8:;
+L_____7: ;
+L______8: ;
 }
 //indent end
 

Index: src/tests/usr.bin/indent/lsym_case_label.c
diff -u src/tests/usr.bin/indent/lsym_case_label.c:1.7 src/tests/usr.bin/indent/lsym_case_label.c:1.8
--- src/tests/usr.bin/indent/lsym_case_label.c:1.7	Sun Jun  4 12:46:57 2023
+++ src/tests/usr.bin/indent/lsym_case_label.c	Sun Jun  4 18:58:30 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: lsym_case_label.c,v 1.7 2023/06/04 12:46:57 rillig Exp $ */
+/* $NetBSD: lsym_case_label.c,v 1.8 2023/06/04 18:58:30 rillig Exp $ */
 
 /*
  * Tests for the tokens lsym_case and lsym_default, which represent the
@@ -66,8 +66,7 @@ function(void)
 	case 1:	{
 			break;
 		}
-	/* $ FIXME: missing space between ':' and '{'. */
-	case 11:{
+	case 11: {
 			break;
 		}
 	}

Index: src/tests/usr.bin/indent/lsym_lparen_or_lbracket.c
diff -u src/tests/usr.bin/indent/lsym_lparen_or_lbracket.c:1.12 src/tests/usr.bin/indent/lsym_lparen_or_lbracket.c:1.13
--- src/tests/usr.bin/indent/lsym_lparen_or_lbracket.c:1.12	Sun Jun  4 14:20:01 2023
+++ src/tests/usr.bin/indent/lsym_lparen_or_lbracket.c	Sun Jun  4 18:58:30 2023
@@ -1,4 +1,4 @@
-/* $NetBSD: lsym_lparen_or_lbracket.c,v 1.12 2023/06/04 14:20:01 rillig Exp $ */
+/* $NetBSD: lsym_lparen_or_lbracket.c,v 1.13 2023/06/04 18:58:30 rillig Exp $ */
 
 /*
  * Tests for the token lsym_lparen_or_lbracket, which represents a '(' or '['
@@ -298,7 +298,7 @@ cover_want_blank_before_lparen(void)
 	a++ (postfix_op);	/* unlikely to be seen in practice */
 	cond ? (question) : (5);
 	switch (expr) {
-	case (case_label):;
+	case (case_label): ;
 	}
 	a ? 3 : (colon);
 	(semicolon) = 3;

Index: src/usr.bin/indent/io.c
diff -u src/usr.bin/indent/io.c:1.191 src/usr.bin/indent/io.c:1.192
--- src/usr.bin/indent/io.c:1.191	Sun Jun  4 17:54:11 2023
+++ src/usr.bin/indent/io.c	Sun Jun  4 18:58:30 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: io.c,v 1.191 2023/06/04 17:54:11 rillig Exp $	*/
+/*	$NetBSD: io.c,v 1.192 2023/06/04 18:58:30 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: io.c,v 1.191 2023/06/04 17:54:11 rillig Exp $");
+__RCSID("$NetBSD: io.c,v 1.192 2023/06/04 18:58:30 rillig Exp $");
 
 #include <stdio.h>
 
@@ -199,9 +199,11 @@ output_line_code(int ind)
 		}
 	}
 
-	ind = output_indent(ind, target_ind);
+	int code_ind = output_indent(ind, target_ind);
+	if (ind > 0 && code_ind == ind)
+		output_range(" ", 1), code_ind++;
 	output_range(code.st, code.len);
-	return ind_add(ind, code.st, code.len);
+	return ind_add(code_ind, code.st, code.len);
 }
 
 static void

Reply via email to