Module Name:    src
Committed By:   rillig
Date:           Sun Oct 24 11:17:05 UTC 2021

Modified Files:
        src/usr.bin/indent: indent.c indent.h io.c pr_comment.c

Log Message:
indent: replace global variable use_ff with function parameter


To generate a diff of this commit:
cvs rdiff -u -r1.144 -r1.145 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.43 -r1.44 src/usr.bin/indent/indent.h
cvs rdiff -u -r1.100 -r1.101 src/usr.bin/indent/io.c
cvs rdiff -u -r1.81 -r1.82 src/usr.bin/indent/pr_comment.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.144 src/usr.bin/indent/indent.c:1.145
--- src/usr.bin/indent/indent.c:1.144	Wed Oct 20 05:37:21 2021
+++ src/usr.bin/indent/indent.c	Sun Oct 24 11:17:05 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.144 2021/10/20 05:37:21 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.145 2021/10/24 11:17:05 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.144 2021/10/20 05:37:21 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.145 2021/10/24 11:17:05 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -662,8 +662,7 @@ process_comment_in_code(token_type ttype
 static void
 process_form_feed(void)
 {
-    ps.use_ff = true;
-    dump_line();
+    dump_line_ff();
     ps.want_blank = false;
 }
 

Index: src/usr.bin/indent/indent.h
diff -u src/usr.bin/indent/indent.h:1.43 src/usr.bin/indent/indent.h:1.44
--- src/usr.bin/indent/indent.h:1.43	Wed Oct 20 05:41:57 2021
+++ src/usr.bin/indent/indent.h	Sun Oct 24 11:17:05 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.h,v 1.43 2021/10/20 05:41:57 rillig Exp $	*/
+/*	$NetBSD: indent.h,v 1.44 2021/10/24 11:17:05 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -307,8 +307,6 @@ extern struct parser_state {
     bool search_brace;		/* whether it is necessary to buffer up all
 				 * info up to the start of a stmt after an if,
 				 * while, etc */
-    bool use_ff;		/* whether the current line should be
-				 * terminated with a form feed */
     bool want_blank;		/* whether the following token should be
 				 * prefixed by a blank. (Said prefixing is
 				 * ignored in some cases.) */
@@ -353,6 +351,7 @@ char inbuf_next(void);
 token_type lexi(struct parser_state *);
 void diag(int, const char *, ...)__printflike(2, 3);
 void dump_line(void);
+void dump_line_ff(void);
 void inbuf_read_line(void);
 void parse(token_type);
 void process_comment(void);

Index: src/usr.bin/indent/io.c
diff -u src/usr.bin/indent/io.c:1.100 src/usr.bin/indent/io.c:1.101
--- src/usr.bin/indent/io.c:1.100	Sun Oct 24 10:54:12 2021
+++ src/usr.bin/indent/io.c	Sun Oct 24 11:17:05 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: io.c,v 1.100 2021/10/24 10:54:12 rillig Exp $	*/
+/*	$NetBSD: io.c,v 1.101 2021/10/24 11:17:05 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@ static char sccsid[] = "@(#)io.c	8.1 (Be
 
 #include <sys/cdefs.h>
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: io.c,v 1.100 2021/10/24 10:54:12 rillig Exp $");
+__RCSID("$NetBSD: io.c,v 1.101 2021/10/24 11:17:05 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/io.c 334927 2018-06-10 16:44:18Z pstef $");
 #endif
@@ -207,8 +207,8 @@ dump_line_comment(int ind)
  * Write a line of formatted source to the output file. The line consists of a
  * label, the code and the comment.
  */
-void
-dump_line(void)
+static void
+output_line(char line_terminator)
 {
     static bool first_line = true;
 
@@ -254,10 +254,7 @@ dump_line(void)
 	if (com.e != com.s)
 	    dump_line_comment(ind);
 
-	if (ps.use_ff)
-	    output_char('\f');
-	else
-	    output_char('\n');
+	output_char(line_terminator);
 	ps.stats.lines++;
 
 	if (ps.just_saw_decl == 1 && opt.blanklines_after_decl) {
@@ -270,7 +267,6 @@ dump_line(void)
 
     ps.decl_on_line = ps.in_decl;	/* for proper comment indentation */
     ps.ind_stmt = ps.in_stmt && !ps.in_decl;
-    ps.use_ff = false;
     ps.dumped_decl_indent = false;
 
     *(lab.e = lab.s) = '\0';	/* reset buffers */
@@ -289,6 +285,18 @@ dump_line(void)
     first_line = false;
 }
 
+void
+dump_line(void)
+{
+    output_line('\n');
+}
+
+void
+dump_line_ff(void)
+{
+    output_line('\f');
+}
+
 int
 compute_code_indent(void)
 {

Index: src/usr.bin/indent/pr_comment.c
diff -u src/usr.bin/indent/pr_comment.c:1.81 src/usr.bin/indent/pr_comment.c:1.82
--- src/usr.bin/indent/pr_comment.c:1.81	Sun Oct 24 11:08:46 2021
+++ src/usr.bin/indent/pr_comment.c	Sun Oct 24 11:17:05 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: pr_comment.c,v 1.81 2021/10/24 11:08:46 rillig Exp $	*/
+/*	$NetBSD: pr_comment.c,v 1.82 2021/10/24 11:17:05 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@ static char sccsid[] = "@(#)pr_comment.c
 
 #include <sys/cdefs.h>
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: pr_comment.c,v 1.81 2021/10/24 11:08:46 rillig Exp $");
+__RCSID("$NetBSD: pr_comment.c,v 1.82 2021/10/24 11:17:05 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/pr_comment.c 334927 2018-06-10 16:44:18Z pstef $");
 #endif
@@ -225,8 +225,7 @@ process_comment(void)
 	switch (*inp.s) {
 	case '\f':
 	    if (may_wrap) {	/* in a text comment, break the line here */
-		ps.use_ff = true;
-		dump_line();
+		dump_line_ff();
 		last_blank = -1;
 		com_add_delim();
 		inp.s++;

Reply via email to