Module Name: src Committed By: rillig Date: Sat Sep 25 10:41:03 UTC 2021
Modified Files: src/usr.bin/indent: indent.c indent_globs.h io.c pr_comment.c Log Message: indent: move statistical values into a separate struct No functional change. To generate a diff of this commit: cvs rdiff -u -r1.68 -r1.69 src/usr.bin/indent/indent.c cvs rdiff -u -r1.26 -r1.27 src/usr.bin/indent/indent_globs.h cvs rdiff -u -r1.57 -r1.58 src/usr.bin/indent/io.c cvs rdiff -u -r1.40 -r1.41 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.68 src/usr.bin/indent/indent.c:1.69 --- src/usr.bin/indent/indent.c:1.68 Sat Sep 25 08:23:31 2021 +++ src/usr.bin/indent/indent.c Sat Sep 25 10:41:03 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: indent.c,v 1.68 2021/09/25 08:23:31 rillig Exp $ */ +/* $NetBSD: indent.c,v 1.69 2021/09/25 10:41:03 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)indent.c 5.1 #include <sys/cdefs.h> #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: indent.c,v 1.68 2021/09/25 08:23:31 rillig Exp $"); +__RCSID("$NetBSD: indent.c,v 1.69 2021/09/25 10:41:03 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $"); #endif @@ -94,7 +94,6 @@ int prefix_blankline_requested; int postfix_blankline_requested; int break_comma; float case_ind; -int code_lines; int had_eof; int line_no; int inhibit_formatting; @@ -528,9 +527,9 @@ process_end_of_file(void) if (opt.verbose) { printf("There were %d output lines and %d comments\n", - ps.out_lines, ps.out_coms); + ps.stats.lines, ps.stats.comments); printf("(Lines with comments)/(Lines with code): %6.3f\n", - (1.0 * ps.com_lines) / code_lines); + (1.0 * ps.stats.comment_lines) / ps.stats.code_lines); } fflush(output); Index: src/usr.bin/indent/indent_globs.h diff -u src/usr.bin/indent/indent_globs.h:1.26 src/usr.bin/indent/indent_globs.h:1.27 --- src/usr.bin/indent/indent_globs.h:1.26 Sat Sep 25 08:04:13 2021 +++ src/usr.bin/indent/indent_globs.h Sat Sep 25 10:41:03 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: indent_globs.h,v 1.26 2021/09/25 08:04:13 rillig Exp $ */ +/* $NetBSD: indent_globs.h,v 1.27 2021/09/25 10:41:03 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -184,7 +184,6 @@ extern int break_comma; /* when * comma */ extern float case_ind; /* indentation level to be used for a "case * n:" */ -extern int code_lines; /* count of lines with code */ extern int had_eof; /* set to true when input is exhausted */ extern int line_no; /* the current line number. */ extern int inhibit_formatting; /* true if INDENT OFF is in effect */ @@ -226,8 +225,6 @@ extern struct parser_state { * column 1 */ int com_col; /* this is the column in which the current * comment should start */ - int com_lines; /* the number of lines with comments, set by - * dump_line */ int dec_nest; /* current nesting level for structure or init */ int decl_on_line; /* set to true if this line of code has part * of a declaration on it */ @@ -243,10 +240,6 @@ extern struct parser_state { * middle of a stmt */ int last_u_d; /* set to true after scanning a token which * forces a following operator to be unary */ - int out_coms; /* the number of comments processed, set by - * process_comment */ - int out_lines; /* the number of lines written, set by - * dump_line */ int p_l_follow; /* used to remember how to indent following * statement */ int paren_level; /* parenthesization level. used to indent @@ -271,6 +264,13 @@ extern struct parser_state { int tos; /* pointer to top of stack */ char procname[100]; /* The name of the current procedure */ int just_saw_decl; + + struct { + int comments; + int lines; + int code_lines; + int comment_lines; + } stats; } ps; extern int ifdef_level; Index: src/usr.bin/indent/io.c diff -u src/usr.bin/indent/io.c:1.57 src/usr.bin/indent/io.c:1.58 --- src/usr.bin/indent/io.c:1.57 Sat Sep 25 08:23:31 2021 +++ src/usr.bin/indent/io.c Sat Sep 25 10:41:03 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: io.c,v 1.57 2021/09/25 08:23:31 rillig Exp $ */ +/* $NetBSD: io.c,v 1.58 2021/09/25 10:41:03 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)io.c 8.1 (Be #include <sys/cdefs.h> #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: io.c,v 1.57 2021/09/25 08:23:31 rillig Exp $"); +__RCSID("$NetBSD: io.c,v 1.58 2021/09/25 10:41:03 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/io.c 334927 2018-06-10 16:44:18Z pstef $"); #endif @@ -151,7 +151,7 @@ dump_line(void) * at bracket level 0 */ if (lab.e != lab.s || code.e != code.s) - ++code_lines; /* keep count of lines with code */ + ps.stats.code_lines++; if (lab.e != lab.s) { /* print lab, if any */ @@ -237,20 +237,20 @@ dump_line(void) * put it on next line */ output_char('\n'); cur_col = 1; - ++ps.out_lines; + ps.stats.lines++; } while (com.e > com_st && isspace((unsigned char)com.e[-1])) com.e--; (void)output_indent(cur_col - 1, target_col - 1); output_range(com_st, com.e); ps.comment_delta = ps.n_comment_delta; - ++ps.com_lines; /* count lines with comments */ + ps.stats.comment_lines++; } if (ps.use_ff) output_char('\014'); else output_char('\n'); - ++ps.out_lines; + ps.stats.lines++; if (ps.just_saw_decl == 1 && opt.blanklines_after_declarations) { prefix_blankline_requested = 1; ps.just_saw_decl = 0; Index: src/usr.bin/indent/pr_comment.c diff -u src/usr.bin/indent/pr_comment.c:1.40 src/usr.bin/indent/pr_comment.c:1.41 --- src/usr.bin/indent/pr_comment.c:1.40 Sat Sep 25 08:23:31 2021 +++ src/usr.bin/indent/pr_comment.c Sat Sep 25 10:41:03 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: pr_comment.c,v 1.40 2021/09/25 08:23:31 rillig Exp $ */ +/* $NetBSD: pr_comment.c,v 1.41 2021/09/25 10:41:03 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -46,7 +46,7 @@ static char sccsid[] = "@(#)pr_comment.c #include <sys/cdefs.h> #ifndef lint #if defined(__NetBSD__) -__RCSID("$NetBSD: pr_comment.c,v 1.40 2021/09/25 08:23:31 rillig Exp $"); +__RCSID("$NetBSD: pr_comment.c,v 1.41 2021/09/25 10:41:03 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/pr_comment.c 334927 2018-06-10 16:44:18Z pstef $"); #endif @@ -107,7 +107,7 @@ process_comment(void) ps.box_com = false; /* at first, assume that we are not in * a boxed comment or some other * comment that should not be touched */ - ++ps.out_coms; /* keep track of number of comments */ + ps.stats.comments++; /* Figure where to align and how to treat the comment */