Module Name: src Committed By: rillig Date: Sat May 13 17:20:41 UTC 2023
Modified Files: src/usr.bin/indent: indent.c io.c Log Message: 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. To generate a diff of this commit: cvs rdiff -u -r1.262 -r1.263 src/usr.bin/indent/indent.c cvs rdiff -u -r1.160 -r1.161 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.262 src/usr.bin/indent/indent.c:1.263 --- src/usr.bin/indent/indent.c:1.262 Sat May 13 16:40:18 2023 +++ src/usr.bin/indent/indent.c Sat May 13 17:20:41 2023 @@ -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 && Index: src/usr.bin/indent/io.c diff -u src/usr.bin/indent/io.c:1.160 src/usr.bin/indent/io.c:1.161 --- src/usr.bin/indent/io.c:1.160 Sat May 13 15:34:22 2023 +++ src/usr.bin/indent/io.c Sat May 13 17:20:41 2023 @@ -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