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: split process_comment_in_code into se...
details: https://anonhg.NetBSD.org/src/rev/b53961aa7720
branches: trunk
changeset: 1024787:b53961aa7720
user: rillig <rillig%NetBSD.org@localhost>
date: Thu Nov 04 20:31:04 2021 +0000
description:
indent: split process_comment_in_code into separate functions
No functional change.
diffstat:
usr.bin/indent/indent.c | 57 ++++++++++++++++++++++++++----------------------
1 files changed, 31 insertions(+), 26 deletions(-)
diffs (88 lines):
diff -r 8e02b29669b1 -r b53961aa7720 usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c Thu Nov 04 19:23:57 2021 +0000
+++ b/usr.bin/indent/indent.c Thu Nov 04 20:31:04 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: indent.c,v 1.206 2021/11/04 17:12:12 rillig Exp $ */
+/* $NetBSD: indent.c,v 1.207 2021/11/04 20:31:04 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@
#include <sys/cdefs.h>
#if defined(__NetBSD__)
-__RCSID("$NetBSD: indent.c,v 1.206 2021/11/04 17:12:12 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.207 2021/11/04 20:31:04 rillig Exp $");
#elif defined(__FreeBSD__)
__FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
#endif
@@ -685,31 +685,31 @@
}
static void
-process_comment_in_code(lexer_symbol lsym, bool *force_nl)
+maybe_break_line(lexer_symbol lsym, bool *force_nl)
{
- if (*force_nl &&
- lsym != lsym_semicolon &&
- (lsym != lsym_lbrace || !opt.brace_same_line)) {
+ if (!*force_nl)
+ return;
+ if (lsym == lsym_semicolon)
+ return;
+ else if (lsym == lsym_lbrace && opt.brace_same_line)
+ return;
- /* we should force a broken line here */
- if (opt.verbose)
- diag(0, "Line broken");
- dump_line();
- ps.want_blank = false; /* don't insert blank at line start */
- *force_nl = false;
- }
+ if (opt.verbose)
+ diag(0, "Line broken");
+ dump_line();
+ ps.want_blank = false;
+ *force_nl = false;
+}
- /* add an extra level of indentation; turned off again by a ';' or '}' */
- ps.in_stmt = true;
-
- if (com.s != com.e) { /* a comment embedded in a line */
- buf_add_char(&code, ' ');
- buf_add_buf(&code, &com);
- buf_add_char(&code, ' ');
- buf_terminate(&code);
- buf_reset(&com);
- ps.want_blank = false;
- }
+static void
+move_com_to_code(void)
+{
+ buf_add_char(&code, ' ');
+ buf_add_buf(&code, &com);
+ buf_add_char(&code, ' ');
+ buf_terminate(&code);
+ buf_reset(&com);
+ ps.want_blank = false;
}
static void
@@ -1402,8 +1402,13 @@
if (lsym == lsym_newline || lsym == lsym_form_feed ||
lsym == lsym_preprocessing)
force_nl = false;
- else if (lsym != lsym_comment)
- process_comment_in_code(lsym, &force_nl);
+ else if (lsym != lsym_comment) {
+ maybe_break_line(lsym, &force_nl);
+ ps.in_stmt = true; /* add an extra level of indentation; turned
+ * off again by a ';' or '}' */
+ if (com.s != com.e)
+ move_com_to_code();
+ }
buf_reserve(&code, 3); /* space for 2 characters plus '\0' */
Home |
Main Index |
Thread Index |
Old Index