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: switch to standard code style



details:   https://anonhg.NetBSD.org/src/rev/51e1c3e0eb72
branches:  trunk
changeset: 375873:51e1c3e0eb72
user:      rillig <rillig%NetBSD.org@localhost>
date:      Thu May 18 04:23:03 2023 +0000

description:
indent: switch to standard code style

Taken from share/misc/indent.pro.

Indent does not wrap code to fit into the line width, it only does so
for comments.  The 'INDENT OFF' sections and too long lines will be
addressed in a follow-up commit.

No functional change.

diffstat:

 usr.bin/indent/.indent.pro  |    29 +-
 usr.bin/indent/args.c       |   370 +++++-----
 usr.bin/indent/debug.c      |   338 +++++-----
 usr.bin/indent/indent.c     |  1449 +++++++++++++++++++++---------------------
 usr.bin/indent/indent.h     |   391 +++++-----
 usr.bin/indent/io.c         |   349 +++++-----
 usr.bin/indent/lexi.c       |   838 ++++++++++++------------
 usr.bin/indent/parse.c      |   332 ++++----
 usr.bin/indent/pr_comment.c |   430 ++++++------
 9 files changed, 2276 insertions(+), 2250 deletions(-)

diffs (truncated from 5700 to 300 lines):

diff -r 948f73026336 -r 51e1c3e0eb72 usr.bin/indent/.indent.pro
--- a/usr.bin/indent/.indent.pro        Thu May 18 03:38:34 2023 +0000
+++ b/usr.bin/indent/.indent.pro        Thu May 18 04:23:03 2023 +0000
@@ -1,9 +1,24 @@
-/* $NetBSD: .indent.pro,v 1.6 2023/05/16 12:46:43 rillig Exp $ */
+/* $NetBSD: .indent.pro,v 1.7 2023/05/18 04:23:03 rillig Exp $ */
 
--l78           /* Keep 2 columns distance from the 80-column margin. */
--di0           /* Do not indent variable names in global declarations. */
--eei           /* Indent expressions in 'if' and 'while' once more. */
--i4            /* Indent by 4 spaces, for traditional reasons. */
--ldi0          /* Do not indent variable names in local declarations. */
--nlp           /* Do not indent function arguments. */
+-bap           /* Force a blank line after function body. */
+-br            /* Place '{' to the right side. */
+-ce            /* Place '} else' on the same line. */
+-ci4           /* Indent statement continuations with 4 spaces. */
+-cli0          /* Don't indent 'case' relative to the 'switch'. */
+-d0            /* Indent comments in the same column as the code. */
+-di0           /* Do not indent variable declarations. */
+-i8            /* Use a single tab (8 columns) per indentation level. */
+-ip            /* Indent parameter declarations. */
+-l79           /* Leave a single empty column on 80-column displays. */
+-nbc           /* Don't force each declarator on a separate line. */
+-ncdb          /* Allow single-line block comments. */
+-ndj           /* Indent declarations in the same column as the code. */
+-ei            /* Place 'else if' on the same line. */
+-nfc1          /* Don't format comments in line 1, to preserve CVS IDs. */
+-nlp           /* Indent statement continuations by a fixed amount. */
+-npcs          /* Don't place a space between function name and '('. */
+-psl           /* Place function names in column 1. */
+-sc            /* Prefix multi-line block comments with '*'. */
+-sob           /* Swallow optional blank lines. */
+
 -ta            /* For proper formatting of type casts. */
diff -r 948f73026336 -r 51e1c3e0eb72 usr.bin/indent/args.c
--- a/usr.bin/indent/args.c     Thu May 18 03:38:34 2023 +0000
+++ b/usr.bin/indent/args.c     Thu May 18 04:23:03 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: args.c,v 1.77 2023/05/14 12:12:02 rillig Exp $ */
+/*     $NetBSD: args.c,v 1.78 2023/05/18 04:23:03 rillig Exp $ */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: args.c,v 1.77 2023/05/14 12:12:02 rillig Exp $");
+__RCSID("$NetBSD: args.c,v 1.78 2023/05/18 04:23:03 rillig Exp $");
 
 /* Read options from profile files and from the command line. */
 
@@ -65,242 +65,242 @@
 
 /* See set_special_option for special options. */
 static const struct pro {
-    const char p_name[5];      /* e.g. "bl", "cli" */
-    bool p_is_bool;
-    bool p_may_negate;
-    bool p_bool_value;         /* only relevant if !p_may_negate */
-    short i_min;
-    short i_max;
-    void *p_var;               /* the associated variable */
+       const char p_name[5];   /* e.g. "bl", "cli" */
+       bool p_is_bool;
+       bool p_may_negate;
+       bool p_bool_value;      /* only relevant if !p_may_negate */
+       short i_min;
+       short i_max;
+       void *p_var;            /* the associated variable */
 } pro[] = {
-    bool_options("bacc", blanklines_around_conditional_compilation),
-    bool_options("bad", blank_line_after_decl),
-    bool_options("badp", blank_line_after_decl_at_top),
-    bool_options("bap", blanklines_after_procs),
-    bool_options("bbb", blanklines_before_block_comments),
-    bool_options("bc", break_after_comma),
-    bool_option("bl", false, brace_same_line),
-    bool_option("br", true, brace_same_line),
-    bool_options("bs", blank_after_sizeof),
-    int_option("c", comment_column, 1, 999),
-    int_option("cd", decl_comment_column, 1, 999),
-    bool_options("cdb", comment_delimiter_on_blankline),
-    bool_options("ce", cuddle_else),
-    int_option("ci", continuation_indent, 0, 999),
-    /* "cli" is special */
-    bool_options("cs", space_after_cast),
-    int_option("d", unindent_displace, -999, 999),
-    int_option("di", decl_indent, 0, 999),
-    bool_options("dj", ljust_decl),
-    bool_options("eei", extra_expr_indent),
-    bool_options("ei", else_if),
-    bool_options("fbs", function_brace_split),
-    bool_options("fc1", format_col1_comments),
-    bool_options("fcb", format_block_comments),
-    int_option("i", indent_size, 1, 80),
-    bool_options("ip", indent_parameters),
-    int_option("l", max_line_length, 1, 999),
-    int_option("lc", block_comment_max_line_length, 1, 999),
-    int_option("ldi", local_decl_indent, 0, 999),
-    bool_options("lp", lineup_to_parens),
-    bool_options("lpl", lineup_to_parens_always),
-    /* "npro" is special */
-    /* "P" is special */
-    bool_options("pcs", proc_calls_space),
-    bool_options("psl", procnames_start_line),
-    bool_options("sc", star_comment_cont),
-    bool_options("sob", swallow_optional_blanklines),
-    /* "st" is special */
-    bool_option("ta", true, auto_typedefs),
-    /* "T" is special */
-    int_option("ts", tabsize, 1, 80),
-    /* "U" is special */
-    bool_options("ut", use_tabs),
-    bool_options("v", verbose),
-    /* "-version" is special */
+       bool_options("bacc", blanklines_around_conditional_compilation),
+       bool_options("bad", blank_line_after_decl),
+       bool_options("badp", blank_line_after_decl_at_top),
+       bool_options("bap", blanklines_after_procs),
+       bool_options("bbb", blanklines_before_block_comments),
+       bool_options("bc", break_after_comma),
+       bool_option("bl", false, brace_same_line),
+       bool_option("br", true, brace_same_line),
+       bool_options("bs", blank_after_sizeof),
+       int_option("c", comment_column, 1, 999),
+       int_option("cd", decl_comment_column, 1, 999),
+       bool_options("cdb", comment_delimiter_on_blankline),
+       bool_options("ce", cuddle_else),
+       int_option("ci", continuation_indent, 0, 999),
+       /* "cli" is special */
+       bool_options("cs", space_after_cast),
+       int_option("d", unindent_displace, -999, 999),
+       int_option("di", decl_indent, 0, 999),
+       bool_options("dj", ljust_decl),
+       bool_options("eei", extra_expr_indent),
+       bool_options("ei", else_if),
+       bool_options("fbs", function_brace_split),
+       bool_options("fc1", format_col1_comments),
+       bool_options("fcb", format_block_comments),
+       int_option("i", indent_size, 1, 80),
+       bool_options("ip", indent_parameters),
+       int_option("l", max_line_length, 1, 999),
+       int_option("lc", block_comment_max_line_length, 1, 999),
+       int_option("ldi", local_decl_indent, 0, 999),
+       bool_options("lp", lineup_to_parens),
+       bool_options("lpl", lineup_to_parens_always),
+       /* "npro" is special */
+       /* "P" is special */
+       bool_options("pcs", proc_calls_space),
+       bool_options("psl", procnames_start_line),
+       bool_options("sc", star_comment_cont),
+       bool_options("sob", swallow_optional_blanklines),
+       /* "st" is special */
+       bool_option("ta", true, auto_typedefs),
+       /* "T" is special */
+       int_option("ts", tabsize, 1, 80),
+       /* "U" is special */
+       bool_options("ut", use_tabs),
+       bool_options("v", verbose),
+       /* "-version" is special */
 };
 
 
 static void
 add_typedefs_from_file(const char *fname)
 {
-    FILE *file;
-    char line[BUFSIZ];
+       FILE *file;
+       char line[BUFSIZ];
 
-    if ((file = fopen(fname, "r")) == NULL) {
-       fprintf(stderr, "indent: cannot open file %s\n", fname);
-       exit(1);
-    }
-    while ((fgets(line, sizeof(line), file)) != NULL) {
-       /* Only keep the first word of the line. */
-       line[strcspn(line, " \t\n\r")] = '\0';
-       register_typename(line);
-    }
-    (void)fclose(file);
+       if ((file = fopen(fname, "r")) == NULL) {
+               fprintf(stderr, "indent: cannot open file %s\n", fname);
+               exit(1);
+       }
+       while ((fgets(line, sizeof(line), file)) != NULL) {
+               /* Only keep the first word of the line. */
+               line[strcspn(line, " \t\n\r")] = '\0';
+               register_typename(line);
+       }
+       (void)fclose(file);
 }
 
 static bool
 set_special_option(const char *arg, const char *option_source)
 {
-    const char *arg_end;
+       const char *arg_end;
 
-    if (strcmp(arg, "-version") == 0) {
-       printf("NetBSD indent 2.1\n");
-       exit(0);
-    }
+       if (strcmp(arg, "-version") == 0) {
+               printf("NetBSD indent 2.1\n");
+               exit(0);
+       }
 
-    if (arg[0] == 'P' || strcmp(arg, "npro") == 0)
-       return true;            /* see main_load_profiles */
+       if (arg[0] == 'P' || strcmp(arg, "npro") == 0)
+               return true;    /* see main_load_profiles */
 
-    if (strncmp(arg, "cli", 3) == 0) {
-       arg_end = arg + 3;
-       if (arg_end[0] == '\0')
-           goto need_arg;
-       char *end;
-       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);
-       return true;
-    }
+       if (strncmp(arg, "cli", 3) == 0) {
+               arg_end = arg + 3;
+               if (arg_end[0] == '\0')
+                       goto need_arg;
+               char *end;
+               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);
+               return true;
+       }
 
-    if (strcmp(arg, "st") == 0) {
-       if (input == NULL)
-           input = stdin;
-       if (output == NULL)
-           output = stdout;
-       return true;
-    }
+       if (strcmp(arg, "st") == 0) {
+               if (input == NULL)
+                       input = stdin;
+               if (output == NULL)
+                       output = stdout;
+               return true;
+       }
 
-    if (arg[0] == 'T') {
-       arg_end = arg + 1;
-       if (arg_end[0] == '\0')
-           goto need_arg;
-       register_typename(arg_end);
-       return true;
-    }
+       if (arg[0] == 'T') {
+               arg_end = arg + 1;
+               if (arg_end[0] == '\0')
+                       goto need_arg;
+               register_typename(arg_end);
+               return true;
+       }
 
-    if (arg[0] == 'U') {
-       arg_end = arg + 1;
-       if (arg_end[0] == '\0')
-           goto need_arg;
-       add_typedefs_from_file(arg_end);
-       return true;
-    }
+       if (arg[0] == 'U') {
+               arg_end = arg + 1;
+               if (arg_end[0] == '\0')
+                       goto need_arg;
+               add_typedefs_from_file(arg_end);
+               return true;
+       }
 
-    return false;
+       return false;
 
 need_arg:
-    errx(1, "%s: option \"-%.*s\" requires an argument",
-       option_source, (int)(arg_end - arg), arg);
-    /* NOTREACHED */
+       errx(1, "%s: option \"-%.*s\" requires an argument",
+           option_source, (int)(arg_end - arg), arg);
+       /* NOTREACHED */
 }
 
 static const char *
 skip_over(const char *s, bool may_negate, const char *prefix)
 {
-    if (may_negate && s[0] == 'n')
-       s++;



Home | Main Index | Thread Index | Old Index