Module Name:    src
Committed By:   rillig
Date:           Fri Oct 29 16:59:35 UTC 2021

Modified Files:
        src/usr.bin/indent: indent.c indent.h lexi.c

Log Message:
indent: keep p_l_follow nonnegative, use consistent comparison

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.168 -r1.169 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.56 -r1.57 src/usr.bin/indent/indent.h
cvs rdiff -u -r1.108 -r1.109 src/usr.bin/indent/lexi.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.168 src/usr.bin/indent/indent.c:1.169
--- src/usr.bin/indent/indent.c:1.168	Fri Oct 29 16:54:51 2021
+++ src/usr.bin/indent/indent.c	Fri Oct 29 16:59:35 2021
@@ -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 @@ static char sccsid[] = "@(#)indent.c	5.1
 
 #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 @@ process_rparen_or_rbracket(bool *spaced_
 	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 @@ process_semicolon(bool *seen_case, int *
     }
     *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 @@ process_rbrace(bool *spaced_expr, int *d
 	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;

Index: src/usr.bin/indent/indent.h
diff -u src/usr.bin/indent/indent.h:1.56 src/usr.bin/indent/indent.h:1.57
--- src/usr.bin/indent/indent.h:1.56	Fri Oct 29 16:54:51 2021
+++ src/usr.bin/indent/indent.h	Fri Oct 29 16:59:35 2021
@@ -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 @@ extern struct parser_state {
     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

Index: src/usr.bin/indent/lexi.c
diff -u src/usr.bin/indent/lexi.c:1.108 src/usr.bin/indent/lexi.c:1.109
--- src/usr.bin/indent/lexi.c:1.108	Fri Oct 29 16:54:51 2021
+++ src/usr.bin/indent/lexi.c	Fri Oct 29 16:59:35 2021
@@ -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 @@ static char sccsid[] = "@(#)lexi.c	8.1 (
 
 #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 @@ lex_char_or_string(void)
 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 @@ lexi_alnum(void)
 	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 @@ lexi_alnum(void)
 		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;
 

Reply via email to