diff --git a/usr.bin/indent/debug.c b/usr.bin/indent/debug.c index bcc9989bc9ff..e156b0429e25 100644 --- a/usr.bin/indent/debug.c +++ b/usr.bin/indent/debug.c @@ -1,4 +1,4 @@ -/* $NetBSD: debug.c,v 1.55 2023/06/14 08:25:15 rillig Exp $ */ +/* $NetBSD: debug.c,v 1.56 2023/06/14 08:36:51 rillig Exp $ */ /*- * Copyright (c) 2023 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include -__RCSID("$NetBSD: debug.c,v 1.55 2023/06/14 08:25:15 rillig Exp $"); +__RCSID("$NetBSD: debug.c,v 1.56 2023/06/14 08:36:51 rillig Exp $"); #include #include @@ -374,9 +374,6 @@ debug_parser_state(void) debug_ps_enum(declaration, declaration_name); debug_ps_bool(blank_line_after_decl); - state.heading = "comments"; - debug_ps_bool(next_col_1); - state.heading = NULL; debug_blank_line(); diff --git a/usr.bin/indent/indent.c b/usr.bin/indent/indent.c index 606b15495853..43d0926101a9 100644 --- a/usr.bin/indent/indent.c +++ b/usr.bin/indent/indent.c @@ -1,4 +1,4 @@ -/* $NetBSD: indent.c,v 1.358 2023/06/14 07:20:55 rillig Exp $ */ +/* $NetBSD: indent.c,v 1.359 2023/06/14 08:36:51 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -38,7 +38,7 @@ */ #include -__RCSID("$NetBSD: indent.c,v 1.358 2023/06/14 07:20:55 rillig Exp $"); +__RCSID("$NetBSD: indent.c,v 1.359 2023/06/14 08:36:51 rillig Exp $"); #include #include @@ -186,7 +186,6 @@ init_globals(void) { ps.psyms.sym[0] = psym_stmt; ps.prev_lsym = lsym_semicolon; - ps.next_col_1 = true; ps.lbrace_kind = psym_lbrace_block; const char *suffix = getenv("SIMPLE_BACKUP_SUFFIX"); diff --git a/usr.bin/indent/indent.h b/usr.bin/indent/indent.h index 6715e66602ed..4a761299b289 100644 --- a/usr.bin/indent/indent.h +++ b/usr.bin/indent/indent.h @@ -1,4 +1,4 @@ -/* $NetBSD: indent.h,v 1.190 2023/06/14 08:25:15 rillig Exp $ */ +/* $NetBSD: indent.h,v 1.191 2023/06/14 08:36:51 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD @@ -402,11 +402,6 @@ extern struct parser_state { decl_end, /* finished a declaration */ } declaration; bool blank_line_after_decl; - - /* Comments */ - - bool next_col_1; /* whether the next token starts in column 1 of - * the original input */ } ps; extern struct output_state { diff --git a/usr.bin/indent/lexi.c b/usr.bin/indent/lexi.c index 65745ac134da..2c5e2b656562 100644 --- a/usr.bin/indent/lexi.c +++ b/usr.bin/indent/lexi.c @@ -1,4 +1,4 @@ -/* $NetBSD: lexi.c,v 1.226 2023/06/14 08:25:15 rillig Exp $ */ +/* $NetBSD: lexi.c,v 1.227 2023/06/14 08:36:51 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -38,7 +38,7 @@ */ #include -__RCSID("$NetBSD: lexi.c,v 1.226 2023/06/14 08:25:15 rillig Exp $"); +__RCSID("$NetBSD: lexi.c,v 1.227 2023/06/14 08:36:51 rillig Exp $"); #include #include @@ -532,7 +532,6 @@ lexer_symbol lexi(void) { buf_clear(&token); - ps.next_col_1 = false; for (;;) { if (ch_isblank(inp_p[0])) @@ -567,7 +566,6 @@ lexi(void) /* if data has been exhausted, the '\n' is a dummy. */ lsym = had_eof ? lsym_eof : lsym_newline; next_unary = ps.next_unary; - ps.next_col_1 = true; break; /* INDENT OFF */ diff --git a/usr.bin/indent/pr_comment.c b/usr.bin/indent/pr_comment.c index 50440e845055..8ffae7a8b53c 100644 --- a/usr.bin/indent/pr_comment.c +++ b/usr.bin/indent/pr_comment.c @@ -1,4 +1,4 @@ -/* $NetBSD: pr_comment.c,v 1.162 2023/06/14 08:25:15 rillig Exp $ */ +/* $NetBSD: pr_comment.c,v 1.163 2023/06/14 08:36:51 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -38,7 +38,7 @@ */ #include -__RCSID("$NetBSD: pr_comment.c,v 1.162 2023/06/14 08:25:15 rillig Exp $"); +__RCSID("$NetBSD: pr_comment.c,v 1.163 2023/06/14 08:36:51 rillig Exp $"); #include @@ -178,8 +178,6 @@ copy_comment_wrap_text(int line_length, ssize_t *last_blank) break; } - ps.next_col_1 = false; - if (now_len <= line_length) return; if (ch_isspace(com.s[com.len - 1])) @@ -206,10 +204,10 @@ copy_comment_wrap_text(int line_length, ssize_t *last_blank) } static bool -copy_comment_wrap_newline(ssize_t *last_blank) +copy_comment_wrap_newline(ssize_t *last_blank, bool *seen_newline) { *last_blank = -1; - if (ps.next_col_1) { + if (*seen_newline) { if (com.len == 0) com_add_char(' '); /* force empty output line */ if (com.len > 3) { @@ -219,7 +217,7 @@ copy_comment_wrap_newline(ssize_t *last_blank) output_line(); com_add_delim(); } else { - ps.next_col_1 = true; + *seen_newline = true; if (!(com.len > 0 && ch_isblank(com.s[com.len - 1]))) com_add_char(' '); *last_blank = (int)com.len - 1; @@ -282,17 +280,21 @@ static void copy_comment_wrap(int line_length, bool delim) { ssize_t last_blank = -1; /* index of the last blank in 'com' */ + bool seen_newline = false; for (;;) { if (inp_p[0] == '\n') { if (had_eof) goto unterminated_comment; - if (!copy_comment_wrap_newline(&last_blank)) + if (!copy_comment_wrap_newline(&last_blank, + &seen_newline)) goto end_of_comment; } else if (inp_p[0] == '*' && inp_p[1] == '/') goto end_of_comment; - else + else { copy_comment_wrap_text(line_length, &last_blank); + seen_newline = false; + } } end_of_comment: