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: group global variables related to out...



details:   https://anonhg.NetBSD.org/src/rev/6570eb03e911
branches:  trunk
changeset: 365748:6570eb03e911
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Apr 23 06:43:22 2022 +0000

description:
indent: group global variables related to output control

No functional change.

diffstat:

 tests/usr.bin/indent/opt_bacc.c |   4 ++--
 usr.bin/indent/indent.c         |  28 +++++++++++++---------------
 usr.bin/indent/indent.h         |  12 ++++++++----
 usr.bin/indent/io.c             |  39 +++++++++++++++++++--------------------
 usr.bin/indent/pr_comment.c     |   6 +++---
 5 files changed, 45 insertions(+), 44 deletions(-)

diffs (274 lines):

diff -r a2f407f896ea -r 6570eb03e911 tests/usr.bin/indent/opt_bacc.c
--- a/tests/usr.bin/indent/opt_bacc.c   Sat Apr 23 06:32:20 2022 +0000
+++ b/tests/usr.bin/indent/opt_bacc.c   Sat Apr 23 06:43:22 2022 +0000
@@ -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 @@
 
 /*
  * 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;
diff -r a2f407f896ea -r 6570eb03e911 usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c   Sat Apr 23 06:32:20 2022 +0000
+++ b/usr.bin/indent/indent.c   Sat Apr 23 06:43:22 2022 +0000
@@ -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 @@
 
 #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 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 @@
 
 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 @@
     }
 
     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 @@
                                         * 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 @@
        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 @@
     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 @@
     }
 
     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 @@
 
        case lsym_typedef:
        case lsym_storage_class:
-           blank_line_before = false;
+           out.blank_line_before = false;
            goto copy_token;
 
        case lsym_tag:
diff -r a2f407f896ea -r 6570eb03e911 usr.bin/indent/indent.h
--- a/usr.bin/indent/indent.h   Sat Apr 23 06:32:20 2022 +0000
+++ b/usr.bin/indent/indent.h   Sat Apr 23 06:43:22 2022 +0000
@@ -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 @@
     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 @@
 } 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
diff -r a2f407f896ea -r 6570eb03e911 usr.bin/indent/io.c
--- a/usr.bin/indent/io.c       Sat Apr 23 06:32:20 2022 +0000
+++ b/usr.bin/indent/io.c       Sat Apr 23 06:43:22 2022 +0000
@@ -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 @@
 
 #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 @@
 } inbuf;
 
 static int paren_indent;
-static bool suppress_blanklines;
 
 
 void
@@ -516,24 +515,24 @@
     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 @@
 
        /* 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 @@
         * 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;
     }
 }
 
diff -r a2f407f896ea -r 6570eb03e911 usr.bin/indent/pr_comment.c
--- a/usr.bin/indent/pr_comment.c       Sat Apr 23 06:32:20 2022 +0000
+++ b/usr.bin/indent/pr_comment.c       Sat Apr 23 06:43:22 2022 +0000
@@ -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 @@
 
 #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 @@
     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();
     }



Home | Main Index | Thread Index | Old Index