indent: run indent on its own source code
With manual corrections afterwards, to compensate for the remaining bugs in indent. Without the type definitions in .indent.pro, the opening braces of the functions kw_name and lexi_alnum would not be at the beginning of the line.
This commit is contained in:
parent
48417ce252
commit
65460602c1
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: .indent.pro,v 1.2 2021/10/05 22:09:05 rillig Exp $ */
|
||||
/* $NetBSD: .indent.pro,v 1.3 2021/10/26 19:36:30 rillig Exp $ */
|
||||
|
||||
-di0 /* Do not indent variable names in global declarations. */
|
||||
/* XXX: -eei does not work; the expressions are indented only a single level. */
|
||||
|
@ -9,4 +9,6 @@
|
|||
-nlp /* Do not indent function arguments. */
|
||||
-ta /* Identifiers ending in '_t' are considered type names. */
|
||||
-TFILE /* Additional types, for proper formatting of '*'. */
|
||||
-Ttoken_type
|
||||
-Tlexer_symbol
|
||||
-Tparser_symbol
|
||||
-Tkeyword_kind
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: args.c,v 1.59 2021/10/24 19:14:33 rillig Exp $ */
|
||||
/* $NetBSD: args.c,v 1.60 2021/10/26 19:36:30 rillig Exp $ */
|
||||
|
||||
/*-
|
||||
* SPDX-License-Identifier: BSD-4-Clause
|
||||
|
@ -43,7 +43,7 @@ static char sccsid[] = "@(#)args.c 8.1 (Berkeley) 6/6/93";
|
|||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(__NetBSD__)
|
||||
__RCSID("$NetBSD: args.c,v 1.59 2021/10/24 19:14:33 rillig Exp $");
|
||||
__RCSID("$NetBSD: args.c,v 1.60 2021/10/26 19:36:30 rillig Exp $");
|
||||
#elif defined(__FreeBSD__)
|
||||
__FBSDID("$FreeBSD: head/usr.bin/indent/args.c 336318 2018-07-15 21:04:21Z pstef $");
|
||||
#endif
|
||||
|
@ -89,7 +89,7 @@ static const struct pro {
|
|||
short i_min;
|
||||
short i_max;
|
||||
void *p_var; /* the associated variable */
|
||||
} pro[] = {
|
||||
} pro[] = {
|
||||
bool_options("bacc", blanklines_around_conditional_compilation),
|
||||
bool_options("bad", blanklines_after_decl),
|
||||
bool_options("badp", blanklines_after_decl_at_top),
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: indent.c,v 1.159 2021/10/25 21:33:24 rillig Exp $ */
|
||||
/* $NetBSD: indent.c,v 1.160 2021/10/26 19:36:30 rillig Exp $ */
|
||||
|
||||
/*-
|
||||
* SPDX-License-Identifier: BSD-4-Clause
|
||||
|
@ -43,7 +43,7 @@ static char sccsid[] = "@(#)indent.c 5.17 (Berkeley) 6/7/93";
|
|||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(__NetBSD__)
|
||||
__RCSID("$NetBSD: indent.c,v 1.159 2021/10/25 21:33:24 rillig Exp $");
|
||||
__RCSID("$NetBSD: indent.c,v 1.160 2021/10/26 19:36:30 rillig Exp $");
|
||||
#elif defined(__FreeBSD__)
|
||||
__FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
|
||||
#endif
|
||||
|
@ -245,10 +245,10 @@ search_stmt_other(lexer_symbol lsym, bool *force_nl,
|
|||
bool remove_newlines;
|
||||
|
||||
remove_newlines =
|
||||
/* "} else" */
|
||||
(lsym == lsym_else && code.e != code.s && code.e[-1] == '}')
|
||||
/* "else if" */
|
||||
|| (lsym == lsym_if && last_else && opt.else_if);
|
||||
/* "} else" */
|
||||
(lsym == lsym_else && code.e != code.s && code.e[-1] == '}')
|
||||
/* "else if" */
|
||||
|| (lsym == lsym_if && last_else && opt.else_if);
|
||||
if (remove_newlines)
|
||||
*force_nl = false;
|
||||
|
||||
|
@ -1333,8 +1333,8 @@ main_loop(void)
|
|||
bool tabs_to_var = false; /* true if using tabs to indent to var name */
|
||||
bool spaced_expr = false; /* whether we are in the expression of
|
||||
* if(...), while(...), etc. */
|
||||
stmt_head hd = hd_0; /* the type of statement for 'if (...)',
|
||||
* 'for (...)', etc */
|
||||
stmt_head hd = hd_0; /* the type of statement for 'if (...)', 'for
|
||||
* (...)', etc */
|
||||
int quest_level = 0; /* when this is positive, we have seen a '?'
|
||||
* without the matching ':' in a '?:'
|
||||
* expression */
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: indent.h,v 1.50 2021/10/25 19:56:03 rillig Exp $ */
|
||||
/* $NetBSD: indent.h,v 1.51 2021/10/26 19:36:30 rillig Exp $ */
|
||||
|
||||
/*-
|
||||
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
|
||||
|
@ -235,7 +235,7 @@ extern struct options {
|
|||
* uses all spaces */
|
||||
bool verbose; /* whether non-essential error messages are
|
||||
* printed */
|
||||
} opt;
|
||||
} opt;
|
||||
|
||||
enum keyword_kind {
|
||||
kw_0,
|
||||
|
@ -344,7 +344,7 @@ extern struct parser_state {
|
|||
int code_lines;
|
||||
int comment_lines;
|
||||
} stats;
|
||||
} ps;
|
||||
} ps;
|
||||
|
||||
|
||||
#define array_length(array) (sizeof (array) / sizeof (array[0]))
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: lexi.c,v 1.102 2021/10/26 18:36:25 rillig Exp $ */
|
||||
/* $NetBSD: lexi.c,v 1.103 2021/10/26 19:36:30 rillig Exp $ */
|
||||
|
||||
/*-
|
||||
* SPDX-License-Identifier: BSD-4-Clause
|
||||
|
@ -43,7 +43,7 @@ static char sccsid[] = "@(#)lexi.c 8.1 (Berkeley) 6/6/93";
|
|||
|
||||
#include <sys/cdefs.h>
|
||||
#if defined(__NetBSD__)
|
||||
__RCSID("$NetBSD: lexi.c,v 1.102 2021/10/26 18:36:25 rillig Exp $");
|
||||
__RCSID("$NetBSD: lexi.c,v 1.103 2021/10/26 19:36:30 rillig Exp $");
|
||||
#elif defined(__FreeBSD__)
|
||||
__FBSDID("$FreeBSD: head/usr.bin/indent/lexi.c 337862 2018-08-15 18:19:45Z pstef $");
|
||||
#endif
|
||||
|
@ -261,7 +261,8 @@ lsym_name(lexer_symbol sym)
|
|||
}
|
||||
|
||||
static const char *
|
||||
kw_name(enum keyword_kind kw) {
|
||||
kw_name(enum keyword_kind kw)
|
||||
{
|
||||
static const char *name[] = {
|
||||
"0",
|
||||
"offsetof",
|
||||
|
@ -437,8 +438,8 @@ lexi_alnum(struct parser_state *state)
|
|||
if (isdigit((unsigned char)*inp.s) ||
|
||||
(inp.s[0] == '.' && isdigit((unsigned char)inp.s[1]))) {
|
||||
lex_number();
|
||||
} else if ((isalnum((unsigned char)*inp.s) ||
|
||||
*inp.s == '_' || *inp.s == '$')) {
|
||||
} else if (isalnum((unsigned char)*inp.s) ||
|
||||
*inp.s == '_' || *inp.s == '$') {
|
||||
lex_word();
|
||||
} else
|
||||
return lsym_eof; /* just as a placeholder */
|
||||
|
@ -453,8 +454,7 @@ lexi_alnum(struct parser_state *state)
|
|||
inbuf_skip();
|
||||
state->keyword = kw_0;
|
||||
|
||||
if (state->last_token == lsym_tag &&
|
||||
state->p_l_follow == 0) {
|
||||
if (state->last_token == lsym_tag && state->p_l_follow == 0) {
|
||||
state->next_unary = true;
|
||||
return lsym_type;
|
||||
}
|
||||
|
@ -717,7 +717,7 @@ lexi(struct parser_state *state)
|
|||
char *tp = inp.s;
|
||||
|
||||
while (isalpha((unsigned char)*tp) ||
|
||||
isspace((unsigned char)*tp)) {
|
||||
isspace((unsigned char)*tp)) {
|
||||
if (++tp >= inp.e)
|
||||
inbuf_read_line();
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: parse.c,v 1.41 2021/10/25 20:32:38 rillig Exp $ */
|
||||
/* $NetBSD: parse.c,v 1.42 2021/10/26 19:36:30 rillig Exp $ */
|
||||
|
||||
/*-
|
||||
* SPDX-License-Identifier: BSD-4-Clause
|
||||
|
@ -134,7 +134,7 @@ parse(parser_symbol psym)
|
|||
}
|
||||
/* FALLTHROUGH */
|
||||
case psym_do:
|
||||
case psym_for_exprs: /* 'for' (...) */
|
||||
case psym_for_exprs: /* 'for' (...) */
|
||||
ps.s_sym[++ps.tos] = psym;
|
||||
ps.s_ind_level[ps.tos] = ps.ind_level = ps.ind_level_follow;
|
||||
++ps.ind_level_follow; /* subsequent statements should be indented 1 */
|
||||
|
@ -284,8 +284,8 @@ reduce_stmt(void)
|
|||
ps.s_sym[--ps.tos] = psym_if_expr_stmt;
|
||||
int i = ps.tos - 1;
|
||||
while (ps.s_sym[i] != psym_stmt &&
|
||||
ps.s_sym[i] != psym_stmt_list &&
|
||||
ps.s_sym[i] != psym_lbrace)
|
||||
ps.s_sym[i] != psym_stmt_list &&
|
||||
ps.s_sym[i] != psym_lbrace)
|
||||
--i;
|
||||
ps.ind_level_follow = ps.s_ind_level[i];
|
||||
/*
|
||||
|
|
Loading…
Reference in New Issue