Module Name:    src
Committed By:   rillig
Date:           Thu Oct 28 22:20:08 UTC 2021

Modified Files:
        src/usr.bin/indent: args.c indent.c indent.h parse.c

Log Message:
indent: clean up indentation, comments, reduce

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.65 -r1.66 src/usr.bin/indent/args.c
cvs rdiff -u -r1.166 -r1.167 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.54 -r1.55 src/usr.bin/indent/indent.h
cvs rdiff -u -r1.43 -r1.44 src/usr.bin/indent/parse.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/args.c
diff -u src/usr.bin/indent/args.c:1.65 src/usr.bin/indent/args.c:1.66
--- src/usr.bin/indent/args.c:1.65	Thu Oct 28 21:35:57 2021
+++ src/usr.bin/indent/args.c	Thu Oct 28 22:20:08 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: args.c,v 1.65 2021/10/28 21:35:57 rillig Exp $	*/
+/*	$NetBSD: args.c,v 1.66 2021/10/28 22:20:08 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@ static char sccsid[] = "@(#)args.c	8.1 (
 
 #include <sys/cdefs.h>
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: args.c,v 1.65 2021/10/28 21:35:57 rillig Exp $");
+__RCSID("$NetBSD: args.c,v 1.66 2021/10/28 22:20:08 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/args.c 336318 2018-07-15 21:04:21Z pstef $");
 #endif
@@ -169,7 +169,7 @@ set_special_option(const char *arg, cons
 	opt.case_indent = (float)strtod(arg_end, &end);
 	if (*end != '\0')
 	    errx(1, "%s: argument \"%s\" to option \"-%.*s\" must be numeric",
-		 option_source, arg_end, (int)(arg_end - arg), arg);
+		option_source, arg_end, (int)(arg_end - arg), arg);
 	return true;
     }
 
@@ -283,7 +283,7 @@ load_profile(const char *fname, bool mus
 		break;
 	    } else if (n >= array_length(buf) - 5) {
 		errx(1, "buffer overflow in %s, starting with '%.10s'",
-		     fname, buf);
+		    fname, buf);
 	    } else
 		buf[n++] = (char)ch;
 	}

Index: src/usr.bin/indent/indent.c
diff -u src/usr.bin/indent/indent.c:1.166 src/usr.bin/indent/indent.c:1.167
--- src/usr.bin/indent/indent.c:1.166	Thu Oct 28 22:06:23 2021
+++ src/usr.bin/indent/indent.c	Thu Oct 28 22:20:08 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.166 2021/10/28 22:06:23 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.167 2021/10/28 22:20:08 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.166 2021/10/28 22:06:23 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.167 2021/10/28 22:20:08 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -791,7 +791,7 @@ process_rparen_or_rbracket(bool *spaced_
 	ps.next_unary = true;
 	ps.in_stmt = false;	/* don't use stmt continuation indentation */
 
-	parse_hd(hd);		/* let parser worry about if, or whatever */
+	parse_stmt_head(hd);
     }
 
     /*
@@ -908,10 +908,9 @@ process_semicolon(bool *seen_case, int *
 	 */
 	diag(1, "Unbalanced parens");
 	ps.p_l_follow = 0;
-	if (*spaced_expr) {	/* 'if', 'while', etc. with unbalanced
-				 * parentheses */
+	if (*spaced_expr) {	/* 'if', 'while', etc. */
 	    *spaced_expr = false;
-	    parse_hd(hd);	/* don't lose the 'if', or whatever */
+	    parse_stmt_head(hd);
 	}
     }
     *code.e++ = ';';
@@ -962,7 +961,7 @@ process_lbrace(bool *force_nl, bool *spa
 	ps.p_l_follow = 0;
 	if (*spaced_expr) {	/* check for unclosed 'if', 'for', etc. */
 	    *spaced_expr = false;
-	    parse_hd(hd);
+	    parse_stmt_head(hd);
 	    ps.ind_level = ps.ind_level_follow;
 	}
     }
@@ -1137,7 +1136,7 @@ process_ident(lexer_symbol lsym, int dec
 	*force_nl = true;
 	ps.next_unary = true;
 	ps.in_stmt = false;
-	parse_hd(hd);
+	parse_stmt_head(hd);
     }
 }
 

Index: src/usr.bin/indent/indent.h
diff -u src/usr.bin/indent/indent.h:1.54 src/usr.bin/indent/indent.h:1.55
--- src/usr.bin/indent/indent.h:1.54	Thu Oct 28 21:56:26 2021
+++ src/usr.bin/indent/indent.h	Thu Oct 28 22:20:08 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.h,v 1.54 2021/10/28 21:56:26 rillig Exp $	*/
+/*	$NetBSD: indent.h,v 1.55 2021/10/28 22:20:08 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -374,7 +374,7 @@ void dump_line(void);
 void dump_line_ff(void);
 void inbuf_read_line(void);
 void parse(parser_symbol);
-void parse_hd(stmt_head);
+void parse_stmt_head(stmt_head);
 void process_comment(void);
 void set_option(const char *, const char *);
 void load_profiles(const char *);

Index: src/usr.bin/indent/parse.c
diff -u src/usr.bin/indent/parse.c:1.43 src/usr.bin/indent/parse.c:1.44
--- src/usr.bin/indent/parse.c:1.43	Thu Oct 28 21:51:43 2021
+++ src/usr.bin/indent/parse.c	Thu Oct 28 22:20:08 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: parse.c,v 1.43 2021/10/28 21:51:43 rillig Exp $	*/
+/*	$NetBSD: parse.c,v 1.44 2021/10/28 22:20:08 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -246,7 +246,7 @@ parse(parser_symbol psym)
 }
 
 void
-parse_hd(stmt_head hd)
+parse_stmt_head(stmt_head hd)
 {
     static const parser_symbol psym[] = {
 	[hd_for] = psym_for_exprs,
@@ -257,10 +257,6 @@ parse_hd(stmt_head hd)
     parse(psym[hd]);
 }
 
-/*----------------------------------------------*\
-|   REDUCTION PHASE				 |
-\*----------------------------------------------*/
-
 /*
  * Try to combine the statement on the top of the parse stack with the symbol
  * directly below it, replacing these two symbols with a single symbol.
@@ -290,8 +286,8 @@ reduce_stmt(void)
 	ps.ind_level_follow = ps.s_ind_level[i];
 	/*
 	 * For the time being, assume that there is no 'else' on this 'if',
-	 * and set the indentation level accordingly. If an 'else' is
-	 * scanned, it will be fixed up later.
+	 * and set the indentation level accordingly. If an 'else' is scanned,
+	 * it will be fixed up later.
 	 */
 	return true;
 
@@ -314,21 +310,16 @@ reduce_stmt(void)
 /*
  * Repeatedly try to reduce the top two symbols on the parse stack to a
  * single symbol, until no more reductions are possible.
- *
- * On each reduction, ps.i_l_follow (the indentation for the following line)
- * is set to the indentation level associated with the old TOS.
  */
 static void
 reduce(void)
 {
 again:
-    if (ps.s_sym[ps.tos] == psym_stmt) {
-	if (reduce_stmt())
-	    goto again;
-    } else if (ps.s_sym[ps.tos] == psym_while_expr) {
-	if (ps.s_sym[ps.tos - 1] == psym_do_stmt) {
-	    ps.tos -= 2;
-	    goto again;
-	}
+    if (ps.s_sym[ps.tos] == psym_stmt && reduce_stmt())
+	goto again;
+    if (ps.s_sym[ps.tos] == psym_while_expr &&
+	    ps.s_sym[ps.tos - 1] == psym_do_stmt) {
+	ps.tos -= 2;		/* XXX: why not reduce to stmt? */
+	goto again;
     }
 }

Reply via email to