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: clean up main_init_globals



details:   https://anonhg.NetBSD.org/src/rev/8c646c7a257d
branches:  trunk
changeset: 1024599:8c646c7a257d
user:      rillig <rillig%NetBSD.org@localhost>
date:      Fri Oct 29 19:22:55 2021 +0000

description:
indent: clean up main_init_globals

No functional change.

diffstat:

 tests/usr.bin/indent/t_misc.sh |  15 ++++++++++++++-
 usr.bin/indent/indent.c        |  39 ++++++++++++---------------------------
 2 files changed, 26 insertions(+), 28 deletions(-)

diffs (115 lines):

diff -r 63267874a8d5 -r 8c646c7a257d tests/usr.bin/indent/t_misc.sh
--- a/tests/usr.bin/indent/t_misc.sh    Fri Oct 29 19:12:48 2021 +0000
+++ b/tests/usr.bin/indent/t_misc.sh    Fri Oct 29 19:22:55 2021 +0000
@@ -1,5 +1,5 @@
 #! /bin/sh
-# $NetBSD: t_misc.sh,v 1.10 2021/10/29 16:54:51 rillig Exp $
+# $NetBSD: t_misc.sh,v 1.11 2021/10/29 19:22:55 rillig Exp $
 #
 # Copyright (c) 2021 The NetBSD Foundation, Inc.
 # All rights reserved.
@@ -323,6 +323,18 @@
            "$indent" code.c -st
 }
 
+atf_test_case 'default_backup_extension'
+default_backup_extension_body()
+{
+       echo 'int var;' > code.c
+       echo 'int var;' > code.c.orig
+
+       atf_check \
+           "$indent" code.c
+       atf_check -o 'file:code.c.orig' \
+           cat code.c.BAK
+}
+
 atf_init_test_cases()
 {
        atf_add_test_case 'in_place'
@@ -333,4 +345,5 @@
        atf_add_test_case 'opt_npro'
        atf_add_test_case 'opt_U'
        atf_add_test_case 'line_no_counting'
+       atf_add_test_case 'default_backup_extension'
 }
diff -r 63267874a8d5 -r 8c646c7a257d usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c   Fri Oct 29 19:12:48 2021 +0000
+++ b/usr.bin/indent/indent.c   Fri Oct 29 19:22:55 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: indent.c,v 1.173 2021/10/29 19:12:48 rillig Exp $      */
+/*     $NetBSD: indent.c,v 1.174 2021/10/29 19:22:55 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.173 2021/10/29 19:12:48 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.174 2021/10/29 19:22:55 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -85,7 +85,11 @@
     .use_tabs = true,
 };
 
-struct parser_state ps;
+struct parser_state ps = {
+    .s_sym[0] = psym_stmt,
+    .prev_token = lsym_semicolon,
+    .prev_newline = true,
+};
 
 struct buffer lab;
 struct buffer code;
@@ -108,7 +112,7 @@
 bool break_comma;
 float case_ind;
 bool had_eof;
-int line_no;
+int line_no = 1;
 bool inhibit_formatting;
 
 static int ifdef_level;
@@ -454,35 +458,16 @@
 static void
 main_init_globals(void)
 {
-    found_err = false;
-
-    ps.s_sym[0] = psym_stmt;
-    ps.prev_newline = true;
-    ps.prev_token = lsym_semicolon;
-    buf_init(&com);
-    buf_init(&lab);
-    buf_init(&code);
-    buf_init(&token);
-
-    opt.else_if = true;                /* XXX: redundant? */
-
     inp.buf = xmalloc(10);
     inp.l = inp.buf + 8;
     inp.s = inp.buf;
     inp.e = inp.buf;
 
-    line_no = 1;
-    had_eof = ps.in_decl = ps.decl_on_line = break_comma = false;
+    buf_init(&token);
 
-    ps.init_or_struct = false;
-    ps.want_blank = ps.in_stmt = ps.ind_stmt = false;
-    ps.is_case_label = false;
-
-    sc_end = NULL;
-    saved_inp_s = NULL;
-    saved_inp_e = NULL;
-
-    output = NULL;
+    buf_init(&com);
+    buf_init(&lab);
+    buf_init(&code);
 
     const char *suffix = getenv("SIMPLE_BACKUP_SUFFIX");
     if (suffix != NULL)



Home | Main Index | Thread Index | Old Index