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 indentation, comments, reduce



details:   https://anonhg.NetBSD.org/src/rev/f1324bb982f0
branches:  trunk
changeset: 990489:f1324bb982f0
user:      rillig <rillig%NetBSD.org@localhost>
date:      Thu Oct 28 22:20:08 2021 +0000

description:
indent: clean up indentation, comments, reduce

No functional change.

diffstat:

 usr.bin/indent/args.c   |   8 ++++----
 usr.bin/indent/indent.c |  15 +++++++--------
 usr.bin/indent/indent.h |   4 ++--
 usr.bin/indent/parse.c  |  29 ++++++++++-------------------
 4 files changed, 23 insertions(+), 33 deletions(-)

diffs (180 lines):

diff -r 25e31e7c9780 -r f1324bb982f0 usr.bin/indent/args.c
--- a/usr.bin/indent/args.c     Thu Oct 28 22:06:23 2021 +0000
+++ b/usr.bin/indent/args.c     Thu Oct 28 22:20:08 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: args.c,v 1.65 2021/10/28 21:35:57 rillig Exp $ */
+/*     $NetBSD: args.c,v 1.66 2021/10/28 22:20:08 rillig Exp $ */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: args.c,v 1.65 2021/10/28 21:35:57 rillig Exp $");
+__RCSID("$NetBSD: args.c,v 1.66 2021/10/28 22:20:08 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/args.c 336318 2018-07-15 21:04:21Z pstef $");
 #endif
@@ -169,7 +169,7 @@
        opt.case_indent = (float)strtod(arg_end, &end);
        if (*end != '\0')
            errx(1, "%s: argument \"%s\" to option \"-%.*s\" must be numeric",
-                option_source, arg_end, (int)(arg_end - arg), arg);
+               option_source, arg_end, (int)(arg_end - arg), arg);
        return true;
     }
 
@@ -283,7 +283,7 @@
                break;
            } else if (n >= array_length(buf) - 5) {
                errx(1, "buffer overflow in %s, starting with '%.10s'",
-                    fname, buf);
+                   fname, buf);
            } else
                buf[n++] = (char)ch;
        }
diff -r 25e31e7c9780 -r f1324bb982f0 usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c   Thu Oct 28 22:06:23 2021 +0000
+++ b/usr.bin/indent/indent.c   Thu Oct 28 22:20:08 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: indent.c,v 1.166 2021/10/28 22:06:23 rillig Exp $      */
+/*     $NetBSD: indent.c,v 1.167 2021/10/28 22:20:08 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.166 2021/10/28 22:06:23 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.167 2021/10/28 22:20:08 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -791,7 +791,7 @@
        ps.next_unary = true;
        ps.in_stmt = false;     /* don't use stmt continuation indentation */
 
-       parse_hd(hd);           /* let parser worry about if, or whatever */
+       parse_stmt_head(hd);
     }
 
     /*
@@ -908,10 +908,9 @@
         */
        diag(1, "Unbalanced parens");
        ps.p_l_follow = 0;
-       if (*spaced_expr) {     /* 'if', 'while', etc. with unbalanced
-                                * parentheses */
+       if (*spaced_expr) {     /* 'if', 'while', etc. */
            *spaced_expr = false;
-           parse_hd(hd);       /* don't lose the 'if', or whatever */
+           parse_stmt_head(hd);
        }
     }
     *code.e++ = ';';
@@ -962,7 +961,7 @@
        ps.p_l_follow = 0;
        if (*spaced_expr) {     /* check for unclosed 'if', 'for', etc. */
            *spaced_expr = false;
-           parse_hd(hd);
+           parse_stmt_head(hd);
            ps.ind_level = ps.ind_level_follow;
        }
     }
@@ -1137,7 +1136,7 @@
        *force_nl = true;
        ps.next_unary = true;
        ps.in_stmt = false;
-       parse_hd(hd);
+       parse_stmt_head(hd);
     }
 }
 
diff -r 25e31e7c9780 -r f1324bb982f0 usr.bin/indent/indent.h
--- a/usr.bin/indent/indent.h   Thu Oct 28 22:06:23 2021 +0000
+++ b/usr.bin/indent/indent.h   Thu Oct 28 22:20:08 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: indent.h,v 1.54 2021/10/28 21:56:26 rillig Exp $       */
+/*     $NetBSD: indent.h,v 1.55 2021/10/28 22:20:08 rillig Exp $       */
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -374,7 +374,7 @@
 void dump_line_ff(void);
 void inbuf_read_line(void);
 void parse(parser_symbol);
-void parse_hd(stmt_head);
+void parse_stmt_head(stmt_head);
 void process_comment(void);
 void set_option(const char *, const char *);
 void load_profiles(const char *);
diff -r 25e31e7c9780 -r f1324bb982f0 usr.bin/indent/parse.c
--- a/usr.bin/indent/parse.c    Thu Oct 28 22:06:23 2021 +0000
+++ b/usr.bin/indent/parse.c    Thu Oct 28 22:20:08 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: parse.c,v 1.43 2021/10/28 21:51:43 rillig Exp $        */
+/*     $NetBSD: parse.c,v 1.44 2021/10/28 22:20:08 rillig Exp $        */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -246,7 +246,7 @@
 }
 
 void
-parse_hd(stmt_head hd)
+parse_stmt_head(stmt_head hd)
 {
     static const parser_symbol psym[] = {
        [hd_for] = psym_for_exprs,
@@ -257,10 +257,6 @@
     parse(psym[hd]);
 }
 
-/*----------------------------------------------*\
-|   REDUCTION PHASE                             |
-\*----------------------------------------------*/
-
 /*
  * Try to combine the statement on the top of the parse stack with the symbol
  * directly below it, replacing these two symbols with a single symbol.
@@ -290,8 +286,8 @@
        ps.ind_level_follow = ps.s_ind_level[i];
        /*
         * For the time being, assume that there is no 'else' on this 'if',
-        * and set the indentation level accordingly. If an 'else' is
-        * scanned, it will be fixed up later.
+        * and set the indentation level accordingly. If an 'else' is scanned,
+        * it will be fixed up later.
         */
        return true;
 
@@ -314,21 +310,16 @@
 /*
  * Repeatedly try to reduce the top two symbols on the parse stack to a
  * single symbol, until no more reductions are possible.
- *
- * On each reduction, ps.i_l_follow (the indentation for the following line)
- * is set to the indentation level associated with the old TOS.
  */
 static void
 reduce(void)
 {
 again:
-    if (ps.s_sym[ps.tos] == psym_stmt) {
-       if (reduce_stmt())
-           goto again;
-    } else if (ps.s_sym[ps.tos] == psym_while_expr) {
-       if (ps.s_sym[ps.tos - 1] == psym_do_stmt) {
-           ps.tos -= 2;
-           goto again;
-       }
+    if (ps.s_sym[ps.tos] == psym_stmt && reduce_stmt())
+       goto again;
+    if (ps.s_sym[ps.tos] == psym_while_expr &&
+           ps.s_sym[ps.tos - 1] == psym_do_stmt) {
+       ps.tos -= 2;            /* XXX: why not reduce to stmt? */
+       goto again;
     }
 }



Home | Main Index | Thread Index | Old Index