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: let indent format its own code -- in ...
details: https://anonhg.NetBSD.org/src/rev/ef1023517163
branches: trunk
changeset: 1023811:ef1023517163
user: rillig <rillig%NetBSD.org@localhost>
date: Sun Sep 26 19:37:11 2021 +0000
description:
indent: let indent format its own code -- in supervised mode
After running indent on the code, I manually selected each change that
now looks better than before. The remaining changes are left for later.
All in all, indent did a pretty good job, except for syntactic additions
from after 1990, but that was to be expected. Examples for such
additions are GCC's __attribute__ and C99 designated initializers.
Indent has only few knobs to tune the indentation. The knob for the
continuation indentation applies to function declarations as well as to
expressions. The knob for indentation of local variable declarations
applies to struct members as well, even if these are members of a
top-level struct.
Several code comments crossed the right margin in column 78. Several
other code comments were correctly broken though. The cause for this
difference was not obvious.
No functional change.
diffstat:
usr.bin/indent/args.c | 28 ++--
usr.bin/indent/indent.c | 284 +++++++++++++++++++++----------------------
usr.bin/indent/io.c | 54 ++++---
usr.bin/indent/lexi.c | 42 +++---
usr.bin/indent/parse.c | 45 +++---
usr.bin/indent/pr_comment.c | 49 +++---
6 files changed, 254 insertions(+), 248 deletions(-)
diffs (truncated from 1212 to 300 lines):
diff -r e843c6f17bba -r ef1023517163 usr.bin/indent/args.c
--- a/usr.bin/indent/args.c Sun Sep 26 19:02:35 2021 +0000
+++ b/usr.bin/indent/args.c Sun Sep 26 19:37:11 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: args.c,v 1.32 2021/09/26 00:57:28 rillig Exp $ */
+/* $NetBSD: args.c,v 1.33 2021/09/26 19:37:11 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.32 2021/09/26 00:57:28 rillig Exp $");
+__RCSID("$NetBSD: args.c,v 1.33 2021/09/26 19:37:11 rillig Exp $");
#elif defined(__FreeBSD__)
__FBSDID("$FreeBSD: head/usr.bin/indent/args.c 336318 2018-07-15 21:04:21Z pstef $");
#endif
@@ -87,11 +87,11 @@
* See also set_special_option.
*/
static const struct pro {
- const char p_name[6]; /* name, e.g. "bl", "cli" */
- bool p_is_bool;
- bool p_bool_value;
- void *p_obj; /* the associated variable (bool, int) */
-} pro[] = {
+ const char p_name[6]; /* name, e.g. "bl", "cli" */
+ bool p_is_bool;
+ bool p_bool_value;
+ void *p_obj; /* the associated variable (bool, int) */
+} pro[] = {
bool_option("bacc", true, opt.blanklines_around_conditional_compilation),
bool_option("badp", true, opt.blanklines_after_declarations_at_proctop),
bool_option("bad", true, opt.blanklines_after_declarations),
@@ -174,11 +174,11 @@
snprintf(fname, sizeof(fname), "%s", profile_name + 2);
if ((f = fopen(option_source = fname, "r")) != NULL) {
scan_profile(f);
- (void) fclose(f);
+ (void)fclose(f);
}
if ((f = fopen(option_source = prof, "r")) != NULL) {
scan_profile(f);
- (void) fclose(f);
+ (void)fclose(f);
}
option_source = "Command line";
}
@@ -186,9 +186,9 @@
static void
scan_profile(FILE *f)
{
- int comment_index, i;
- char *p;
- char buf[BUFSIZ];
+ int comment_index, i;
+ char *p;
+ char buf[BUFSIZ];
for (;;) {
p = buf;
@@ -235,7 +235,7 @@
if (strncmp(arg, "-version", 8) == 0) {
printf("FreeBSD indent %s\n", INDENT_VERSION);
exit(0);
- /*NOTREACHED*/
+ /* NOTREACHED */
}
if (arg[0] == 'P' || strncmp(arg, "npro", 4) == 0)
@@ -285,7 +285,7 @@
set_option(const char *arg)
{
const struct pro *p;
- const char *param_start;
+ const char *param_start;
arg++; /* ignore leading "-" */
if (set_special_option(arg))
diff -r e843c6f17bba -r ef1023517163 usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c Sun Sep 26 19:02:35 2021 +0000
+++ b/usr.bin/indent/indent.c Sun Sep 26 19:37:11 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: indent.c,v 1.85 2021/09/26 18:52:16 rillig Exp $ */
+/* $NetBSD: indent.c,v 1.86 2021/09/26 19:37:11 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.85 2021/09/26 18:52:16 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.86 2021/09/26 19:37:11 rillig Exp $");
#elif defined(__FreeBSD__)
__FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
#endif
@@ -65,25 +65,25 @@
#include "indent.h"
struct options opt = {
- .leave_comma = true,
- .btype_2 = true,
- .comment_delimiter_on_blankline = true,
- .cuddle_else = true,
- .comment_column = 33,
- .decl_indent = 16,
- .else_if = true,
- .function_brace_split = true,
- .format_col1_comments = true,
- .format_block_comments = true,
- .indent_parameters = true,
- .indent_size = 8,
- .local_decl_indent = -1,
- .lineup_to_parens = true,
- .procnames_start_line = true,
- .star_comment_cont = true,
- .tabsize = 8,
- .max_line_length = 78,
- .use_tabs = true,
+ .leave_comma = true,
+ .btype_2 = true,
+ .comment_delimiter_on_blankline = true,
+ .cuddle_else = true,
+ .comment_column = 33,
+ .decl_indent = 16,
+ .else_if = true,
+ .function_brace_split = true,
+ .format_col1_comments = true,
+ .format_block_comments = true,
+ .indent_parameters = true,
+ .indent_size = 8,
+ .local_decl_indent = -1,
+ .lineup_to_parens = true,
+ .procnames_start_line = true,
+ .star_comment_cont = true,
+ .tabsize = 8,
+ .max_line_length = 78,
+ .use_tabs = true,
};
struct parser_state ps;
@@ -93,35 +93,35 @@
struct buffer com;
struct buffer token;
-char *in_buffer;
-char *in_buffer_limit;
-char *buf_ptr;
-char *buf_end;
+char *in_buffer;
+char *in_buffer_limit;
+char *buf_ptr;
+char *buf_end;
-char sc_buf[sc_size];
-char *save_com;
-char *sc_end;
+char sc_buf[sc_size];
+char *save_com;
+char *sc_end;
-char *bp_save;
-char *be_save;
+char *bp_save;
+char *be_save;
-bool found_err;
-int n_real_blanklines;
-bool prefix_blankline_requested;
-bool postfix_blankline_requested;
-bool break_comma;
-float case_ind;
-bool had_eof;
-int line_no;
-bool inhibit_formatting;
-int suppress_blanklines;
+bool found_err;
+int n_real_blanklines;
+bool prefix_blankline_requested;
+bool postfix_blankline_requested;
+bool break_comma;
+float case_ind;
+bool had_eof;
+int line_no;
+bool inhibit_formatting;
+int suppress_blanklines;
-int ifdef_level;
+int ifdef_level;
struct parser_state state_stack[5];
struct parser_state match_state[5];
-FILE *input;
-FILE *output;
+FILE *input;
+FILE *output;
static void bakcopy(void);
static void indent_declaration(int, bool);
@@ -132,7 +132,7 @@
* of output file */
const char *simple_backup_suffix = ".BAK"; /* Suffix to use for backup
* files */
-char bakfile[MAXPATHLEN] = "";
+char bakfile[MAXPATHLEN] = "";
static void
check_size_code(size_t desired_size)
@@ -168,7 +168,7 @@
static void
search_brace(token_type *inout_ttype, bool *inout_force_nl,
- bool *inout_comment_buffered, bool *inout_last_else)
+ bool *inout_comment_buffered, bool *inout_last_else)
{
while (ps.search_brace) {
switch (*inout_ttype) {
@@ -181,12 +181,12 @@
*sc_end++ = '\n';
/*
* We may have inherited a force_nl == true from the previous
- * token (like a semicolon). But once we know that a newline
- * has been scanned in this loop, force_nl should be false.
+ * token (like a semicolon). But once we know that a newline has
+ * been scanned in this loop, force_nl should be false.
*
- * However, the force_nl == true must be preserved if newline
- * is never scanned in this loop, so this assignment cannot be
- * done earlier.
+ * However, the force_nl == true must be preserved if newline is
+ * never scanned in this loop, so this assignment cannot be done
+ * earlier.
*/
*inout_force_nl = false;
break;
@@ -226,17 +226,17 @@
break;
case lbrace:
/*
- * Put KNF-style lbraces before the buffered up tokens and
- * jump out of this loop in order to avoid copying the token
- * again under the default case of the switch below.
+ * Put KNF-style lbraces before the buffered up tokens and jump
+ * out of this loop in order to avoid copying the token again
+ * under the default case of the switch below.
*/
if (sc_end != NULL && opt.btype_2) {
save_com[0] = '{';
/*
- * Originally the lbrace may have been alone on its own
- * line, but it will be moved into "the else's line", so
- * if there was a newline resulting from the "{" before,
- * it must be scanned now and ignored.
+ * Originally the lbrace may have been alone on its own line,
+ * but it will be moved into "the else's line", so if there
+ * was a newline resulting from the "{" before, it must be
+ * scanned now and ignored.
*/
while (isspace((unsigned char)*buf_ptr)) {
if (++buf_ptr >= buf_end)
@@ -303,28 +303,27 @@
}
} /* end of switch */
/*
- * We must make this check, just in case there was an unexpected
- * EOF.
+ * We must make this check, just in case there was an unexpected EOF.
*/
if (*inout_ttype != end_of_file) {
/*
* The only intended purpose of calling lexi() below is to
* categorize the next token in order to decide whether to
- * continue buffering forthcoming tokens. Once the buffering
- * is over, lexi() will be called again elsewhere on all of
- * the tokens - this time for normal processing.
+ * continue buffering forthcoming tokens. Once the buffering is
+ * over, lexi() will be called again elsewhere on all of the
+ * tokens - this time for normal processing.
*
* Calling it for this purpose is a bug, because lexi() also
- * changes the parser state and discards leading whitespace,
- * which is needed mostly for comment-related considerations.
+ * changes the parser state and discards leading whitespace, which
+ * is needed mostly for comment-related considerations.
*
- * Work around the former problem by giving lexi() a copy of
- * the current parser state and discard it if the call turned
- * out to be just a look ahead.
+ * Work around the former problem by giving lexi() a copy of the
+ * current parser state and discard it if the call turned out to
+ * be just a look ahead.
*
* Work around the latter problem by copying all whitespace
- * characters into the buffer so that the later lexi() call
- * will read them.
+ * characters into the buffer so that the later lexi() call will
+ * read them.
*/
Home |
Main Index |
Thread Index |
Old Index