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: force at least one space after the co...



details:   https://anonhg.NetBSD.org/src/rev/86141d3d0d2b
branches:  trunk
changeset: 376206:86141d3d0d2b
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Jun 04 18:58:30 2023 +0000

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

diffstat:

 tests/usr.bin/indent/edge_cases.c              |   6 +++---
 tests/usr.bin/indent/label.c                   |   6 +++---
 tests/usr.bin/indent/lsym_case_label.c         |   5 ++---
 tests/usr.bin/indent/lsym_lparen_or_lbracket.c |   4 ++--
 usr.bin/indent/io.c                            |  10 ++++++----
 5 files changed, 16 insertions(+), 15 deletions(-)

diffs (111 lines):

diff -r c945e3e9093d -r 86141d3d0d2b tests/usr.bin/indent/edge_cases.c
--- a/tests/usr.bin/indent/edge_cases.c Sun Jun 04 17:54:11 2023 +0000
+++ b/tests/usr.bin/indent/edge_cases.c Sun Jun 04 18:58:30 2023 +0000
@@ -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.
diff -r c945e3e9093d -r 86141d3d0d2b tests/usr.bin/indent/label.c
--- a/tests/usr.bin/indent/label.c      Sun Jun 04 17:54:11 2023 +0000
+++ b/tests/usr.bin/indent/label.c      Sun Jun 04 18:58:30 2023 +0000
@@ -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
 
diff -r c945e3e9093d -r 86141d3d0d2b tests/usr.bin/indent/lsym_case_label.c
--- a/tests/usr.bin/indent/lsym_case_label.c    Sun Jun 04 17:54:11 2023 +0000
+++ b/tests/usr.bin/indent/lsym_case_label.c    Sun Jun 04 18:58:30 2023 +0000
@@ -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;
                }
        }
diff -r c945e3e9093d -r 86141d3d0d2b tests/usr.bin/indent/lsym_lparen_or_lbracket.c
--- a/tests/usr.bin/indent/lsym_lparen_or_lbracket.c    Sun Jun 04 17:54:11 2023 +0000
+++ b/tests/usr.bin/indent/lsym_lparen_or_lbracket.c    Sun Jun 04 18:58:30 2023 +0000
@@ -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;
diff -r c945e3e9093d -r 86141d3d0d2b usr.bin/indent/io.c
--- a/usr.bin/indent/io.c       Sun Jun 04 17:54:11 2023 +0000
+++ b/usr.bin/indent/io.c       Sun Jun 04 18:58:30 2023 +0000
@@ -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



Home | Main Index | Thread Index | Old Index