Module Name: src Committed By: rillig Date: Sat Apr 23 06:43:23 UTC 2022
Modified Files: src/tests/usr.bin/indent: opt_bacc.c src/usr.bin/indent: indent.c indent.h io.c pr_comment.c Log Message: indent: group global variables related to output control No functional change. To generate a diff of this commit: cvs rdiff -u -r1.7 -r1.8 src/tests/usr.bin/indent/opt_bacc.c cvs rdiff -u -r1.243 -r1.244 src/usr.bin/indent/indent.c cvs rdiff -u -r1.111 -r1.112 src/usr.bin/indent/indent.h cvs rdiff -u -r1.147 -r1.148 src/usr.bin/indent/io.c cvs rdiff -u -r1.126 -r1.127 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/tests/usr.bin/indent/opt_bacc.c diff -u src/tests/usr.bin/indent/opt_bacc.c:1.7 src/tests/usr.bin/indent/opt_bacc.c:1.8 --- src/tests/usr.bin/indent/opt_bacc.c:1.7 Fri Apr 22 21:21:20 2022 +++ src/tests/usr.bin/indent/opt_bacc.c Sat Apr 23 06:43:23 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: opt_bacc.c,v 1.7 2022/04/22 21:21:20 rillig Exp $ */ +/* $NetBSD: opt_bacc.c,v 1.8 2022/04/23 06:43:23 rillig Exp $ */ /* * Tests for the options '-bacc' and '-nbacc' ("blank line around conditional @@ -23,7 +23,7 @@ int c; /* * XXX: As of 2021-11-19, the option -bacc has no effect on declarations since - * process_type resets blank_line_before unconditionally. + * process_type resets out.blank_line_before unconditionally. */ #indent run -bacc int a; Index: src/usr.bin/indent/indent.c diff -u src/usr.bin/indent/indent.c:1.243 src/usr.bin/indent/indent.c:1.244 --- src/usr.bin/indent/indent.c:1.243 Sat Apr 23 06:32:20 2022 +++ src/usr.bin/indent/indent.c Sat Apr 23 06:43:22 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: indent.c,v 1.243 2022/04/23 06:32:20 rillig Exp $ */ +/* $NetBSD: indent.c,v 1.244 2022/04/23 06:43:22 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.243 2022/04/23 06:32:20 rillig Exp $"); +__RCSID("$NetBSD: indent.c,v 1.244 2022/04/23 06:43:22 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $"); #endif @@ -91,9 +91,6 @@ struct buffer code; struct buffer com; bool found_err; -int blank_lines_to_output; -bool blank_line_before; -bool blank_line_after; bool break_comma; float case_ind; bool had_eof; @@ -105,6 +102,7 @@ static struct parser_state state_stack[5 FILE *input; FILE *output; +struct output_control out; static const char *in_name = "Standard Input"; static const char *out_name = "Standard Output"; @@ -903,7 +901,7 @@ process_lbrace(bool *force_nl, bool *spa } if (ps.in_func_def_params) - blank_line_before = false; + out.blank_line_before = false; if (ps.nparen > 0) { diag(1, "Unbalanced parentheses"); @@ -929,7 +927,7 @@ process_lbrace(bool *force_nl, bool *spa * declaration, so don't do special * indentation of comments */ if (opt.blanklines_after_decl_at_top && ps.in_func_def_params) - blank_line_after = true; + out.blank_line_after = true; ps.in_func_def_params = false; ps.in_decl = false; } @@ -981,14 +979,14 @@ process_rbrace(bool *spaced_expr, int *d ps.in_decl = true; } - blank_line_before = false; + out.blank_line_before = false; parse(psym_rbrace); ps.search_stmt = opt.cuddle_else && ps.s_sym[ps.tos] == psym_if_expr_stmt && ps.s_ind_level[ps.tos] >= ps.ind_level; if (ps.tos <= 1 && opt.blanklines_after_procs && ps.decl_level <= 0) - blank_line_after = true; + out.blank_line_after = true; } static void @@ -1048,7 +1046,7 @@ process_type(int *decl_ind, bool *tabs_t if (ps.decl_level <= 0) ps.just_saw_decl = 2; - blank_line_before = false; + out.blank_line_before = false; int len = (int)buf_len(&token) + 1; int ind = ps.ind_level == 0 || ps.decl_level > 0 @@ -1242,11 +1240,11 @@ process_preprocessing(void) } if (opt.blanklines_around_conditional_compilation) { - blank_line_after = true; - blank_lines_to_output = 0; + out.blank_line_after = true; + out.blank_lines_to_output = 0; } else { - blank_line_after = false; - blank_line_before = false; + out.blank_line_after = false; + out.blank_line_before = false; } /* @@ -1386,7 +1384,7 @@ main_loop(void) case lsym_typedef: case lsym_storage_class: - blank_line_before = false; + out.blank_line_before = false; goto copy_token; case lsym_tag: Index: src/usr.bin/indent/indent.h diff -u src/usr.bin/indent/indent.h:1.111 src/usr.bin/indent/indent.h:1.112 --- src/usr.bin/indent/indent.h:1.111 Sun Feb 13 12:43:26 2022 +++ src/usr.bin/indent/indent.h Sat Apr 23 06:43:22 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: indent.h,v 1.111 2022/02/13 12:43:26 rillig Exp $ */ +/* $NetBSD: indent.h,v 1.112 2022/04/23 06:43:22 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD @@ -143,6 +143,13 @@ struct buffer { char *l; /* end of the allocated memory */ }; +extern struct output_control { + int blank_lines_to_output; + bool blank_line_before; + bool blank_line_after; + bool suppress_blanklines; +} out; + extern FILE *input; extern FILE *output; @@ -234,9 +241,6 @@ extern struct options { } opt; extern bool found_err; -extern int blank_lines_to_output; -extern bool blank_line_before; -extern bool blank_line_after; extern bool break_comma; /* when true and not in parentheses, break * after a comma */ extern float case_ind; /* indentation level to be used for a "case Index: src/usr.bin/indent/io.c diff -u src/usr.bin/indent/io.c:1.147 src/usr.bin/indent/io.c:1.148 --- src/usr.bin/indent/io.c:1.147 Sun Feb 13 12:48:12 2022 +++ src/usr.bin/indent/io.c Sat Apr 23 06:43:22 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: io.c,v 1.147 2022/02/13 12:48:12 rillig Exp $ */ +/* $NetBSD: io.c,v 1.148 2022/04/23 06:43:22 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.147 2022/02/13 12:48:12 rillig Exp $"); +__RCSID("$NetBSD: io.c,v 1.148 2022/04/23 06:43:22 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/io.c 334927 2018-06-10 16:44:18Z pstef $"); #endif @@ -93,7 +93,6 @@ static struct { } inbuf; static int paren_indent; -static bool suppress_blanklines; void @@ -516,24 +515,24 @@ output_complete_line(char line_terminato ps.is_function_definition = false; if (code.s == code.e && lab.s == lab.e && com.s == com.e) { - if (suppress_blanklines) - suppress_blanklines = false; + if (out.suppress_blanklines) + out.suppress_blanklines = false; else - blank_lines_to_output++; + out.blank_lines_to_output++; } else if (!inhibit_formatting) { - suppress_blanklines = false; - if (blank_line_before && !first_line) { + out.suppress_blanklines = false; + if (out.blank_line_before && !first_line) { if (opt.swallow_optional_blanklines) { - if (blank_lines_to_output == 1) - blank_lines_to_output = 0; + if (out.blank_lines_to_output == 1) + out.blank_lines_to_output = 0; } else { - if (blank_lines_to_output == 0) - blank_lines_to_output = 1; + if (out.blank_lines_to_output == 0) + out.blank_lines_to_output = 1; } } - for (; blank_lines_to_output > 0; blank_lines_to_output--) + for (; out.blank_lines_to_output > 0; out.blank_lines_to_output--) output_char('\n'); if (ps.ind_level == 0) @@ -555,11 +554,11 @@ output_complete_line(char line_terminato /* TODO: rename to blank_line_after_decl */ if (ps.just_saw_decl == 1 && opt.blanklines_after_decl) { - blank_line_before = true; + out.blank_line_before = true; ps.just_saw_decl = 0; } else - blank_line_before = blank_line_after; - blank_line_after = false; + out.blank_line_before = out.blank_line_after; + out.blank_line_after = false; } ps.decl_on_line = ps.in_decl; /* for proper comment indentation */ @@ -698,10 +697,10 @@ parse_indent_comment(void) * XXX: Does this make sense? Is the handling of blank lines above * INDENT OFF comments essentially the same? */ - blank_lines_to_output = 0; - blank_line_after = false; - blank_line_before = false; - suppress_blanklines = true; + out.blank_lines_to_output = 0; + out.blank_line_after = false; + out.blank_line_before = false; + out.suppress_blanklines = true; } } Index: src/usr.bin/indent/pr_comment.c diff -u src/usr.bin/indent/pr_comment.c:1.126 src/usr.bin/indent/pr_comment.c:1.127 --- src/usr.bin/indent/pr_comment.c:1.126 Sat Nov 27 18:37:17 2021 +++ src/usr.bin/indent/pr_comment.c Sat Apr 23 06:43:22 2022 @@ -1,4 +1,4 @@ -/* $NetBSD: pr_comment.c,v 1.126 2021/11/27 18:37:17 rillig Exp $ */ +/* $NetBSD: pr_comment.c,v 1.127 2022/04/23 06:43:22 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.126 2021/11/27 18:37:17 rillig Exp $"); +__RCSID("$NetBSD: pr_comment.c,v 1.127 2022/04/23 06:43:22 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/pr_comment.c 334927 2018-06-10 16:44:18Z pstef $"); #endif @@ -177,7 +177,7 @@ analyze_comment(bool *p_may_wrap, bool * if (break_delim) { if (opt.blanklines_before_block_comments && ps.prev_token != lsym_lbrace) - blank_line_before = true; + out.blank_line_before = true; output_line(); com_add_delim(); }