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: fix line break between semicolon and ...



details:   https://anonhg.NetBSD.org/src/rev/d1a48874f0fa
branches:  trunk
changeset: 376335:d1a48874f0fa
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Jun 10 18:46:42 2023 +0000

description:
indent: fix line break between semicolon and brace

diffstat:

 tests/usr.bin/indent/lsym_if.c |   8 ++++----
 usr.bin/indent/debug.c         |   6 +++---
 usr.bin/indent/indent.c        |  28 ++++++++++++++--------------
 3 files changed, 21 insertions(+), 21 deletions(-)

diffs (105 lines):

diff -r 98b2f24c2039 -r d1a48874f0fa tests/usr.bin/indent/lsym_if.c
--- a/tests/usr.bin/indent/lsym_if.c    Sat Jun 10 17:56:29 2023 +0000
+++ b/tests/usr.bin/indent/lsym_if.c    Sat Jun 10 18:46:42 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lsym_if.c,v 1.5 2023/06/10 16:43:56 rillig Exp $ */
+/* $NetBSD: lsym_if.c,v 1.6 2023/06/10 18:46:42 rillig Exp $ */
 
 /*
  * Tests for the token lsym_if, which represents the keyword 'if' that starts
@@ -38,8 +38,8 @@ function(void)
        if (0)
                if (1)
                        if (2)
-// $ FIXME: The '{' must be on a separate line, with indentation 8.
-                               stmt(); {
-                               }
+                               stmt();
+       {
+       }
 }
 //indent end
diff -r 98b2f24c2039 -r d1a48874f0fa usr.bin/indent/debug.c
--- a/usr.bin/indent/debug.c    Sat Jun 10 17:56:29 2023 +0000
+++ b/usr.bin/indent/debug.c    Sat Jun 10 18:46:42 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: debug.c,v 1.50 2023/06/10 16:43:55 rillig Exp $        */
+/*     $NetBSD: debug.c,v 1.51 2023/06/10 18:46:42 rillig Exp $        */
 
 /*-
  * Copyright (c) 2023 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: debug.c,v 1.50 2023/06/10 16:43:55 rillig Exp $");
+__RCSID("$NetBSD: debug.c,v 1.51 2023/06/10 18:46:42 rillig Exp $");
 
 #include <stdarg.h>
 #include <string.h>
@@ -395,6 +395,6 @@ debug_psyms_stack(const char *situation)
        for (int i = 0; i <= psyms->top; ++i)
                debug_printf(" %d %s",
                    psyms->ind_level[i], psym_name[psyms->sym[i]]);
-       debug_blank_line();
+       debug_println("");
 }
 #endif
diff -r 98b2f24c2039 -r d1a48874f0fa usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c   Sat Jun 10 17:56:29 2023 +0000
+++ b/usr.bin/indent/indent.c   Sat Jun 10 18:46:42 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: indent.c,v 1.354 2023/06/10 16:43:55 rillig Exp $      */
+/*     $NetBSD: indent.c,v 1.355 2023/06/10 18:46:42 rillig Exp $      */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: indent.c,v 1.354 2023/06/10 16:43:55 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.355 2023/06/10 18:46:42 rillig Exp $");
 
 #include <sys/param.h>
 #include <err.h>
@@ -314,19 +314,16 @@ set_initial_indentation(void)
        ps.ind_level = ps.ind_level_follow = ind / opt.indent_size;
 }
 
-static void
-maybe_break_line(lexer_symbol lsym)
+static bool
+should_break_line(lexer_symbol lsym)
 {
-       if (!ps.force_nl)
-               return;
        if (lsym == lsym_semicolon)
-               return;
-       if (lsym == lsym_lbrace && opt.brace_same_line
-           && ps.prev_lsym != lsym_lbrace)
-               return;
-
-       output_line();
-       ps.force_nl = false;
+               return false;
+       if (ps.prev_lsym == lsym_lbrace || ps.prev_lsym == lsym_semicolon)
+               return true;
+       if (lsym == lsym_lbrace && opt.brace_same_line)
+               return false;
+       return true;
 }
 
 static void
@@ -1051,7 +1048,10 @@ indent(void)
                else if (lsym == lsym_comment) {
                        /* no special processing */
                } else {
-                       maybe_break_line(lsym);
+                       if (ps.force_nl && should_break_line(lsym)) {
+                               ps.force_nl = false;
+                               output_line();
+                       }
                        ps.in_stmt_or_decl = true;
                        if (com.len > 0)
                                move_com_to_code(lsym);



Home | Main Index | Thread Index | Old Index