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: clean up comments
details: https://anonhg.NetBSD.org/src/rev/de82ee16b223
branches: trunk
changeset: 1024020:de82ee16b223
user: rillig <rillig%NetBSD.org@localhost>
date: Thu Oct 07 21:43:20 2021 +0000
description:
indent: clean up comments
No functional change.
diffstat:
usr.bin/indent/indent.c | 28 +++++++++++++---------------
usr.bin/indent/parse.c | 13 +++++++------
usr.bin/indent/pr_comment.c | 12 ++++--------
3 files changed, 24 insertions(+), 29 deletions(-)
diffs (163 lines):
diff -r 00be88e3c82b -r de82ee16b223 usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c Thu Oct 07 21:41:59 2021 +0000
+++ b/usr.bin/indent/indent.c Thu Oct 07 21:43:20 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: indent.c,v 1.117 2021/10/07 21:41:59 rillig Exp $ */
+/* $NetBSD: indent.c,v 1.118 2021/10/07 21:43:20 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.117 2021/10/07 21:41:59 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.118 2021/10/07 21:43:20 rillig Exp $");
#elif defined(__FreeBSD__)
__FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
#endif
@@ -577,11 +577,10 @@
*force_nl = false;
}
- ps.in_stmt = true; /* turn on flag which causes an extra level of
- * indentation. this is turned off by a ';' or
- * '}' */
- if (com.s != com.e) { /* the turkey has embedded a comment in a
- * line. fix it */
+ /* 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, ' ');
@@ -877,8 +876,7 @@
}
}
if (code.s == code.e)
- ps.ind_stmt = false; /* don't put extra indentation on a line
- * with '{' */
+ ps.ind_stmt = false; /* don't indent the '{' itself */
if (ps.in_decl && ps.in_or_st) { /* this is either a structure
* declaration or an init */
di_stack[ps.decl_nest] = *decl_ind;
@@ -1243,10 +1241,10 @@
* read are stored in "token". */
/*
- * The following code moves newlines and comments following an if (),
- * while (), else, etc. up to the start of the following stmt to a
- * buffer. This allows proper handling of both kinds of brace
- * placement (-br, -bl) and cuddling "else" (-ce).
+ * Move newlines and comments following an if (), while (), else, etc.
+ * up to the start of the following stmt to a buffer. This allows
+ * proper handling of both kinds of brace placement (-br, -bl) and
+ * cuddling "else" (-ce).
*/
search_brace(&ttype, &force_nl, &comment_buffered, &last_else);
@@ -1352,7 +1350,7 @@
if (ps.p_l_follow > 0)
goto copy_token;
/* FALLTHROUGH */
- case decl: /* we have a declaration type (int, etc.) */
+ case decl: /* a declaration type (int, etc.) */
process_decl(&decl_ind, &tabs_to_var);
goto copy_token;
@@ -1378,7 +1376,7 @@
process_comma(decl_ind, tabs_to_var, &force_nl);
break;
- case preprocessing: /* '#' */
+ case preprocessing: /* the initial '#' */
process_preprocessing();
break;
case comment: /* the initial '/' '*' or '//' of a comment */
diff -r 00be88e3c82b -r de82ee16b223 usr.bin/indent/parse.c
--- a/usr.bin/indent/parse.c Thu Oct 07 21:41:59 2021 +0000
+++ b/usr.bin/indent/parse.c Thu Oct 07 21:43:20 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: parse.c,v 1.30 2021/10/07 21:38:25 rillig Exp $ */
+/* $NetBSD: parse.c,v 1.31 2021/10/07 21:43:20 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-4-Clause
@@ -55,6 +55,10 @@
static void reduce(void);
+/*
+ * Shift the token onto the parser stack, or reduce it by combining it with
+ * previous tokens.
+ */
void
parse(token_type ttype)
{
@@ -101,7 +105,6 @@
*/
ps.ind_level_follow = ps.il[ps.tos--];
}
- /* the rest is the same as for keyword_do and for_exprs */
/* FALLTHROUGH */
case keyword_do:
case for_exprs: /* 'for' (...) */
@@ -119,15 +122,13 @@
* group or a declaration */
else {
if (code.s == code.e) {
+ /* it is a group as part of a while, for, etc. */
--ps.ind_level;
/*
- * it is a group as part of a while, for, etc.
+ * for a switch, brace should be two levels out from the code
*/
if (ps.p_stack[ps.tos] == switch_expr && opt.case_indent >= 1)
--ps.ind_level;
- /*
- * for a switch, brace should be two levels out from the code
- */
}
}
diff -r 00be88e3c82b -r de82ee16b223 usr.bin/indent/pr_comment.c
--- a/usr.bin/indent/pr_comment.c Thu Oct 07 21:41:59 2021 +0000
+++ b/usr.bin/indent/pr_comment.c Thu Oct 07 21:43:20 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: pr_comment.c,v 1.54 2021/10/07 21:38:25 rillig Exp $ */
+/* $NetBSD: pr_comment.c,v 1.55 2021/10/07 21:43:20 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@
#include <sys/cdefs.h>
#if defined(__NetBSD__)
-__RCSID("$NetBSD: pr_comment.c,v 1.54 2021/10/07 21:38:25 rillig Exp $");
+__RCSID("$NetBSD: pr_comment.c,v 1.55 2021/10/07 21:43:20 rillig Exp $");
#elif defined(__FreeBSD__)
__FBSDID("$FreeBSD: head/usr.bin/indent/pr_comment.c 334927 2018-06-10 16:44:18Z pstef $");
#endif
@@ -169,9 +169,7 @@
if (*buf_ptr != ' ' && !ps.box_com)
*com.e++ = ' ';
- /*
- * Don't put a break delimiter if this is a one-liner that won't wrap.
- */
+ /* Don't put a break delimiter if this is a one-liner that won't wrap. */
if (break_delim)
for (t_ptr = buf_ptr; *t_ptr != '\0' && *t_ptr != '\n'; t_ptr++) {
if (t_ptr >= buf_end)
@@ -310,9 +308,7 @@
/* XXX: signed character comparison '>' does not work for UTF-8 */
if (now_len > adj_max_line_length &&
!ps.box_com && com.e[-1] > ' ') {
- /*
- * the comment is too long, it must be broken up
- */
+ /* the comment is too long, it must be broken up */
if (last_blank == -1) {
dump_line();
if (!ps.box_com && opt.star_comment_cont)
Home |
Main Index |
Thread Index |
Old Index