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: do not add a blank at the beginning o...



details:   https://anonhg.NetBSD.org/src/rev/241ff72a88f3
branches:  trunk
changeset: 374836:241ff72a88f3
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat May 13 17:20:41 2023 +0000

description:
indent: do not add a blank at the beginning of a line

Most calls to output_line did already reset the variable.  There may be
some untested edge cases in or after comments, but these should be fine
as well.

diffstat:

 usr.bin/indent/indent.c |  25 ++++++++-----------------
 usr.bin/indent/io.c     |   6 ++++--
 2 files changed, 12 insertions(+), 19 deletions(-)

diffs (112 lines):

diff -r f511d0c441ee -r 241ff72a88f3 usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c   Sat May 13 16:40:18 2023 +0000
+++ b/usr.bin/indent/indent.c   Sat May 13 17:20:41 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: indent.c,v 1.262 2023/05/13 16:40:18 rillig Exp $      */
+/*     $NetBSD: indent.c,v 1.263 2023/05/13 17:20:41 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.262 2023/05/13 16:40:18 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.263 2023/05/13 17:20:41 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -406,7 +406,6 @@ maybe_break_line(lexer_symbol lsym)
     if (opt.verbose)
        diag(0, "Line broken");
     output_line();
-    ps.want_blank = false;
     ps.force_nl = false;
 }
 
@@ -438,7 +437,6 @@ process_newline(void)
        goto stay_in_line;
 
     output_line();
-    ps.want_blank = false;
 
 stay_in_line:
     ++line_no;
@@ -679,16 +677,13 @@ process_lbrace(void)
        ps.block_init_level++;
 
     if (code.s != code.e && !ps.block_init) {
-       if (!opt.brace_same_line) {
+       if (!opt.brace_same_line)
            output_line();
-           ps.want_blank = false;
-       } else if (ps.in_func_def_params && !ps.init_or_struct) {
+       else if (ps.in_func_def_params && !ps.init_or_struct) {
            ps.ind_level_follow = 0;
-           if (opt.function_brace_split) {     /* dump the line prior to the
-                                                * brace ... */
+           if (opt.function_brace_split)
                output_line();
-               ps.want_blank = false;
-           } else              /* add a space between the decl and brace */
+           else
                ps.want_blank = true;
        }
     }
@@ -774,7 +769,6 @@ process_do(void)
        if (opt.verbose)
            diag(0, "Line broken");
        output_line();
-       ps.want_blank = false;
     }
 
     ps.force_nl = true;
@@ -789,8 +783,7 @@ process_else(void)
     if (code.e > code.s && !(opt.cuddle_else && code.e[-1] == '}')) {
        if (opt.verbose)
            diag(0, "Line broken");
-       output_line();          /* make sure this starts a line */
-       ps.want_blank = false;
+       output_line();
     }
 
     ps.force_nl = true;
@@ -803,10 +796,8 @@ process_type(void)
     parse(psym_decl);          /* let the parser worry about indentation */
 
     if (ps.prev_token == lsym_rparen_or_rbracket && ps.tos <= 1) {
-       if (code.s != code.e) {
+       if (code.s != code.e)
            output_line();
-           ps.want_blank = false;
-       }
     }
 
     if (ps.in_func_def_params && opt.indent_parameters &&
diff -r f511d0c441ee -r 241ff72a88f3 usr.bin/indent/io.c
--- a/usr.bin/indent/io.c       Sat May 13 16:40:18 2023 +0000
+++ b/usr.bin/indent/io.c       Sat May 13 17:20:41 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: io.c,v 1.160 2023/05/13 15:34:22 rillig Exp $  */
+/*     $NetBSD: io.c,v 1.161 2023/05/13 17:20:41 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.160 2023/05/13 15:34:22 rillig Exp $");
+__RCSID("$NetBSD: io.c,v 1.161 2023/05/13 17:20:41 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/io.c 334927 2018-06-10 16:44:18Z pstef $");
 #endif
@@ -331,6 +331,8 @@ output_complete_line(char line_terminato
        paren_indent = -1 - ps.paren[ps.nparen - 1].indent;
        debug_println("paren_indent is now %d", paren_indent);
     }
+
+    ps.want_blank = false;
 }
 
 void



Home | Main Index | Thread Index | Old Index