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: run indent on its own source code



details:   https://anonhg.NetBSD.org/src/rev/4d6a7d41415d
branches:  trunk
changeset: 1024494:4d6a7d41415d
user:      rillig <rillig%NetBSD.org@localhost>
date:      Tue Oct 26 19:36:30 2021 +0000

description:
indent: run indent on its own source code

With manual corrections afterwards, to compensate for the remaining bugs
in indent.

Without the type definitions in .indent.pro, the opening braces of the
functions kw_name and lexi_alnum would not be at the beginning of the
line.

diffstat:

 usr.bin/indent/.indent.pro |   6 ++++--
 usr.bin/indent/args.c      |   6 +++---
 usr.bin/indent/indent.c    |  16 ++++++++--------
 usr.bin/indent/indent.h    |   6 +++---
 usr.bin/indent/lexi.c      |  16 ++++++++--------
 usr.bin/indent/parse.c     |   8 ++++----
 6 files changed, 30 insertions(+), 28 deletions(-)

diffs (202 lines):

diff -r 4855e9a80982 -r 4d6a7d41415d usr.bin/indent/.indent.pro
--- a/usr.bin/indent/.indent.pro        Tue Oct 26 18:36:25 2021 +0000
+++ b/usr.bin/indent/.indent.pro        Tue Oct 26 19:36:30 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: .indent.pro,v 1.2 2021/10/05 22:09:05 rillig Exp $ */
+/* $NetBSD: .indent.pro,v 1.3 2021/10/26 19:36:30 rillig Exp $ */
 
 -di0           /* Do not indent variable names in global declarations. */
 /* XXX: -eei does not work; the expressions are indented only a single level. */
@@ -9,4 +9,6 @@
 -nlp           /* Do not indent function arguments. */
 -ta            /* Identifiers ending in '_t' are considered type names. */
 -TFILE         /* Additional types, for proper formatting of '*'. */
--Ttoken_type
+-Tlexer_symbol
+-Tparser_symbol
+-Tkeyword_kind
diff -r 4855e9a80982 -r 4d6a7d41415d usr.bin/indent/args.c
--- a/usr.bin/indent/args.c     Tue Oct 26 18:36:25 2021 +0000
+++ b/usr.bin/indent/args.c     Tue Oct 26 19:36:30 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: args.c,v 1.59 2021/10/24 19:14:33 rillig Exp $ */
+/*     $NetBSD: args.c,v 1.60 2021/10/26 19:36:30 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.59 2021/10/24 19:14:33 rillig Exp $");
+__RCSID("$NetBSD: args.c,v 1.60 2021/10/26 19:36:30 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/args.c 336318 2018-07-15 21:04:21Z pstef $");
 #endif
@@ -89,7 +89,7 @@
     short i_min;
     short i_max;
     void *p_var;               /* the associated variable */
-}   pro[] = {
+} pro[] = {
     bool_options("bacc", blanklines_around_conditional_compilation),
     bool_options("bad", blanklines_after_decl),
     bool_options("badp", blanklines_after_decl_at_top),
diff -r 4855e9a80982 -r 4d6a7d41415d usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c   Tue Oct 26 18:36:25 2021 +0000
+++ b/usr.bin/indent/indent.c   Tue Oct 26 19:36:30 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: indent.c,v 1.159 2021/10/25 21:33:24 rillig Exp $      */
+/*     $NetBSD: indent.c,v 1.160 2021/10/26 19:36:30 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.159 2021/10/25 21:33:24 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.160 2021/10/26 19:36:30 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -245,10 +245,10 @@
     bool remove_newlines;
 
     remove_newlines =
-           /* "} else" */
-           (lsym == lsym_else && code.e != code.s && code.e[-1] == '}')
-           /* "else if" */
-           || (lsym == lsym_if && last_else && opt.else_if);
+       /* "} else" */
+       (lsym == lsym_else && code.e != code.s && code.e[-1] == '}')
+       /* "else if" */
+       || (lsym == lsym_if && last_else && opt.else_if);
     if (remove_newlines)
        *force_nl = false;
 
@@ -1333,8 +1333,8 @@
     bool tabs_to_var = false;  /* true if using tabs to indent to var name */
     bool spaced_expr = false;  /* whether we are in the expression of
                                 * if(...), while(...), etc. */
-    stmt_head hd = hd_0;       /* the type of statement for 'if (...)',
-                                * 'for (...)', etc */
+    stmt_head hd = hd_0;       /* the type of statement for 'if (...)', 'for
+                                * (...)', etc */
     int quest_level = 0;       /* when this is positive, we have seen a '?'
                                 * without the matching ':' in a '?:'
                                 * expression */
diff -r 4855e9a80982 -r 4d6a7d41415d usr.bin/indent/indent.h
--- a/usr.bin/indent/indent.h   Tue Oct 26 18:36:25 2021 +0000
+++ b/usr.bin/indent/indent.h   Tue Oct 26 19:36:30 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: indent.h,v 1.50 2021/10/25 19:56:03 rillig Exp $       */
+/*     $NetBSD: indent.h,v 1.51 2021/10/26 19:36:30 rillig Exp $       */
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -235,7 +235,7 @@
                                 * uses all spaces */
     bool verbose;              /* whether non-essential error messages are
                                 * printed */
-}       opt;
+} opt;
 
 enum keyword_kind {
     kw_0,
@@ -344,7 +344,7 @@
        int code_lines;
        int comment_lines;
     }      stats;
-}            ps;
+} ps;
 
 
 #define array_length(array) (sizeof (array) / sizeof (array[0]))
diff -r 4855e9a80982 -r 4d6a7d41415d usr.bin/indent/lexi.c
--- a/usr.bin/indent/lexi.c     Tue Oct 26 18:36:25 2021 +0000
+++ b/usr.bin/indent/lexi.c     Tue Oct 26 19:36:30 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lexi.c,v 1.102 2021/10/26 18:36:25 rillig Exp $        */
+/*     $NetBSD: lexi.c,v 1.103 2021/10/26 19:36:30 rillig Exp $        */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: lexi.c,v 1.102 2021/10/26 18:36:25 rillig Exp $");
+__RCSID("$NetBSD: lexi.c,v 1.103 2021/10/26 19:36:30 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/lexi.c 337862 2018-08-15 18:19:45Z pstef $");
 #endif
@@ -261,7 +261,8 @@
 }
 
 static const char *
-kw_name(enum keyword_kind kw) {
+kw_name(enum keyword_kind kw)
+{
     static const char *name[] = {
        "0",
        "offsetof",
@@ -437,8 +438,8 @@
     if (isdigit((unsigned char)*inp.s) ||
        (inp.s[0] == '.' && isdigit((unsigned char)inp.s[1]))) {
        lex_number();
-    } else if ((isalnum((unsigned char)*inp.s) ||
-               *inp.s == '_' || *inp.s == '$')) {
+    } else if (isalnum((unsigned char)*inp.s) ||
+           *inp.s == '_' || *inp.s == '$') {
        lex_word();
     } else
        return lsym_eof;        /* just as a placeholder */
@@ -453,8 +454,7 @@
        inbuf_skip();
     state->keyword = kw_0;
 
-    if (state->last_token == lsym_tag &&
-           state->p_l_follow == 0) {
+    if (state->last_token == lsym_tag && state->p_l_follow == 0) {
        state->next_unary = true;
        return lsym_type;
     }
@@ -717,7 +717,7 @@
            char *tp = inp.s;
 
            while (isalpha((unsigned char)*tp) ||
-                  isspace((unsigned char)*tp)) {
+                   isspace((unsigned char)*tp)) {
                if (++tp >= inp.e)
                    inbuf_read_line();
            }
diff -r 4855e9a80982 -r 4d6a7d41415d usr.bin/indent/parse.c
--- a/usr.bin/indent/parse.c    Tue Oct 26 18:36:25 2021 +0000
+++ b/usr.bin/indent/parse.c    Tue Oct 26 19:36:30 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: parse.c,v 1.41 2021/10/25 20:32:38 rillig Exp $        */
+/*     $NetBSD: parse.c,v 1.42 2021/10/26 19:36:30 rillig Exp $        */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -134,7 +134,7 @@
        }
        /* FALLTHROUGH */
     case psym_do:
-    case psym_for_exprs:               /* 'for' (...) */
+    case psym_for_exprs:       /* 'for' (...) */
        ps.s_sym[++ps.tos] = psym;
        ps.s_ind_level[ps.tos] = ps.ind_level = ps.ind_level_follow;
        ++ps.ind_level_follow;  /* subsequent statements should be indented 1 */
@@ -284,8 +284,8 @@
        ps.s_sym[--ps.tos] = psym_if_expr_stmt;
        int i = ps.tos - 1;
        while (ps.s_sym[i] != psym_stmt &&
-              ps.s_sym[i] != psym_stmt_list &&
-              ps.s_sym[i] != psym_lbrace)
+               ps.s_sym[i] != psym_stmt_list &&
+               ps.s_sym[i] != psym_lbrace)
            --i;
        ps.ind_level_follow = ps.s_ind_level[i];
        /*



Home | Main Index | Thread Index | Old Index