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: keep p_l_follow nonnegative, use cons...
details: https://anonhg.NetBSD.org/src/rev/e2f9066597a2
branches: trunk
changeset: 990510:e2f9066597a2
user: rillig <rillig%NetBSD.org@localhost>
date: Fri Oct 29 16:59:35 2021 +0000
description:
indent: keep p_l_follow nonnegative, use consistent comparison
No functional change.
diffstat:
usr.bin/indent/indent.c | 15 +++++++--------
usr.bin/indent/indent.h | 4 ++--
usr.bin/indent/lexi.c | 10 +++++-----
3 files changed, 14 insertions(+), 15 deletions(-)
diffs (114 lines):
diff -r 1e2a8e14ce82 -r e2f9066597a2 usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c Fri Oct 29 16:54:51 2021 +0000
+++ b/usr.bin/indent/indent.c Fri Oct 29 16:59:35 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: indent.c,v 1.168 2021/10/29 16:54:51 rillig Exp $ */
+/* $NetBSD: indent.c,v 1.169 2021/10/29 16:59:35 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.168 2021/10/29 16:54:51 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.169 2021/10/29 16:59:35 rillig Exp $");
#elif defined(__FreeBSD__)
__FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
#endif
@@ -774,10 +774,10 @@
ps.want_blank = true;
ps.not_cast_mask &= (1 << ps.p_l_follow) - 1;
- if (--ps.p_l_follow < 0) {
- ps.p_l_follow = 0;
+ if (ps.p_l_follow > 0)
+ ps.p_l_follow--;
+ else
diag(0, "Extra '%c'", *token.s);
- }
if (code.e == code.s) /* if the paren starts the line */
ps.paren_level = ps.p_l_follow; /* then indent it */
@@ -915,8 +915,7 @@
}
*code.e++ = ';';
ps.want_blank = true;
- ps.in_stmt = ps.p_l_follow > 0; /* we are no longer in the middle of a
- * stmt */
+ ps.in_stmt = ps.p_l_follow > 0;
if (!*spaced_expr) { /* if not if for (;;) */
parse(psym_semicolon); /* let parser know about end of stmt */
@@ -1002,7 +1001,7 @@
parse(psym_semicolon);
}
- if (ps.p_l_follow != 0) { /* check for unclosed if, for, else. */
+ if (ps.p_l_follow > 0) { /* check for unclosed if, for, else. */
diag(1, "Unbalanced parentheses");
ps.p_l_follow = 0;
*spaced_expr = false;
diff -r 1e2a8e14ce82 -r e2f9066597a2 usr.bin/indent/indent.h
--- a/usr.bin/indent/indent.h Fri Oct 29 16:54:51 2021 +0000
+++ b/usr.bin/indent/indent.h Fri Oct 29 16:59:35 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: indent.h,v 1.56 2021/10/29 16:54:51 rillig Exp $ */
+/* $NetBSD: indent.h,v 1.57 2021/10/29 16:59:35 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -319,7 +319,7 @@
bool next_unary; /* whether the following operator should be
* unary */
int p_l_follow; /* used to remember how to indent the
- * following statement */
+ * remaining lines of the statement */
int paren_level; /* parenthesization level. used to indent
* within statements */
short paren_indents[20]; /* indentation of the operand/argument of each
diff -r 1e2a8e14ce82 -r e2f9066597a2 usr.bin/indent/lexi.c
--- a/usr.bin/indent/lexi.c Fri Oct 29 16:54:51 2021 +0000
+++ b/usr.bin/indent/lexi.c Fri Oct 29 16:59:35 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lexi.c,v 1.108 2021/10/29 16:54:51 rillig Exp $ */
+/* $NetBSD: lexi.c,v 1.109 2021/10/29 16:59:35 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@
#include <sys/cdefs.h>
#if defined(__NetBSD__)
-__RCSID("$NetBSD: lexi.c,v 1.108 2021/10/29 16:54:51 rillig Exp $");
+__RCSID("$NetBSD: lexi.c,v 1.109 2021/10/29 16:59:35 rillig Exp $");
#elif defined(__FreeBSD__)
__FBSDID("$FreeBSD: head/usr.bin/indent/lexi.c 337862 2018-08-15 18:19:45Z pstef $");
#endif
@@ -389,7 +389,7 @@
static bool
probably_typename(void)
{
- if (ps.p_l_follow != 0)
+ if (ps.p_l_follow > 0)
return false;
if (ps.block_init || ps.in_stmt)
return false;
@@ -487,7 +487,7 @@
case kw_struct_or_union_or_enum:
case kw_type:
found_typename:
- if (ps.p_l_follow != 0) {
+ if (ps.p_l_follow > 0) {
/* inside parentheses: cast, param list, offsetof or sizeof */
ps.cast_mask |= (1 << ps.p_l_follow) & ~ps.not_cast_mask;
}
@@ -496,7 +496,7 @@
break;
if (kw != NULL && kw->kind == kw_struct_or_union_or_enum)
return lsym_tag;
- if (ps.p_l_follow != 0)
+ if (ps.p_l_follow > 0)
break;
return lsym_type;
Home |
Main Index |
Thread Index |
Old Index