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: use consistent indentation for 'else'



details:   https://anonhg.NetBSD.org/src/rev/9c64fe3cc4c3
branches:  trunk
changeset: 1019505:9c64fe3cc4c3
user:      rillig <rillig%NetBSD.org@localhost>
date:      Fri Mar 12 23:10:18 2021 +0000

description:
indent: use consistent indentation for 'else'

Half of the code used -ce, the other half the opposite -nce.

No functional change.

diffstat:

 usr.bin/indent/args.c       |   7 ++---
 usr.bin/indent/indent.c     |  52 +++++++++++++++-----------------------------
 usr.bin/indent/io.c         |  27 +++++++++-------------
 usr.bin/indent/lexi.c       |  21 +++++++----------
 usr.bin/indent/parse.c      |   8 ++----
 usr.bin/indent/pr_comment.c |  28 ++++++++---------------
 6 files changed, 54 insertions(+), 89 deletions(-)

diffs (truncated from 491 to 300 lines):

diff -r 9045f3ddbefe -r 9c64fe3cc4c3 usr.bin/indent/args.c
--- a/usr.bin/indent/args.c     Fri Mar 12 22:53:18 2021 +0000
+++ b/usr.bin/indent/args.c     Fri Mar 12 23:10:18 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: args.c,v 1.18 2021/03/09 16:48:28 rillig Exp $ */
+/*     $NetBSD: args.c,v 1.19 2021/03/12 23:10:18 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.18 2021/03/09 16:48:28 rillig Exp $");
+__RCSID("$NetBSD: args.c,v 1.19 2021/03/12 23:10:18 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/args.c 336318 2018-07-15 21:04:21Z pstef $");
 #endif
@@ -234,8 +234,7 @@
            if (opt.verbose)
                printf("profile: %s\n", buf);
            set_option(buf);
-       }
-       else if (i == EOF)
+       } else if (i == EOF)
            return;
     }
 }
diff -r 9045f3ddbefe -r 9c64fe3cc4c3 usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c   Fri Mar 12 22:53:18 2021 +0000
+++ b/usr.bin/indent/indent.c   Fri Mar 12 23:10:18 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: indent.c,v 1.44 2021/03/12 00:15:34 rillig Exp $       */
+/*     $NetBSD: indent.c,v 1.45 2021/03/12 23:10:18 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.44 2021/03/12 00:15:34 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.45 2021/03/12 23:10:18 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -507,8 +507,7 @@
                if (input == NULL)      /* check for open error */
                        err(1, "%s", in_name);
                continue;
-           }
-           else if (output == NULL) {  /* we have the output file */
+           } else if (output == NULL) {        /* we have the output file */
                out_name = argv[i];     /* remember name of output file */
                if (strcmp(in_name, out_name) == 0) {   /* attempt to overwrite
                                                         * the file */
@@ -520,8 +519,7 @@
                continue;
            }
            errx(1, "unknown parameter: %s", argv[i]);
-       }
-       else
+       } else
            set_option(argv[i]);
     }                          /* end of for */
     if (input == NULL)
@@ -636,8 +634,7 @@
                ps.want_blank = false;
                e_com = s_com;
            }
-       }
-       else if (type_code != comment)  /* preserve force_nl thru a comment */
+       } else if (type_code != comment) /* preserve force_nl thru a comment */
            force_nl = false;   /* cancel forced newline after newline, form
                                 * feed, etc */
 
@@ -681,8 +678,7 @@
                /* function pointer declarations */
                indent_declaration(dec_ind, tabs_to_var);
                ps.dumped_decl_indent = true;
-           }
-           else if (ps.want_blank &&
+           } else if (ps.want_blank &&
                    ((ps.last_token != ident && ps.last_token != funcname) ||
                    opt.proc_calls_space ||
                    (ps.keyword == rw_sizeof ? opt.Bill_Shannon :
@@ -756,8 +752,7 @@
                    /* find length of token */;
                indent_declaration(dec_ind - i, tabs_to_var);
                ps.dumped_decl_indent = true;
-           }
-           else if (ps.want_blank)
+           } else if (ps.want_blank)
                *e_code++ = ' ';
 
            {
@@ -906,8 +901,7 @@
                if (!opt.btype_2) {
                    dump_line();
                    ps.want_blank = false;
-               }
-               else if (ps.in_parameter_declaration && !ps.in_or_st) {
+               } else if (ps.in_parameter_declaration && !ps.in_or_st) {
                    ps.i_l_follow = 0;
                    if (opt.function_brace_split) { /* dump the line prior
                                 * to the brace ... */
@@ -942,8 +936,7 @@
                    ps.dec_nest--;
                }
                /* ?            dec_ind = 0; */
-           }
-           else {
+           } else {
                ps.decl_on_line = false;        /* we can't be in the middle of
                                                 * a declaration, so don't do
                                                 * special indentation of
@@ -1030,8 +1023,7 @@
                force_nl = true;/* also, following stuff must go onto new line */
                last_else = 1;
                parse(keyword_else);
-           }
-           else {
+           } else {
                if (e_code != s_code) { /* make sure this starts a line */
                    if (opt.verbose)
                        diag(0, "Line broken");
@@ -1092,21 +1084,18 @@
                    if (opt.procnames_start_line && s_code != e_code) {
                        *e_code = '\0';
                        dump_line();
-                   }
-                   else if (ps.want_blank) {
+                   } else if (ps.want_blank) {
                        *e_code++ = ' ';
                    }
                    ps.want_blank = false;
-               }
-               else if (!ps.block_init && !ps.dumped_decl_indent &&
+               } else if (!ps.block_init && !ps.dumped_decl_indent &&
                    ps.paren_level == 0) { /* if we are in a declaration, we
                                            * must indent identifier */
                    indent_declaration(dec_ind, tabs_to_var);
                    ps.dumped_decl_indent = true;
                    ps.want_blank = false;
                }
-           }
-           else if (sp_sw && ps.p_l_follow == 0) {
+           } else if (sp_sw && ps.p_l_follow == 0) {
                sp_sw = false;
                force_nl = true;
                ps.last_u_d = true;
@@ -1231,8 +1220,7 @@
                                                 * we must set up the buffer */
                        save_com = sc_buf;
                        sc_end = &save_com[0];
-                   }
-                   else {
+                   } else {
                        *sc_end++ = '\n';       /* add newline between
                                                 * comments */
                        *sc_end++ = ' ';
@@ -1263,19 +1251,16 @@
                if ((size_t)ifdef_level < nitems(state_stack)) {
                    match_state[ifdef_level].tos = -1;
                    state_stack[ifdef_level++] = ps;
-               }
-               else
+               } else
                    diag(1, "#if stack overflow");
-           }
-           else if (strncmp(s_lab, "#el", 3) == 0) { /* else, elif */
+           } else if (strncmp(s_lab, "#el", 3) == 0) { /* else, elif */
                if (ifdef_level <= 0)
                    diag(1, s_lab[3] == 'i' ? "Unmatched #elif" : "Unmatched #else");
                else {
                    match_state[ifdef_level - 1] = ps;
                    ps = state_stack[ifdef_level - 1];
                }
-           }
-           else if (strncmp(s_lab, "#endif", 6) == 0) {
+           } else if (strncmp(s_lab, "#endif", 6) == 0) {
                if (ifdef_level <= 0)
                    diag(1, "Unmatched #endif");
                else
@@ -1304,8 +1289,7 @@
            if (opt.blanklines_around_conditional_compilation) {
                postfix_blankline_requested++;
                n_real_blanklines = 0;
-           }
-           else {
+           } else {
                postfix_blankline_requested = 0;
                prefix_blankline_requested = 0;
            }
diff -r 9045f3ddbefe -r 9c64fe3cc4c3 usr.bin/indent/io.c
--- a/usr.bin/indent/io.c       Fri Mar 12 22:53:18 2021 +0000
+++ b/usr.bin/indent/io.c       Fri Mar 12 23:10:18 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: io.c,v 1.29 2021/03/12 19:14:18 rillig Exp $   */
+/*     $NetBSD: io.c,v 1.30 2021/03/12 23:10:18 rillig Exp $   */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -46,7 +46,7 @@
 #include <sys/cdefs.h>
 #ifndef lint
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: io.c,v 1.29 2021/03/12 19:14:18 rillig Exp $");
+__RCSID("$NetBSD: io.c,v 1.30 2021/03/12 23:10:18 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/io.c 334927 2018-06-10 16:44:18Z pstef $");
 #endif
@@ -104,6 +104,7 @@
        ps.ind_level = 0;
        ps.procname[0] = 0;
     }
+
     if (s_code == e_code && s_lab == e_lab && s_com == e_com) {
        if (suppress_blanklines > 0)
            suppress_blanklines--;
@@ -111,16 +112,14 @@
            ps.bl_line = true;
            n_real_blanklines++;
        }
-    }
-    else if (!inhibit_formatting) {
+    } else if (!inhibit_formatting) {
        suppress_blanklines = 0;
        ps.bl_line = false;
        if (prefix_blankline_requested && not_first_line) {
            if (opt.swallow_optional_blanklines) {
                if (n_real_blanklines == 1)
                    n_real_blanklines = 0;
-           }
-           else {
+           } else {
                if (n_real_blanklines == 0)
                    n_real_blanklines = 1;
            }
@@ -168,8 +167,7 @@
            } else
                output_range(s_lab, e_lab);
            cur_col = count_spaces(cur_col, s_lab);
-       }
-       else
+       } else
            cur_col = 1;        /* there is no label section */
 
        ps.pcase = false;
@@ -211,8 +209,7 @@
                else if (*com_st == '\t') {
                    target = opt.tabsize * (1 + (target - 1) / opt.tabsize) + 1;
                    com_st++;
-               }
-               else
+               } else
                    target = 1;
            if (cur_col > target) {     /* if comment can't fit on this line,
                                     * put it on next line */
@@ -235,8 +232,7 @@
        if (ps.just_saw_decl == 1 && opt.blanklines_after_declarations) {
            prefix_blankline_requested = 1;
            ps.just_saw_decl = 0;
-       }
-       else
+       } else
            prefix_blankline_requested = postfix_blankline_requested;
        postfix_blankline_requested = 0;
     }
@@ -270,7 +266,7 @@
 {
     int target_col = opt.ind_size * ps.ind_level + 1;
 
-    if (ps.paren_level)
+    if (ps.paren_level) {
        if (!opt.lineup_to_parens)
            target_col += opt.continuation_indent *
                (2 * opt.continuation_indent == opt.ind_size ? 1 : ps.paren_level);
@@ -285,11 +281,10 @@
                t -= w + 1;
                if (t > target_col)
                    target_col = t;
-           }
-           else
+           } else
                target_col = t;
        }
-    else if (ps.ind_stmt)
+    } else if (ps.ind_stmt)
        target_col += opt.continuation_indent;
     return target_col;
 }
diff -r 9045f3ddbefe -r 9c64fe3cc4c3 usr.bin/indent/lexi.c
--- a/usr.bin/indent/lexi.c     Fri Mar 12 22:53:18 2021 +0000
+++ b/usr.bin/indent/lexi.c     Fri Mar 12 23:10:18 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: lexi.c,v 1.37 2021/03/12 18:11:50 rillig Exp $ */
+/*     $NetBSD: lexi.c,v 1.38 2021/03/12 23:10:18 rillig Exp $ */
 
 /*-



Home | Main Index | Thread Index | Old Index