Module Name: src Committed By: rillig Date: Sun Oct 24 19:14:33 UTC 2021
Modified Files: src/usr.bin/indent: args.c indent.c lexi.c parse.c pr_comment.c Log Message: indent: run indent on its own source code With manual corrections afterwards. Indent still does not get extra_expr_indent correctly, it also indents global variables after tagged declarations too deep. No functional change. To generate a diff of this commit: cvs rdiff -u -r1.58 -r1.59 src/usr.bin/indent/args.c cvs rdiff -u -r1.148 -r1.149 src/usr.bin/indent/indent.c cvs rdiff -u -r1.94 -r1.95 src/usr.bin/indent/lexi.c cvs rdiff -u -r1.36 -r1.37 src/usr.bin/indent/parse.c cvs rdiff -u -r1.82 -r1.83 src/usr.bin/indent/pr_comment.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.bin/indent/args.c diff -u src/usr.bin/indent/args.c:1.58 src/usr.bin/indent/args.c:1.59 --- src/usr.bin/indent/args.c:1.58 Sun Oct 24 11:19:25 2021 +++ src/usr.bin/indent/args.c Sun Oct 24 19:14:33 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: args.c,v 1.58 2021/10/24 11:19:25 rillig Exp $ */ +/* $NetBSD: args.c,v 1.59 2021/10/24 19:14:33 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -43,7 +43,7 @@ static char sccsid[] = "@(#)args.c 8.1 ( #include <sys/cdefs.h> #if defined(__NetBSD__) -__RCSID("$NetBSD: args.c,v 1.58 2021/10/24 11:19:25 rillig Exp $"); +__RCSID("$NetBSD: args.c,v 1.59 2021/10/24 19:14:33 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/args.c 336318 2018-07-15 21:04:21Z pstef $"); #endif @@ -162,7 +162,7 @@ load_profile(const char *fname, bool mus break; } else if (n >= array_length(buf) - 5) { diag(1, "buffer overflow in %s, starting with '%.10s'", - fname, buf); + fname, buf); exit(1); } else buf[n++] = (char)ch; @@ -308,7 +308,7 @@ found: if (!(errno == 0 && *end == '\0' && p->i_min <= num && num <= p->i_max)) errx(1, "%s: invalid argument \"%s\" for option \"-%s\"", - option_source, param_start, p->p_name); + option_source, param_start, p->p_name); *(int *)p->p_var = (int)num; } } Index: src/usr.bin/indent/indent.c diff -u src/usr.bin/indent/indent.c:1.148 src/usr.bin/indent/indent.c:1.149 --- src/usr.bin/indent/indent.c:1.148 Sun Oct 24 17:19:48 2021 +++ src/usr.bin/indent/indent.c Sun Oct 24 19:14:33 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: indent.c,v 1.148 2021/10/24 17:19:48 rillig Exp $ */ +/* $NetBSD: indent.c,v 1.149 2021/10/24 19:14:33 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -43,7 +43,7 @@ static char sccsid[] = "@(#)indent.c 5.1 #include <sys/cdefs.h> #if defined(__NetBSD__) -__RCSID("$NetBSD: indent.c,v 1.148 2021/10/24 17:19:48 rillig Exp $"); +__RCSID("$NetBSD: indent.c,v 1.149 2021/10/24 19:14:33 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $"); #endif @@ -309,19 +309,18 @@ search_brace_lookahead(token_type *ttype return; /* - * 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. + * 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. * - * 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. + * 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. * - * 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 lookahead. + * 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 + * lookahead. * * Work around the latter problem by copying all whitespace characters * into the buffer so that the later lexi() call will read them. @@ -367,7 +366,7 @@ search_brace(token_type *ttype, bool *fo if (!search_brace_other(*ttype, force_nl, *comment_buffered, *last_else)) return; - switch_buffer: + switch_buffer: switch_buffer(); } search_brace_lookahead(ttype); @@ -490,7 +489,7 @@ bakcopy(void) const char *last_slash = strrchr(in_name, '/'); snprintf(bakfile, sizeof(bakfile), "%s%s", - last_slash != NULL ? last_slash + 1 : in_name, backup_suffix); + last_slash != NULL ? last_slash + 1 : in_name, backup_suffix); /* copy in_name to backup file */ bak_fd = creat(bakfile, 0600); @@ -853,7 +852,7 @@ process_colon(int *seen_quest, bool *for return; } - if (ps.init_or_struct) { /* bit-field */ + if (ps.init_or_struct) { /* bit-field */ *code.e++ = ':'; ps.want_blank = false; return; @@ -1100,8 +1099,8 @@ process_decl(int *decl_ind, bool *tabs_t int len = (int)buf_len(&token) + 1; int ind = ps.ind_level == 0 || ps.decl_nest > 0 - ? opt.decl_indent /* global variable or local member */ - : opt.local_decl_indent; /* local variable */ + ? opt.decl_indent /* global variable or local member */ + : opt.local_decl_indent; /* local variable */ *decl_ind = ind > 0 ? ind : len; *tabs_to_var = opt.use_tabs && ind > 0; } @@ -1181,9 +1180,8 @@ process_comma(int decl_ind, bool tabs_to if (ps.block_init_level <= 0) ps.block_init = false; if (break_comma && (opt.break_after_comma || - indentation_after_range( - compute_code_indent(), code.s, code.e) - >= opt.max_line_length - opt.tabsize)) + indentation_after_range(compute_code_indent(), code.s, code.e) + >= opt.max_line_length - opt.tabsize)) *force_nl = true; } } Index: src/usr.bin/indent/lexi.c diff -u src/usr.bin/indent/lexi.c:1.94 src/usr.bin/indent/lexi.c:1.95 --- src/usr.bin/indent/lexi.c:1.94 Sun Oct 24 11:19:25 2021 +++ src/usr.bin/indent/lexi.c Sun Oct 24 19:14:33 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: lexi.c,v 1.94 2021/10/24 11:19:25 rillig Exp $ */ +/* $NetBSD: lexi.c,v 1.95 2021/10/24 19:14:33 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -43,7 +43,7 @@ static char sccsid[] = "@(#)lexi.c 8.1 ( #include <sys/cdefs.h> #if defined(__NetBSD__) -__RCSID("$NetBSD: lexi.c,v 1.94 2021/10/24 11:19:25 rillig Exp $"); +__RCSID("$NetBSD: lexi.c,v 1.95 2021/10/24 19:14:33 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/lexi.c 337862 2018-08-15 18:19:45Z pstef $"); #endif @@ -291,8 +291,8 @@ static void lex_word(void) { while (isalnum((unsigned char)*inp.s) || - *inp.s == '\\' || - *inp.s == '_' || *inp.s == '$') { + *inp.s == '\\' || + *inp.s == '_' || *inp.s == '$') { if (*inp.s == '\\') { if (inp.s[1] == '\n') { @@ -382,8 +382,8 @@ static token_type lexi_alnum(struct parser_state *state) { if (!(isalnum((unsigned char)*inp.s) || - *inp.s == '_' || *inp.s == '$' || - (inp.s[0] == '.' && isdigit((unsigned char)inp.s[1])))) + *inp.s == '_' || *inp.s == '$' || + (inp.s[0] == '.' && isdigit((unsigned char)inp.s[1])))) return end_of_file; /* just as a placeholder */ if (isdigit((unsigned char)*inp.s) || @@ -686,7 +686,7 @@ lexi(struct parser_state *state) unary_delim = true; } - if (inp.s >= inp.e) /* check for input buffer empty */ + if (inp.s >= inp.e) /* check for input buffer empty */ inbuf_read_line(); state->next_unary = unary_delim; Index: src/usr.bin/indent/parse.c diff -u src/usr.bin/indent/parse.c:1.36 src/usr.bin/indent/parse.c:1.37 --- src/usr.bin/indent/parse.c:1.36 Wed Oct 20 05:26:46 2021 +++ src/usr.bin/indent/parse.c Sun Oct 24 19:14:33 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: parse.c,v 1.36 2021/10/20 05:26:46 rillig Exp $ */ +/* $NetBSD: parse.c,v 1.37 2021/10/24 19:14:33 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -117,8 +117,8 @@ parse(token_type ttype) break_comma = false; /* don't break comma in an initializer list */ if (ps.s_ttype[ps.tos] == stmt || ps.s_ttype[ps.tos] == decl || ps.s_ttype[ps.tos] == stmt_list) - ++ps.ind_level_follow; /* it is a random, isolated stmt - * group or a declaration */ + ++ps.ind_level_follow; /* it is a random, isolated stmt group + * or a declaration */ else { if (code.s == code.e) { /* it is a group as part of a while, for, etc. */ Index: src/usr.bin/indent/pr_comment.c diff -u src/usr.bin/indent/pr_comment.c:1.82 src/usr.bin/indent/pr_comment.c:1.83 --- src/usr.bin/indent/pr_comment.c:1.82 Sun Oct 24 11:17:05 2021 +++ src/usr.bin/indent/pr_comment.c Sun Oct 24 19:14:33 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: pr_comment.c,v 1.82 2021/10/24 11:17:05 rillig Exp $ */ +/* $NetBSD: pr_comment.c,v 1.83 2021/10/24 19:14:33 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -43,7 +43,7 @@ static char sccsid[] = "@(#)pr_comment.c #include <sys/cdefs.h> #if defined(__NetBSD__) -__RCSID("$NetBSD: pr_comment.c,v 1.82 2021/10/24 11:17:05 rillig Exp $"); +__RCSID("$NetBSD: pr_comment.c,v 1.83 2021/10/24 19:14:33 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/pr_comment.c 334927 2018-06-10 16:44:18Z pstef $"); #endif @@ -181,8 +181,8 @@ process_comment(void) * much will have to be ignored by dump_line(). This is a box comment, * so nothing changes -- not even indentation. * - * The comment we're about to read usually comes from inp.buf, - * unless it has been copied into save_com. + * The comment we're about to read usually comes from inp.buf, unless + * it has been copied into save_com. */ const char *start;