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: manually indent comments



details:   https://anonhg.NetBSD.org/src/rev/460da241cf37
branches:  trunk
changeset: 960157:460da241cf37
user:      rillig <rillig%NetBSD.org@localhost>
date:      Tue Mar 09 16:48:28 2021 +0000

description:
indent: manually indent comments

It's strange that indent's own code is not formatted by indent itself,
which would be a good demonstration of its capabilities.

In its current state, I don't trust indent to get even the tokenization
correct, therefore the only safe way is to format the code manually.

diffstat:

 usr.bin/indent/args.c       |   8 ++++----
 usr.bin/indent/indent.c     |  20 ++++++++++----------
 usr.bin/indent/lexi.c       |  10 +++++-----
 usr.bin/indent/parse.c      |  32 +++++++++++++-------------------
 usr.bin/indent/pr_comment.c |   8 ++++----
 5 files changed, 36 insertions(+), 42 deletions(-)

diffs (270 lines):

diff -r 3cfae5758455 -r 460da241cf37 usr.bin/indent/args.c
--- a/usr.bin/indent/args.c     Tue Mar 09 16:44:27 2021 +0000
+++ b/usr.bin/indent/args.c     Tue Mar 09 16:48:28 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: args.c,v 1.17 2021/03/07 20:52:11 rillig Exp $ */
+/*     $NetBSD: args.c,v 1.18 2021/03/09 16:48:28 rillig Exp $ */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -46,7 +46,7 @@
 #include <sys/cdefs.h>
 #ifndef lint
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: args.c,v 1.17 2021/03/07 20:52:11 rillig Exp $");
+__RCSID("$NetBSD: args.c,v 1.18 2021/03/09 16:48:28 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/args.c 336318 2018-07-15 21:04:21Z pstef $");
 #endif
@@ -85,8 +85,8 @@
 
 static void scan_profile(FILE *);
 
-#define        KEY_FILE                5       /* only used for args */
-#define VERSION                        6       /* only used for args */
+#define        KEY_FILE        5       /* only used for args */
+#define VERSION                6       /* only used for args */
 
 const char *option_source = "?";
 
diff -r 3cfae5758455 -r 460da241cf37 usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c   Tue Mar 09 16:44:27 2021 +0000
+++ b/usr.bin/indent/indent.c   Tue Mar 09 16:48:28 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: indent.c,v 1.35 2021/03/08 20:20:11 rillig Exp $       */
+/*     $NetBSD: indent.c,v 1.36 2021/03/09 16:48:28 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.35 2021/03/08 20:20:11 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.36 2021/03/09 16:48:28 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -435,7 +435,7 @@
                comment_buffered = true;
                *sc_end++ = '/';        /* copy in start of comment */
                *sc_end++ = '*';
-               for (;;) {      /* loop until we get to the end of the comment */
+               for (;;) {      /* loop until the end of the comment */
                    *sc_end = *buf_ptr++;
                    if (buf_ptr >= buf_end)
                        fill_buffer();
@@ -525,7 +525,7 @@
                    buf_ptr = save_com; /* fix so that subsequent calls to
                                         * lexi will take tokens out of
                                         * save_com */
-                   *sc_end++ = ' ';/* add trailing blank, just in case */
+                   *sc_end++ = ' ';    /* add trailing blank, just in case */
                    buf_end = sc_end;
                    sc_end = NULL;
                    break;
@@ -639,7 +639,7 @@
                                 * final increment for the null character. */
        switch (type_code) {    /* now, decide what to do with the token */
 
-       case form_feed: /* found a form feed in line */
+       case form_feed:         /* found a form feed in line */
            ps.use_ff = true;   /* a form feed is treated much like a newline */
            dump_line();
            ps.want_blank = false;
@@ -716,7 +716,7 @@
            if (sp_sw && (ps.p_l_follow == 0)) {        /* check for end of if
                                                         * (...), or some such */
                sp_sw = false;
-               force_nl = true;/* must force newline after if */
+               force_nl = true;        /* must force newline after if */
                ps.last_u_d = true;     /* inform lexi that a following
                                         * operator is unary */
                ps.in_stmt = false;     /* dont use stmt continuation
@@ -757,7 +757,7 @@
            ps.want_blank = false;
            break;
 
-       case binary_op: /* any binary operation */
+       case binary_op:         /* any binary operation */
            {
                int len = e_token - s_token;
 
@@ -830,8 +830,8 @@
 
        case semicolon: /* got a ';' */
            if (ps.dec_nest == 0)
-               ps.in_or_st = false;/* we are not in an initialization or
-                                    * structure declaration */
+               ps.in_or_st = false;    /* we are not in an initialization or
+                                        * structure declaration */
            scase = false;      /* these will only need resetting in an error */
            squest = 0;
            if (ps.last_token == rparen)
@@ -1004,7 +1004,7 @@
             */
            goto copy_id;       /* copy the token into line */
 
-       case sp_nparen: /* got else, do */
+       case sp_nparen:         /* got else, do */
            ps.in_stmt = false;
            if (*token == 'e') {
                if (e_code != s_code && (!opt.cuddle_else || e_code[-1] != '}')) {
diff -r 3cfae5758455 -r 460da241cf37 usr.bin/indent/lexi.c
--- a/usr.bin/indent/lexi.c     Tue Mar 09 16:44:27 2021 +0000
+++ b/usr.bin/indent/lexi.c     Tue Mar 09 16:48:28 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lexi.c,v 1.27 2021/03/08 21:13:33 rillig Exp $ */
+/*     $NetBSD: lexi.c,v 1.28 2021/03/09 16:48:28 rillig Exp $ */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -46,7 +46,7 @@
 #include <sys/cdefs.h>
 #ifndef lint
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: lexi.c,v 1.27 2021/03/08 21:13:33 rillig Exp $");
+__RCSID("$NetBSD: lexi.c,v 1.28 2021/03/09 16:48:28 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/lexi.c 337862 2018-08-15 18:19:45Z pstef $");
 #endif
@@ -438,8 +438,8 @@
 
     /* Scan a non-alphanumeric token */
 
-    check_size_token(3);               /* things like "<<=" */
-    *e_token++ = *buf_ptr;             /* if it is only a one-character token, it is
+    check_size_token(3);       /* things like "<<=" */
+    *e_token++ = *buf_ptr;     /* if it is only a one-character token, it is
                                 * moved here */
     *e_token = '\0';
     if (++buf_ptr >= buf_end)
@@ -582,7 +582,7 @@
     case '=':
        if (state->in_or_st)
            state->block_init = 1;
-       if (*buf_ptr == '=') {/* == */
+       if (*buf_ptr == '=') {  /* == */
            *e_token++ = '=';   /* Flip =+ to += */
            buf_ptr++;
            *e_token = 0;
diff -r 3cfae5758455 -r 460da241cf37 usr.bin/indent/parse.c
--- a/usr.bin/indent/parse.c    Tue Mar 09 16:44:27 2021 +0000
+++ b/usr.bin/indent/parse.c    Tue Mar 09 16:48:28 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: parse.c,v 1.14 2021/03/07 11:32:05 rillig Exp $        */
+/*     $NetBSD: parse.c,v 1.15 2021/03/09 16:48:28 rillig Exp $        */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -60,7 +60,7 @@
 static void reduce(void);
 
 void
-parse(token_type tk) /* tk: the code for the construct scanned */
+parse(token_type tk)           /* tk: the code for the construct scanned */
 {
     int         i;
 
@@ -111,7 +111,7 @@
                ps.i_l_follow = ps.il[ps.tos--];
        /* the rest is the same as for dolit and forstmt */
        /* FALLTHROUGH */
-    case dolit:                /* 'do' */
+    case dolit:                        /* 'do' */
     case forstmt:              /* for (...) */
        ps.p_stack[++ps.tos] = tk;
        ps.il[ps.tos] = ps.ind_level = ps.i_l_follow;
@@ -269,7 +269,7 @@
  *
  */
 /*----------------------------------------------*\
-|   REDUCTION PHASE                                |
+|   REDUCTION PHASE                             |
 \*----------------------------------------------*/
 static void
 reduce(void)
@@ -284,19 +284,17 @@
        case stmt:
            switch (ps.p_stack[ps.tos - 1]) {
 
-           case stmt:
-           case stmtl:
-               /* stmtl stmt or stmt stmt */
+           case stmt:          /* stmt stmt */
+           case stmtl:         /* stmtl stmt */
                ps.p_stack[--ps.tos] = stmtl;
                break;
 
-           case dolit: /* <do> <stmt> */
+           case dolit:         /* <do> <stmt> */
                ps.p_stack[--ps.tos] = dohead;
                ps.i_l_follow = ps.il[ps.tos];
                break;
 
-           case ifstmt:
-               /* <if> <stmt> */
+           case ifstmt:        /* <if> <stmt> */
                ps.p_stack[--ps.tos] = ifhead;
                for (i = ps.tos - 1;
                        (
@@ -315,17 +313,13 @@
                 */
                break;
 
-           case swstmt:
-               /* <switch> <stmt> */
+           case swstmt:        /* <switch> <stmt> */
                case_ind = ps.cstk[ps.tos - 1];
                /* FALLTHROUGH */
            case decl:          /* finish of a declaration */
-           case elsehead:
-               /* <<if> <stmt> else> <stmt> */
-           case forstmt:
-               /* <for> <stmt> */
-           case whilestmt:
-               /* <while> <stmt> */
+           case elsehead:      /* <if> <stmt> else> <stmt> */
+           case forstmt:       /* <for> <stmt> */
+           case whilestmt:     /* <while> <stmt> */
                ps.p_stack[--ps.tos] = stmt;
                ps.i_l_follow = ps.il[ps.tos];
                break;
@@ -336,7 +330,7 @@
            }                   /* end of section for <stmt> on top of stack */
            break;
 
-       case whilestmt: /* while (...) on top */
+       case whilestmt:         /* while (...) on top */
            if (ps.p_stack[ps.tos - 1] == dohead) {
                /* it is termination of a do while */
                ps.tos -= 2;
diff -r 3cfae5758455 -r 460da241cf37 usr.bin/indent/pr_comment.c
--- a/usr.bin/indent/pr_comment.c       Tue Mar 09 16:44:27 2021 +0000
+++ b/usr.bin/indent/pr_comment.c       Tue Mar 09 16:48:28 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pr_comment.c,v 1.14 2021/03/08 20:15:42 rillig Exp $   */
+/*     $NetBSD: pr_comment.c,v 1.15 2021/03/09 16:48:28 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.14 2021/03/08 20:15:42 rillig Exp $");
+__RCSID("$NetBSD: pr_comment.c,v 1.15 2021/03/09 16:48:28 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/pr_comment.c 334927 2018-06-10 16:44:18Z pstef $");
 #endif
@@ -128,8 +128,8 @@
     ps.just_saw_decl = 0;
     last_bl = NULL;            /* no blanks found so far */
     ps.box_com = false;                /* at first, assume that we are not in
-                                        * a boxed comment or some other
-                                        * comment that should not be touched */
+                                * a boxed comment or some other
+                                * comment that should not be touched */
     ++ps.out_coms;             /* keep track of number of comments */
 
     /* Figure where to align and how to treat the comment */



Home | Main Index | Thread Index | Old Index