Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/indent indent: move statistical values into a separa...



details:   https://anonhg.NetBSD.org/src/rev/ee78e8d277b6
branches:  trunk
changeset: 1023740:ee78e8d277b6
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Sep 25 10:41:03 2021 +0000

description:
indent: move statistical values into a separate struct

No functional change.

diffstat:

 usr.bin/indent/indent.c       |   9 ++++-----
 usr.bin/indent/indent_globs.h |  16 ++++++++--------
 usr.bin/indent/io.c           |  12 ++++++------
 usr.bin/indent/pr_comment.c   |   6 +++---
 4 files changed, 21 insertions(+), 22 deletions(-)

diffs (167 lines):

diff -r 441ee8c63a76 -r ee78e8d277b6 usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c   Sat Sep 25 10:24:10 2021 +0000
+++ b/usr.bin/indent/indent.c   Sat Sep 25 10:41:03 2021 +0000
@@ -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 @@
 #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         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 @@
 
     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);
diff -r 441ee8c63a76 -r ee78e8d277b6 usr.bin/indent/indent_globs.h
--- a/usr.bin/indent/indent_globs.h     Sat Sep 25 10:24:10 2021 +0000
+++ b/usr.bin/indent/indent_globs.h     Sat Sep 25 10:41:03 2021 +0000
@@ -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 @@
                                 * 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 @@
                                 * 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 @@
                                 * 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 @@
     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;
diff -r 441ee8c63a76 -r ee78e8d277b6 usr.bin/indent/io.c
--- a/usr.bin/indent/io.c       Sat Sep 25 10:24:10 2021 +0000
+++ b/usr.bin/indent/io.c       Sat Sep 25 10:41:03 2021 +0000
@@ -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 @@
 #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 @@
                                 * 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 @@
                                 * 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;
diff -r 441ee8c63a76 -r ee78e8d277b6 usr.bin/indent/pr_comment.c
--- a/usr.bin/indent/pr_comment.c       Sat Sep 25 10:24:10 2021 +0000
+++ b/usr.bin/indent/pr_comment.c       Sat Sep 25 10:41:03 2021 +0000
@@ -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 @@
 #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 @@
     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 */
 



Home | Main Index | Thread Index | Old Index