Module Name:    src
Committed By:   rillig
Date:           Sat Sep 25 17:11:24 UTC 2021

Modified Files:
        src/usr.bin/indent: Makefile args.c indent.c indent.h indent_globs.h
            io.c lexi.c parse.c pr_comment.c

Log Message:
indent: prepare for lint's strict bool mode

Before C99, C had no boolean type. Instead, indent used int for that,
just like many other programs. Even with C99, bool and int can be used
interchangeably in many situations, such as querying '!i' or '!ptr' or
'cond == 0'.

Since January 2021, lint provides the strict bool mode, which makes bool
a non-arithmetic type that is incompatible with any other type. Having
clearly separate types helps in understanding the code.

To migrate indent to strict bool mode, the first step is to apply all
changes that keep the resulting binary the same. Since sizeof(bool) is
1 and sizeof(int) is 4, the type ibool serves as an intermediate type.
For now it is defined to int, later it will become bool.

The current code compiles cleanly in C99 and C11 mode, as well as in
lint's strict bool mode. There are a few tricky places:

In args.c in 'struct pro', there are two types of options: boolean and
integer. Boolean options point to a bool variable, integer options
point to an int variable. To keep the current structure of the code,
the pointer has been changed to 'void *'. To ensure type safety, the
definition of the options is done via preprocessor magic, which in C11
mode ensures the correct pointer types. (Add CFLAGS+=-std=gnu11 at the
very bottom of the Makefile.)

In indent.c in process_preprocessing, a boolean variable is
post-incremented. That variable is only assigned to another variable,
and that variable is only used in a boolean context. To provoke a
different behavior between the '++' and the '= true', the source code
to be indented would need 1 << 32 preprocessing directives, which is
unlikely to happen in practice.

In io.c in dump_line, the variables ps.in_stmt and ps.in_decl only ever
get the values 0 and 1. For these values, the expressions 'a & ~b' and
'a && !b' are equivalent, in all versions of C. The compiler may
generate different code for them, though.

In io.c in parse_indent_comment, the assignment to inhibit_formatting
takes place in integer context. If the compiler is smart enough to
detect the possible values of on_off, it may generate the same code
before and after the change, but that is rather unlikely.

The second step of the migration will be to replace ibool with bool,
step by step, just in case there are any hidden gotchas in the code,
such as sizeof or pointer casts.

No change to the resulting binary.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/usr.bin/indent/Makefile
cvs rdiff -u -r1.24 -r1.25 src/usr.bin/indent/args.c
cvs rdiff -u -r1.72 -r1.73 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.20 -r1.21 src/usr.bin/indent/indent.h
cvs rdiff -u -r1.28 -r1.29 src/usr.bin/indent/indent_globs.h
cvs rdiff -u -r1.59 -r1.60 src/usr.bin/indent/io.c
cvs rdiff -u -r1.53 -r1.54 src/usr.bin/indent/lexi.c
cvs rdiff -u -r1.23 -r1.24 src/usr.bin/indent/parse.c
cvs rdiff -u -r1.42 -r1.43 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/Makefile
diff -u src/usr.bin/indent/Makefile:1.12 src/usr.bin/indent/Makefile:1.13
--- src/usr.bin/indent/Makefile:1.12	Fri Mar 26 22:27:43 2021
+++ src/usr.bin/indent/Makefile	Sat Sep 25 17:11:23 2021
@@ -1,10 +1,10 @@
-#	$NetBSD: Makefile,v 1.12 2021/03/26 22:27:43 rillig Exp $
+#	$NetBSD: Makefile,v 1.13 2021/09/25 17:11:23 rillig Exp $
 #	from: @(#)Makefile	8.1 (Berkeley) 6/6/93
 
 PROG=	indent
 SRCS=	indent.c io.c lexi.c parse.c pr_comment.c args.c
 
 CPPFLAGS+=	${DEBUG:D-Ddebug}
-LINTFLAGS+=	-e -w
+LINTFLAGS+=	-e -w -T
 
 .include <bsd.prog.mk>

Index: src/usr.bin/indent/args.c
diff -u src/usr.bin/indent/args.c:1.24 src/usr.bin/indent/args.c:1.25
--- src/usr.bin/indent/args.c:1.24	Sat Sep 25 14:16:06 2021
+++ src/usr.bin/indent/args.c	Sat Sep 25 17:11:23 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: args.c,v 1.24 2021/09/25 14:16:06 rillig Exp $	*/
+/*	$NetBSD: args.c,v 1.25 2021/09/25 17:11:23 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.24 2021/09/25 14:16:06 rillig Exp $");
+__RCSID("$NetBSD: args.c,v 1.25 2021/09/25 17:11:23 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/args.c 336318 2018-07-15 21:04:21Z pstef $");
 #endif
@@ -88,88 +88,99 @@ const char *option_source = "?";
 
 void add_typedefs_from_file(const char *str);
 
+#if __STDC_VERSION__ >= 201112L
+#define assert_type(expr, type) _Generic((expr), type : (expr))
+#else
+#define assert_type(expr, type) (expr)
+#endif
+#define bool_option(name, value, var) \
+	{name, PRO_BOOL, value, assert_type(&(var), ibool *)}
+#define int_option(name, value, var) \
+	{name, PRO_INT, value, assert_type(&(var), int *)}
+#define special_option(name, value) \
+	{name, PRO_SPECIAL, assert_type(value, int), NULL}
+
 /*
  * N.B.: because of the way the table here is scanned, options whose names are
  * substrings of other options must occur later; that is, with -lp vs -l, -lp
- * must be first.  Also, while (most) booleans occur more than once, the last
- * default value is the one actually assigned.
+ * must be first.
  */
 const struct pro {
     const char *p_name;		/* name, e.g. -bl, -cli */
     int         p_type;		/* type (int, bool, special) */
     int         p_special;	/* depends on type */
-    int        *p_obj;		/* the associated variable */
+    void        *p_obj;		/* the associated variable */
 }           pro[] = {
-    {"T", PRO_SPECIAL, KEY, 0},
-    {"U", PRO_SPECIAL, KEY_FILE, 0},
-    {"-version", PRO_SPECIAL, VERSION, 0},
-    {"P", PRO_SPECIAL, IGN, 0},
-    {"bacc", PRO_BOOL, ON, &opt.blanklines_around_conditional_compilation},
-    {"badp", PRO_BOOL, ON, &opt.blanklines_after_declarations_at_proctop},
-    {"bad", PRO_BOOL, ON, &opt.blanklines_after_declarations},
-    {"bap", PRO_BOOL, ON, &opt.blanklines_after_procs},
-    {"bbb", PRO_BOOL, ON, &opt.blanklines_before_blockcomments},
-    {"bc", PRO_BOOL, OFF, &opt.leave_comma},
-    {"bl", PRO_BOOL, OFF, &opt.btype_2},
-    {"br", PRO_BOOL, ON, &opt.btype_2},
-    {"bs", PRO_BOOL, ON, &opt.Bill_Shannon},
-    {"cdb", PRO_BOOL, ON, &opt.comment_delimiter_on_blankline},
-    {"cd", PRO_INT, 0, &opt.decl_comment_column},
-    {"ce", PRO_BOOL, ON, &opt.cuddle_else},
-    {"ci", PRO_INT, 0, &opt.continuation_indent},
-    {"cli", PRO_SPECIAL, CLI, 0},
-    {"cs", PRO_BOOL, ON, &opt.space_after_cast},
-    {"c", PRO_INT, 0, &opt.comment_column},
-    {"di", PRO_INT, 0, &opt.decl_indent},
-    {"dj", PRO_BOOL, ON, &opt.ljust_decl},
-    {"d", PRO_INT, 0, &opt.unindent_displace},
-    {"eei", PRO_BOOL, ON, &opt.extra_expression_indent},
-    {"ei", PRO_BOOL, ON, &opt.else_if},
-    {"fbs", PRO_BOOL, ON, &opt.function_brace_split},
-    {"fc1", PRO_BOOL, ON, &opt.format_col1_comments},
-    {"fcb", PRO_BOOL, ON, &opt.format_block_comments},
-    {"ip", PRO_BOOL, ON, &opt.indent_parameters},
-    {"i", PRO_INT, 0, &opt.indent_size},
-    {"lc", PRO_INT, 0, &opt.block_comment_max_line_length},
-    {"ldi", PRO_INT, 0, &opt.local_decl_indent},
-    {"lpl", PRO_BOOL, ON, &opt.lineup_to_parens_always},
-    {"lp", PRO_BOOL, ON, &opt.lineup_to_parens},
-    {"l", PRO_INT, 0, &opt.max_line_length},
-    {"nbacc", PRO_BOOL, OFF, &opt.blanklines_around_conditional_compilation},
-    {"nbadp", PRO_BOOL, OFF, &opt.blanklines_after_declarations_at_proctop},
-    {"nbad", PRO_BOOL, OFF, &opt.blanklines_after_declarations},
-    {"nbap", PRO_BOOL, OFF, &opt.blanklines_after_procs},
-    {"nbbb", PRO_BOOL, OFF, &opt.blanklines_before_blockcomments},
-    {"nbc", PRO_BOOL, ON, &opt.leave_comma},
-    {"nbs", PRO_BOOL, OFF, &opt.Bill_Shannon},
-    {"ncdb", PRO_BOOL, OFF, &opt.comment_delimiter_on_blankline},
-    {"nce", PRO_BOOL, OFF, &opt.cuddle_else},
-    {"ncs", PRO_BOOL, OFF, &opt.space_after_cast},
-    {"ndj", PRO_BOOL, OFF, &opt.ljust_decl},
-    {"neei", PRO_BOOL, OFF, &opt.extra_expression_indent},
-    {"nei", PRO_BOOL, OFF, &opt.else_if},
-    {"nfbs", PRO_BOOL, OFF, &opt.function_brace_split},
-    {"nfc1", PRO_BOOL, OFF, &opt.format_col1_comments},
-    {"nfcb", PRO_BOOL, OFF, &opt.format_block_comments},
-    {"nip", PRO_BOOL, OFF, &opt.indent_parameters},
-    {"nlpl", PRO_BOOL, OFF, &opt.lineup_to_parens_always},
-    {"nlp", PRO_BOOL, OFF, &opt.lineup_to_parens},
-    {"npcs", PRO_BOOL, OFF, &opt.proc_calls_space},
-    {"npro", PRO_SPECIAL, IGN, 0},
-    {"npsl", PRO_BOOL, OFF, &opt.procnames_start_line},
-    {"nsc", PRO_BOOL, OFF, &opt.star_comment_cont},
-    {"nsob", PRO_BOOL, OFF, &opt.swallow_optional_blanklines},
-    {"nut", PRO_BOOL, OFF, &opt.use_tabs},
-    {"nv", PRO_BOOL, OFF, &opt.verbose},
-    {"pcs", PRO_BOOL, ON, &opt.proc_calls_space},
-    {"psl", PRO_BOOL, ON, &opt.procnames_start_line},
-    {"sc", PRO_BOOL, ON, &opt.star_comment_cont},
-    {"sob", PRO_BOOL, ON, &opt.swallow_optional_blanklines},
-    {"st", PRO_SPECIAL, STDIN, 0},
-    {"ta", PRO_BOOL, ON, &opt.auto_typedefs},
-    {"ts", PRO_INT, 0, &opt.tabsize},
-    {"ut", PRO_BOOL, ON, &opt.use_tabs},
-    {"v", PRO_BOOL, ON, &opt.verbose},
+    special_option("T", KEY),
+    special_option("U", KEY_FILE),
+    special_option("-version", VERSION),
+    special_option("P", IGN),
+    bool_option("bacc", ON, opt.blanklines_around_conditional_compilation),
+    bool_option("badp", ON, opt.blanklines_after_declarations_at_proctop),
+    bool_option("bad", ON, opt.blanklines_after_declarations),
+    bool_option("bap", ON, opt.blanklines_after_procs),
+    bool_option("bbb", ON, opt.blanklines_before_blockcomments),
+    bool_option("bc", OFF, opt.leave_comma),
+    bool_option("bl", OFF, opt.btype_2),
+    bool_option("br", ON, opt.btype_2),
+    bool_option("bs", ON, opt.Bill_Shannon),
+    bool_option("cdb", ON, opt.comment_delimiter_on_blankline),
+    int_option("cd", 0, opt.decl_comment_column),
+    bool_option("ce", ON, opt.cuddle_else),
+    int_option("ci", 0, opt.continuation_indent),
+    special_option("cli", CLI),
+    bool_option("cs", ON, opt.space_after_cast),
+    int_option("c", 0, opt.comment_column),
+    int_option("di", 0, opt.decl_indent),
+    bool_option("dj", ON, opt.ljust_decl),
+    int_option("d", 0, opt.unindent_displace),
+    bool_option("eei", ON, opt.extra_expression_indent),
+    bool_option("ei", ON, opt.else_if),
+    bool_option("fbs", ON, opt.function_brace_split),
+    bool_option("fc1", ON, opt.format_col1_comments),
+    bool_option("fcb", ON, opt.format_block_comments),
+    bool_option("ip", ON, opt.indent_parameters),
+    int_option("i", 0, opt.indent_size),
+    int_option("lc", 0, opt.block_comment_max_line_length),
+    int_option("ldi", 0, opt.local_decl_indent),
+    bool_option("lpl", ON, opt.lineup_to_parens_always),
+    bool_option("lp", ON, opt.lineup_to_parens),
+    int_option("l", 0, opt.max_line_length),
+    bool_option("nbacc", OFF, opt.blanklines_around_conditional_compilation),
+    bool_option("nbadp", OFF, opt.blanklines_after_declarations_at_proctop),
+    bool_option("nbad", OFF, opt.blanklines_after_declarations),
+    bool_option("nbap", OFF, opt.blanklines_after_procs),
+    bool_option("nbbb", OFF, opt.blanklines_before_blockcomments),
+    bool_option("nbc", ON, opt.leave_comma),
+    bool_option("nbs", OFF, opt.Bill_Shannon),
+    bool_option("ncdb", OFF, opt.comment_delimiter_on_blankline),
+    bool_option("nce", OFF, opt.cuddle_else),
+    bool_option("ncs", OFF, opt.space_after_cast),
+    bool_option("ndj", OFF, opt.ljust_decl),
+    bool_option("neei", OFF, opt.extra_expression_indent),
+    bool_option("nei", OFF, opt.else_if),
+    bool_option("nfbs", OFF, opt.function_brace_split),
+    bool_option("nfc1", OFF, opt.format_col1_comments),
+    bool_option("nfcb", OFF, opt.format_block_comments),
+    bool_option("nip", OFF, opt.indent_parameters),
+    bool_option("nlpl", OFF, opt.lineup_to_parens_always),
+    bool_option("nlp", OFF, opt.lineup_to_parens),
+    bool_option("npcs", OFF, opt.proc_calls_space),
+    special_option("npro", IGN),
+    bool_option("npsl", OFF, opt.procnames_start_line),
+    bool_option("nsc", OFF, opt.star_comment_cont),
+    bool_option("nsob", OFF, opt.swallow_optional_blanklines),
+    bool_option("nut", OFF, opt.use_tabs),
+    bool_option("nv", OFF, opt.verbose),
+    bool_option("pcs", ON, opt.proc_calls_space),
+    bool_option("psl", ON, opt.procnames_start_line),
+    bool_option("sc", ON, opt.star_comment_cont),
+    bool_option("sob", ON, opt.swallow_optional_blanklines),
+    special_option("st", STDIN),
+    bool_option("ta", ON, opt.auto_typedefs),
+    int_option("ts", 0, opt.tabsize),
+    bool_option("ut", ON, opt.use_tabs),
+    bool_option("v", ON, opt.verbose),
     /* whew! */
     {0, 0, 0, 0}
 };
@@ -211,14 +222,14 @@ scan_profile(FILE *f)
 	p = buf;
 	comment_index = 0;
 	while ((i = getc(f)) != EOF) {
-	    if (i == '*' && !comment_index && p > buf && p[-1] == '/') {
+	    if (i == '*' && comment_index == 0 && p > buf && p[-1] == '/') {
 		comment_index = (int)(p - buf);
 		*p++ = i;
-	    } else if (i == '/' && comment_index && p > buf && p[-1] == '*') {
+	    } else if (i == '/' && comment_index != 0 && p > buf && p[-1] == '*') {
 		p = buf + comment_index - 1;
 		comment_index = 0;
 	    } else if (isspace((unsigned char)i)) {
-		if (p > buf && !comment_index)
+		if (p > buf && comment_index == 0)
 		    break;
 	    } else {
 		*p++ = i;
@@ -237,7 +248,7 @@ scan_profile(FILE *f)
 static const char *
 eqin(const char *s1, const char *s2)
 {
-    while (*s1) {
+    while (*s1 != '\0') {
 	if (*s1++ != *s2++)
 	    return NULL;
     }
@@ -251,7 +262,7 @@ set_option(char *arg)
     const char	*param_start;
 
     arg++;			/* ignore leading "-" */
-    for (p = pro; p->p_name; p++)
+    for (p = pro; p->p_name != NULL; p++)
 	if (*p->p_name == *arg && (param_start = eqin(p->p_name, arg)) != NULL)
 	    goto found;
     errx(1, "%s: unknown parameter \"%s\"", option_source, arg - 1);
@@ -301,9 +312,9 @@ found:
 
     case PRO_BOOL:
 	if (p->p_special == OFF)
-	    *p->p_obj = false;
+	    *(ibool *)p->p_obj = false;
 	else
-	    *p->p_obj = true;
+	    *(ibool *)p->p_obj = true;
 	break;
 
     case PRO_INT:
@@ -311,7 +322,7 @@ found:
     need_param:
 	    errx(1, "%s: ``%s'' requires a parameter", option_source, p->p_name);
 	}
-	*p->p_obj = atoi(param_start);
+	*(int *)p->p_obj = atoi(param_start);
 	break;
 
     default:

Index: src/usr.bin/indent/indent.c
diff -u src/usr.bin/indent/indent.c:1.72 src/usr.bin/indent/indent.c:1.73
--- src/usr.bin/indent/indent.c:1.72	Sat Sep 25 14:26:05 2021
+++ src/usr.bin/indent/indent.c	Sat Sep 25 17:11:23 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.72 2021/09/25 14:26:05 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.73 2021/09/25 17:11:23 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.72 2021/09/25 14:26:05 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.73 2021/09/25 17:11:23 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -107,13 +107,13 @@ char       *be_save;
 
 int         found_err;
 int         n_real_blanklines;
-int         prefix_blankline_requested;
-int         postfix_blankline_requested;
-int         break_comma;
+ibool       prefix_blankline_requested;
+ibool       postfix_blankline_requested;
+ibool       break_comma;
 float       case_ind;
-int         had_eof;
+ibool       had_eof;
 int         line_no;
-int         inhibit_formatting;
+ibool       inhibit_formatting;
 int         suppress_blanklines;
 
 int         ifdef_level;
@@ -124,7 +124,7 @@ FILE       *input;
 FILE       *output;
 
 static void bakcopy(void);
-static void indent_declaration(int, int);
+static void indent_declaration(int, ibool);
 
 const char *in_name = "Standard Input";	/* will always point to name of input
 					 * file */
@@ -181,8 +181,8 @@ init_capsicum(void)
 #endif
 
 static void
-search_brace(token_type *inout_ttype, int *inout_force_nl,
-	     int *inout_comment_buffered, int *inout_last_else)
+search_brace(token_type *inout_ttype, ibool *inout_force_nl,
+	     ibool *inout_comment_buffered, ibool *inout_last_else)
 {
     while (ps.search_brace) {
 	switch (*inout_ttype) {
@@ -263,7 +263,7 @@ search_brace(token_type *inout_ttype, in
 	    /* FALLTHROUGH */
 	default:		/* it is the start of a normal statement */
 	{
-	    int remove_newlines;
+	    ibool remove_newlines;
 
 	    remove_newlines =
 		    /* "} else" */
@@ -300,7 +300,7 @@ search_brace(token_type *inout_ttype, in
 				 * not already broken */
 		    diag(0, "Line broken");
 	    }
-	    for (const char *t_ptr = token.s; *t_ptr; ++t_ptr)
+	    for (const char *t_ptr = token.s; *t_ptr != '\0'; ++t_ptr)
 		*sc_end++ = *t_ptr;
 
 	    sw_buffer:
@@ -362,7 +362,7 @@ search_brace(token_type *inout_ttype, in
 	}
     }
 
-    *inout_last_else = 0;
+    *inout_last_else = false;
 }
 
 static void
@@ -391,7 +391,7 @@ main_init_globals(void)
     buf_init(&token);
     alloc_typenames();
     init_constant_tt();
-    opt.else_if = 1;		/* Default else-if special processing to on */
+    opt.else_if = true;		/* XXX: redundant? */
 
     in_buffer = xmalloc(10);
     in_buffer_limit = in_buffer + 8;
@@ -524,7 +524,7 @@ process_end_of_file(void)
 }
 
 static void
-process_comment_in_code(token_type ttype, int *inout_force_nl)
+process_comment_in_code(token_type ttype, ibool *inout_force_nl)
 {
     if (*inout_force_nl &&
 	ttype != semicolon &&
@@ -576,7 +576,7 @@ process_newline(void)
 }
 
 static void
-process_lparen_or_lbracket(int dec_ind, int tabs_to_var, int sp_sw)
+process_lparen_or_lbracket(int dec_ind, ibool tabs_to_var, ibool sp_sw)
 {
     /* count parens to make Healy happy */
     if (++ps.p_l_follow == nitems(ps.paren_indents)) {
@@ -626,10 +626,10 @@ process_lparen_or_lbracket(int dec_ind, 
 }
 
 static void
-process_rparen_or_rbracket(int *inout_sp_sw, int *inout_force_nl,
+process_rparen_or_rbracket(ibool *inout_sp_sw, ibool *inout_force_nl,
 			 token_type hd_type)
 {
-    if (ps.cast_mask & (1 << ps.p_l_follow) & ~ps.not_cast_mask) {
+    if ((ps.cast_mask & (1 << ps.p_l_follow) & ~ps.not_cast_mask) != 0) {
 	ps.last_u_d = true;
 	ps.cast_mask &= (1 << ps.p_l_follow) - 1;
 	ps.want_blank = opt.space_after_cast;
@@ -663,7 +663,7 @@ process_rparen_or_rbracket(int *inout_sp
 }
 
 static void
-process_unary_op(int dec_ind, int tabs_to_var)
+process_unary_op(int dec_ind, ibool tabs_to_var)
 {
     if (!ps.dumped_decl_indent && ps.in_decl && !ps.block_init &&
 	ps.procname[0] == '\0' && ps.paren_level == 0) {
@@ -674,7 +674,7 @@ process_unary_op(int dec_ind, int tabs_t
 	 * this token
 	 */
 	int i;
-	for (i = 0; token.s[i]; ++i)
+	for (i = 0; token.s[i] != '\0'; ++i)
 	    /* find length of token */;
 	indent_declaration(dec_ind - i, tabs_to_var);
 	ps.dumped_decl_indent = true;
@@ -726,7 +726,7 @@ process_question(int *inout_squest)
 }
 
 static void
-process_colon(int *inout_squest, int *inout_force_nl, int *inout_scase)
+process_colon(int *inout_squest, ibool *inout_force_nl, ibool *inout_scase)
 {
     if (*inout_squest > 0) {	/* it is part of the <c>?<n>: <n> construct */
 	--*inout_squest;
@@ -766,10 +766,10 @@ process_colon(int *inout_squest, int *in
 }
 
 static void
-process_semicolon(int *inout_scase, int *inout_squest, int const dec_ind,
-		  int const tabs_to_var, int *inout_sp_sw,
-		  token_type const hd_type,
-		  int *inout_force_nl)
+process_semicolon(ibool *inout_scase, int *inout_squest, int dec_ind,
+		  ibool tabs_to_var, ibool *inout_sp_sw,
+		  token_type hd_type,
+		  ibool *inout_force_nl)
 {
     if (ps.dec_nest == 0)
 	ps.in_or_st = false;	/* we are not in an initialization or
@@ -777,10 +777,10 @@ process_semicolon(int *inout_scase, int 
     *inout_scase = false; /* these will only need resetting in an error */
     *inout_squest = 0;
     if (ps.last_token == rparen)
-	ps.in_parameter_declaration = 0;
+	ps.in_parameter_declaration = false;
     ps.cast_mask = 0;
     ps.not_cast_mask = 0;
-    ps.block_init = 0;
+    ps.block_init = false;
     ps.block_init_level = 0;
     ps.just_saw_decl--;
 
@@ -822,7 +822,7 @@ process_semicolon(int *inout_scase, int 
 }
 
 static void
-process_lbrace(int *inout_force_nl, int *inout_sp_sw, token_type hd_type,
+process_lbrace(ibool *inout_force_nl, ibool *inout_sp_sw, token_type hd_type,
 	       int *di_stack, int di_stack_cap, int *inout_dec_ind)
 {
     ps.in_stmt = false;	/* dont indent the {} */
@@ -849,7 +849,7 @@ process_lbrace(int *inout_force_nl, int 
 	}
     }
     if (ps.in_parameter_declaration)
-	prefix_blankline_requested = 0;
+	prefix_blankline_requested = false;
 
     if (ps.p_l_follow > 0) {	/* check for preceding unbalanced
 				 * parens */
@@ -880,8 +880,8 @@ process_lbrace(int *inout_force_nl, int 
 						 * comments */
 	if (opt.blanklines_after_declarations_at_proctop
 	    && ps.in_parameter_declaration)
-	    postfix_blankline_requested = 1;
-	ps.in_parameter_declaration = 0;
+	    postfix_blankline_requested = true;
+	ps.in_parameter_declaration = false;
 	ps.in_decl = false;
     }
     *inout_dec_ind = 0;
@@ -895,12 +895,12 @@ process_lbrace(int *inout_force_nl, int 
 }
 
 static void
-process_rbrace(int *inout_sp_sw, int *inout_dec_ind, const int *di_stack)
+process_rbrace(ibool *inout_sp_sw, int *inout_dec_ind, const int *di_stack)
 {
     if (ps.p_stack[ps.tos] == decl && !ps.block_init)	/* semicolons can be
 				 * omitted in declarations */
 	parse(semicolon);
-    if (ps.p_l_follow) {	/* check for unclosed if, for, else. */
+    if (ps.p_l_follow != 0) {	/* check for unclosed if, for, else. */
 	diag(1, "Unbalanced parens");
 	ps.p_l_follow = 0;
 	*inout_sp_sw = false;
@@ -921,17 +921,17 @@ process_rbrace(int *inout_sp_sw, int *in
 	    ps.just_saw_decl = 2;
 	ps.in_decl = true;
     }
-    prefix_blankline_requested = 0;
+    prefix_blankline_requested = false;
     parse(rbrace);		/* let parser know about this */
     ps.search_brace = opt.cuddle_else
 		      && ps.p_stack[ps.tos] == if_expr_stmt
 		      && ps.il[ps.tos] >= ps.ind_level;
     if (ps.tos <= 1 && opt.blanklines_after_procs && ps.dec_nest <= 0)
-	postfix_blankline_requested = 1;
+	postfix_blankline_requested = true;
 }
 
 static void
-process_keyword_do_else(int *inout_force_nl, int *inout_last_else)
+process_keyword_do_else(ibool *inout_force_nl, ibool *inout_last_else)
 {
     ps.in_stmt = false;
     if (*token.s == 'e') {
@@ -942,7 +942,7 @@ process_keyword_do_else(int *inout_force
 	    ps.want_blank = false;
 	}
 	*inout_force_nl = true;/* also, following stuff must go onto new line */
-	*inout_last_else = 1;
+	*inout_last_else = true;
 	parse(keyword_else);
     } else {
 	if (code.e != code.s) {	/* make sure this starts a line */
@@ -952,48 +952,48 @@ process_keyword_do_else(int *inout_force
 	    ps.want_blank = false;
 	}
 	*inout_force_nl = true;/* also, following stuff must go onto new line */
-	*inout_last_else = 0;
+	*inout_last_else = false;
 	parse(keyword_do);
     }
 }
 
 static void
-process_decl(int *out_dec_ind, int *out_tabs_to_var)
+process_decl(int *out_dec_ind, ibool *out_tabs_to_var)
 {
     parse(decl);		/* let parser worry about indentation */
     if (ps.last_token == rparen && ps.tos <= 1) {
 	if (code.s != code.e) {
 	    dump_line();
-	    ps.want_blank = 0;
+	    ps.want_blank = false;
 	}
     }
     if (ps.in_parameter_declaration && opt.indent_parameters && ps.dec_nest == 0) {
 	ps.ind_level = ps.i_l_follow = 1;
-	ps.ind_stmt = 0;
+	ps.ind_stmt = false;
     }
     ps.in_or_st = true;		/* this might be a structure or initialization
 				 * declaration */
     ps.in_decl = ps.decl_on_line = ps.last_token != type_def;
     if ( /* !ps.in_or_st && */ ps.dec_nest <= 0)
 	ps.just_saw_decl = 2;
-    prefix_blankline_requested = 0;
+    prefix_blankline_requested = false;
     int i;
-    for (i = 0; token.s[i++];);	/* get length of token */
+    for (i = 0; token.s[i++] != '\0';);	/* get length of token */
 
     if (ps.ind_level == 0 || ps.dec_nest > 0) {
 	/* global variable or struct member in local variable */
 	*out_dec_ind = opt.decl_indent > 0 ? opt.decl_indent : i;
-	*out_tabs_to_var = (opt.use_tabs ? opt.decl_indent > 0 : 0);
+	*out_tabs_to_var = opt.use_tabs ? opt.decl_indent > 0 : false;
     } else {
 	/* local variable */
 	*out_dec_ind = opt.local_decl_indent > 0 ? opt.local_decl_indent : i;
-	*out_tabs_to_var = (opt.use_tabs ? opt.local_decl_indent > 0 : 0);
+	*out_tabs_to_var = opt.use_tabs ? opt.local_decl_indent > 0 : false;
     }
 }
 
 static void
-process_ident(token_type ttype, int dec_ind, int tabs_to_var,
-	      int *inout_sp_sw, int *inout_force_nl, token_type hd_type)
+process_ident(token_type ttype, int dec_ind, ibool tabs_to_var,
+	      ibool *inout_sp_sw, ibool *inout_force_nl, token_type hd_type)
 {
     if (ps.in_decl) {
 	if (ttype == funcname) {
@@ -1055,7 +1055,7 @@ process_period(void)
 }
 
 static void
-process_comma(int dec_ind, int tabs_to_var, int *inout_force_nl)
+process_comma(int dec_ind, ibool tabs_to_var, ibool *inout_force_nl)
 {
     ps.want_blank = (code.s != code.e);	/* only put blank after comma
 				 * if comma does not start the line */
@@ -1068,7 +1068,7 @@ process_comma(int dec_ind, int tabs_to_v
     *code.e++ = ',';
     if (ps.p_l_follow == 0) {
 	if (ps.block_init_level <= 0)
-	    ps.block_init = 0;
+	    ps.block_init = false;
 	if (break_comma && (!opt.leave_comma ||
 			    indentation_after_range(
 				    compute_code_indent(), code.s, code.e)
@@ -1086,7 +1086,7 @@ process_preprocessing(void)
     *lab.e++ = '#';	/* move whole line to 'label' buffer */
 
     {
-	int         in_comment = 0;
+	ibool in_comment = false;
 	int         com_start = 0;
 	char        quote = '\0';
 	int         com_end = 0;
@@ -1111,7 +1111,7 @@ process_preprocessing(void)
 		break;
 	    case '/':
 		if (*buf_ptr == '*' && !in_comment && quote == '\0') {
-		    in_comment = 1;
+		    in_comment = true;
 		    *lab.e++ = *buf_ptr++;
 		    com_start = (int)(lab.e - lab.s) - 2;
 		}
@@ -1130,7 +1130,7 @@ process_preprocessing(void)
 		break;
 	    case '*':
 		if (*buf_ptr == '/' && in_comment) {
-		    in_comment = 0;
+		    in_comment = false;
 		    *lab.e++ = *buf_ptr++;
 		    com_end = (int)(lab.e - lab.s);
 		}
@@ -1203,11 +1203,15 @@ process_preprocessing(void)
 	}
     }
     if (opt.blanklines_around_conditional_compilation) {
+#ifdef lint
+	postfix_blankline_requested = true;
+#else
 	postfix_blankline_requested++;
+#endif
 	n_real_blanklines = 0;
     } else {
-	postfix_blankline_requested = 0;
-	prefix_blankline_requested = 0;
+	postfix_blankline_requested = false;
+	prefix_blankline_requested = false;
     }
 
     /*
@@ -1220,19 +1224,19 @@ static void __attribute__((__noreturn__)
 main_loop(void)
 {
     token_type ttype;
-    int force_nl;		/* when true, code must be broken */
-    int last_else = false;	/* true iff last keyword was an else */
+    ibool force_nl;		/* when true, code must be broken */
+    ibool last_else = false;	/* true iff last keyword was an else */
     int         dec_ind;	/* current indentation for declarations */
     int         di_stack[20];	/* a stack of structure indentation levels */
-    int		tabs_to_var;	/* true if using tabs to indent to var name */
-    int         sp_sw;		/* when true, we are in the expression of
+    ibool tabs_to_var;		/* true if using tabs to indent to var name */
+    ibool sp_sw;		/* when true, we are in the expression of
 				 * if(...), while(...), etc. */
     token_type  hd_type = end_of_file; /* used to store type of stmt
 				 * for if (...), for (...), etc */
-    int         squest;		/* when this is positive, we have seen a ?
-				 * without the matching : in a <c>?<s>:<s>
+    int squest;			/* when this is positive, we have seen a '?'
+				 * without the matching ':' in a <c>?<s>:<s>
 				 * construct */
-    int         scase;		/* set to true when we see a case, so we will
+    ibool scase;		/* set to true when we see a case, so we will
 				 * know what to do with the following colon */
 
     sp_sw = force_nl = false;
@@ -1240,11 +1244,11 @@ main_loop(void)
     di_stack[ps.dec_nest = 0] = 0;
     scase = false;
     squest = 0;
-    tabs_to_var = 0;
+    tabs_to_var = false;
 
     for (;;) {			/* this is the main loop.  it will go until we
 				 * reach eof */
-	int comment_buffered = false;
+	ibool comment_buffered = false;
 
 	ttype = lexi(&ps);	/* Read the next token.  The actual characters
 				 * read are stored in "token". */
@@ -1359,7 +1363,7 @@ main_loop(void)
 
 	case type_def:
 	case storage_class:
-	    prefix_blankline_requested = 0;
+	    prefix_blankline_requested = false;
 	    goto copy_id;
 
 	case keyword_struct_union_enum:
@@ -1437,7 +1441,7 @@ bakcopy(void)
     const char *p;
 
     /* construct file name .Bfile */
-    for (p = in_name; *p; p++);	/* skip to end of string */
+    for (p = in_name; *p != '\0'; p++);	/* skip to end of string */
     while (p > in_name && *p != '/')	/* find last '/' */
 	p--;
     if (*p == '/')
@@ -1469,7 +1473,7 @@ bakcopy(void)
 }
 
 static void
-indent_declaration(int cur_dec_ind, int tabs_to_var)
+indent_declaration(int cur_dec_ind, ibool tabs_to_var)
 {
     int pos = (int)(code.e - code.s);
     char *startpos = code.e;

Index: src/usr.bin/indent/indent.h
diff -u src/usr.bin/indent/indent.h:1.20 src/usr.bin/indent/indent.h:1.21
--- src/usr.bin/indent/indent.h:1.20	Sat Sep 25 14:38:31 2021
+++ src/usr.bin/indent/indent.h	Sat Sep 25 17:11:23 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.h,v 1.20 2021/09/25 14:38:31 rillig Exp $	*/
+/*	$NetBSD: indent.h,v 1.21 2021/09/25 17:11:23 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -34,6 +34,12 @@ __FBSDID("$FreeBSD: head/usr.bin/indent/
 
 #include <stdbool.h>
 
+#ifdef lint
+typedef bool ibool;
+#else
+typedef int ibool;
+#endif
+
 #include "indent_codes.h"
 #include "indent_globs.h"
 

Index: src/usr.bin/indent/indent_globs.h
diff -u src/usr.bin/indent/indent_globs.h:1.28 src/usr.bin/indent/indent_globs.h:1.29
--- src/usr.bin/indent/indent_globs.h:1.28	Sat Sep 25 14:38:31 2021
+++ src/usr.bin/indent/indent_globs.h	Sat Sep 25 17:11:23 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent_globs.h,v 1.28 2021/09/25 14:38:31 rillig Exp $	*/
+/*	$NetBSD: indent_globs.h,v 1.29 2021/09/25 17:11:23 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -78,27 +78,27 @@ extern char       *be_save;		/* similarl
 
 
 extern struct options {
-    int         blanklines_around_conditional_compilation;
-    int         blanklines_after_declarations_at_proctop; /* this is vaguely
+    ibool	blanklines_around_conditional_compilation;
+    ibool	blanklines_after_declarations_at_proctop; /* this is vaguely
 				 * similar to blanklines_after_declarations
 				 * except that it only applies to the first
 				 * set of declarations in a procedure (just
 				 * after the first '{') and it causes a blank
 				 * line to be generated even if there are no
 				 * declarations */
-    int         blanklines_after_declarations;
-    int         blanklines_after_procs;
-    int         blanklines_before_blockcomments;
-    int         leave_comma;	/* if true, never break declarations after
+    ibool	blanklines_after_declarations;
+    ibool	blanklines_after_procs;
+    ibool	blanklines_before_blockcomments;
+    ibool	leave_comma;	/* if true, never break declarations after
 				 * commas */
-    int         btype_2;	/* when true, brace should be on same line
+    ibool	btype_2;	/* whether brace should be on same line
 				 * as if, while, etc */
-    int         Bill_Shannon;	/* true iff a blank should always be
+    ibool	Bill_Shannon;	/* whether a blank should always be
 				 * inserted after sizeof */
-    int         comment_delimiter_on_blankline;
+    ibool	comment_delimiter_on_blankline;
     int         decl_comment_column; /* the column in which comments after
 				 * declarations should be put */
-    int         cuddle_else;	/* true if 'else' should cuddle up to '}' */
+    ibool	cuddle_else;	/* whether 'else' should cuddle up to '}' */
     int         continuation_indent; /* set to the indentation between the
 				 * edge of code and continuation lines */
     float       case_indent;	/* The distance (measured in tabsize) to
@@ -107,52 +107,52 @@ extern struct options {
     int         comment_column;	/* the column in which comments to the right
 				 * of code should start */
     int         decl_indent;	/* indentation of identifier in declaration */
-    int         ljust_decl;	/* true if declarations should be left
+    ibool	ljust_decl;	/* true if declarations should be left
 				 * justified */
     int         unindent_displace; /* comments not to the right of code
 				 * will be placed this many
 				 * indentation levels to the left of
 				 * code */
-    int         extra_expression_indent; /* true if continuation lines from
+    ibool	extra_expression_indent; /* whether continuation lines from
 				 * the expression part of "if(e)",
 				 * "while(e)", "for(e;e;e)" should be
 				 * indented an extra tab stop so that they
 				 * don't conflict with the code that follows */
-    int         else_if;	/* True iff else if pairs should be handled
+    ibool	else_if;	/* whether else-if pairs should be handled
 				 * specially */
-    int         function_brace_split; /* split function declaration and
+    ibool	function_brace_split; /* split function declaration and
 				 * brace onto separate lines */
-    int         format_col1_comments; /* If comments which start in column 1
+    ibool	format_col1_comments; /* If comments which start in column 1
 				 * are to be magically reformatted (just
 				 * like comments that begin in later columns) */
-    int         format_block_comments; /* true if comments beginning with
+    ibool	format_block_comments; /* whether comments beginning with
 				 * '/ * \n' are to be reformatted */
-    int         indent_parameters;
+    ibool	indent_parameters;
     int         indent_size;	/* the size of one indentation level */
     int         block_comment_max_line_length;
     int         local_decl_indent; /* like decl_indent but for locals */
-    int         lineup_to_parens_always; /* if true, do not attempt to keep
+    ibool	lineup_to_parens_always; /* whether to not(?) attempt to keep
 				 * lined-up code within the margin */
-    int         lineup_to_parens; /* if true, continued code within parens
+    ibool	lineup_to_parens; /* whether continued code within parens
 				 * will be lined up to the open paren */
-    int         proc_calls_space; /* If true, procedure calls look like:
+    ibool	proc_calls_space; /* whether procedure calls look like:
 				 * foo (bar) rather than foo(bar) */
-    int         procnames_start_line; /* if true, the names of procedures
-				 * being defined get placed in column 1 (ie.
+    ibool	procnames_start_line; /* whether, the names of procedures
+				 * being defined get placed in column 1 (i.e.
 				 * a newline is placed between the type of
 				 * the procedure and its name) */
-    int         space_after_cast; /* "b = (int) a" vs "b = (int)a" */
-    int         star_comment_cont; /* true iff comment continuation lines
+    ibool	space_after_cast; /* "b = (int) a" vs "b = (int)a" */
+    ibool	star_comment_cont; /* whether comment continuation lines
 				 * should have stars at the beginning of
 				 * each line. */
-    int         swallow_optional_blanklines;
-    int         auto_typedefs;	/* set true to recognize identifiers
+    ibool	swallow_optional_blanklines;
+    ibool	auto_typedefs;	/* whether to recognize identifiers
 				 * ending in "_t" like typedefs */
     int         tabsize;	/* the size of a tab */
     int         max_line_length;
-    int         use_tabs;	/* set true to use tabs for spacing, false
+    ibool	use_tabs;	/* set true to use tabs for spacing, false
 				 * uses all spaces */
-    int         verbose;	/* when true, non-essential error messages
+    ibool	verbose;	/* whether non-essential error messages
 				 * are printed */
 } opt;
 
@@ -175,15 +175,15 @@ enum rwcode {
 
 extern int         found_err;
 extern int         n_real_blanklines;
-extern int         prefix_blankline_requested;
-extern int         postfix_blankline_requested;
-extern int         break_comma;	/* when true and not in parens, break after a
+extern ibool	prefix_blankline_requested;
+extern ibool	postfix_blankline_requested;
+extern ibool	break_comma;	/* when true and not in parens, break after a
 				 * comma */
 extern float       case_ind;		/* indentation level to be used for a "case
 				 * n:" */
-extern int         had_eof;		/* set to true when input is exhausted */
+extern ibool	had_eof;		/* set to true when input is exhausted */
 extern int         line_no;		/* the current line number. */
-extern int         inhibit_formatting;	/* true if INDENT OFF is in effect */
+extern ibool	inhibit_formatting;	/* true if INDENT OFF is in effect */
 extern int         suppress_blanklines;/* set iff following blanklines should be
 				 * suppressed */
 
@@ -194,9 +194,9 @@ extern struct parser_state {
     token_type	p_stack[STACKSIZE];	/* this is the parsers stack */
     int         il[STACKSIZE];	/* this stack stores indentation levels */
     float       cstk[STACKSIZE];/* used to store case stmt indentation levels */
-    int         box_com;	/* set to true when we are in a "boxed"
-				 * comment. In that case, the first non-blank
-				 * char should be lined up with the / in / followed by * */
+    ibool	box_com;	/* whether we are in a "boxed" comment. In
+				 * that case, the first non-blank char should
+				 * be lined up with the '/' in '/' + '*' */
     int         comment_delta;	/* used to set up indentation for all lines
 				 * of a boxed comment after the first one */
     int         n_comment_delta;/* remembers how many columns there were
@@ -207,57 +207,57 @@ extern struct parser_state {
 				 * close off casts */
     int         not_cast_mask;	/* indicates which close parens definitely
 				 * close off something else than casts */
-    int         block_init;	/* true iff inside a block initialization */
+    ibool	block_init;	/* whether inside a block initialization */
     int         block_init_level;	/* The level of brace nesting in an
 					 * initialization */
-    int         last_nl;	/* this is true if the last thing scanned was
+    ibool	last_nl;	/* this is true if the last thing scanned was
 				 * a newline */
-    int         in_or_st;	/* Will be true iff there has been a
+    ibool	in_or_st;	/* Will be true iff there has been a
 				 * declarator (e.g. int or char) and no left
 				 * paren since the last semicolon. When true,
 				 * a '{' is starting a structure definition or
 				 * an initialization list */
-    int         bl_line;	/* set to 1 by dump_line if the line is blank */
-    int         col_1;		/* set to true if the last token started in
+    ibool	bl_line;	/* set to 1 by dump_line if the line is blank */
+    ibool	col_1;		/* set to true if the last token started in
 				 * column 1 */
     int         com_col;	/* this is the column in which the current
 				 * comment should start */
     int         dec_nest;	/* current nesting level for structure or init */
-    int         decl_on_line;	/* set to true if this line of code has part
+    ibool	decl_on_line;	/* set to true if this line of code has part
 				 * of a declaration on it */
     int         i_l_follow;	/* the level to which ind_level should be set
 				 * after the current line is printed */
-    int         in_decl;	/* set to true when we are in a declaration
+    ibool	in_decl;	/* set to true when we are in a declaration
 				 * stmt.  The processing of braces is then
 				 * slightly different */
-    int         in_stmt;	/* set to 1 while in a stmt */
+    ibool	in_stmt;	/* set to 1 while in a stmt */
     int         ind_level;	/* the current indentation level */
-    int         ind_stmt;	/* set to 1 if next line should have an extra
+    ibool	ind_stmt;	/* set to 1 if next line should have an extra
 				 * indentation level because we are in the
 				 * middle of a stmt */
-    int         last_u_d;	/* set to true after scanning a token which
+    ibool	last_u_d;	/* set to true after scanning a token which
 				 * forces a following operator to be unary */
-    int         p_l_follow;	/* used to remember how to indent following
-				 * statement */
+    int         p_l_follow;	/* used to remember how to indent the
+				 * following statement */
     int         paren_level;	/* parenthesization level. used to indent
 				 * within statements */
     short       paren_indents[20]; /* indentation of the operand/argument of
 				 * each level of parentheses or brackets,
 				 * relative to the enclosing statement */
-    int         pcase;		/* set to 1 if the current line label is a
+    ibool	pcase;		/* set to 1 if the current line label is a
 				 * case.  It is printed differently from a
 				 * regular label */
-    int         search_brace;	/* set to true by parse when it is necessary
+    ibool	search_brace;	/* set to true by parse when it is necessary
 				 * to buffer up all info up to the start of a
 				 * stmt after an if, while, etc */
-    int         use_ff;		/* set to one if the current line should be
+    ibool	use_ff;		/* set to one if the current line should be
 				 * terminated with a form feed */
-    int         want_blank;	/* set to true when the following token should
+    ibool	want_blank;	/* set to true when the following token should
 				 * be prefixed by a blank. (Said prefixing is
 				 * ignored in some cases.) */
     enum rwcode keyword;	/* the type of a keyword or 0 */
-    int         dumped_decl_indent;
-    int         in_parameter_declaration;
+    ibool	dumped_decl_indent;
+    ibool	in_parameter_declaration;
     int         tos;		/* pointer to top of stack */
     char        procname[100];	/* The name of the current procedure */
     int         just_saw_decl;

Index: src/usr.bin/indent/io.c
diff -u src/usr.bin/indent/io.c:1.59 src/usr.bin/indent/io.c:1.60
--- src/usr.bin/indent/io.c:1.59	Sat Sep 25 13:38:32 2021
+++ src/usr.bin/indent/io.c	Sat Sep 25 17:11:23 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: io.c,v 1.59 2021/09/25 13:38:32 rillig Exp $	*/
+/*	$NetBSD: io.c,v 1.60 2021/09/25 17:11:23 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@ static char sccsid[] = "@(#)io.c	8.1 (Be
 
 #include <sys/cdefs.h>
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: io.c,v 1.59 2021/09/25 13:38:32 rillig Exp $");
+__RCSID("$NetBSD: io.c,v 1.60 2021/09/25 17:11:23 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/io.c 334927 2018-06-10 16:44:18Z pstef $");
 #endif
@@ -57,7 +57,7 @@ __FBSDID("$FreeBSD: head/usr.bin/indent/
 
 #include "indent.h"
 
-int         comment_open;
+ibool comment_open;
 static int  paren_indent;
 
 static void
@@ -112,11 +112,11 @@ void
 dump_line(void)
 {
     int cur_col;
-    static int  not_first_line;
+    static ibool not_first_line;
 
-    if (ps.procname[0]) {
+    if (ps.procname[0] != '\0') {
 	ps.ind_level = 0;
-	ps.procname[0] = 0;
+	ps.procname[0] = '\0';
     }
 
     if (code.s == code.e && lab.s == lab.e && com.s == com.e) {
@@ -142,7 +142,7 @@ dump_line(void)
 	    output_char('\n');
 	n_real_blanklines = 0;
 	if (ps.ind_level == 0)
-	    ps.ind_stmt = 0;	/* this is a class A kludge. dont do
+	    ps.ind_stmt = false;/* this is a class A kludge. don't do
 				 * additional statement indentation if we are
 				 * at bracket level 0 */
 
@@ -152,7 +152,7 @@ dump_line(void)
 
 	if (lab.e != lab.s) {	/* print lab, if any */
 	    if (comment_open) {
-		comment_open = 0;
+		comment_open = false;
 		output_string(".*/\n");
 	    }
 	    while (lab.e > lab.s && (lab.e[-1] == ' ' || lab.e[-1] == '\t'))
@@ -188,7 +188,7 @@ dump_line(void)
 
 	if (code.s != code.e) {	/* print code section, if any */
 	    if (comment_open) {
-		comment_open = 0;
+		comment_open = false;
 		output_string(".*/\n");
 	    }
 	    int target_col = 1 + compute_code_indent();
@@ -248,11 +248,11 @@ dump_line(void)
 	    output_char('\n');
 	ps.stats.lines++;
 	if (ps.just_saw_decl == 1 && opt.blanklines_after_declarations) {
-	    prefix_blankline_requested = 1;
+	    prefix_blankline_requested = true;
 	    ps.just_saw_decl = 0;
 	} else
 	    prefix_blankline_requested = postfix_blankline_requested;
-	postfix_blankline_requested = 0;
+	postfix_blankline_requested = false;
     }
 
     /* keep blank lines after '//' comments */
@@ -263,11 +263,17 @@ dump_line(void)
     ps.decl_on_line = ps.in_decl; /* if we are in the middle of a declaration,
 				 * remember that fact for proper comment
 				 * indentation */
+#ifdef lint
+    ps.ind_stmt = ps.in_stmt && !ps.in_decl; /* next line should be indented if
+				 * we have not completed this stmt and if we
+				 * are not in the middle of a declaration */
+#else
     ps.ind_stmt = ps.in_stmt & ~ps.in_decl; /* next line should be indented if
 				 * we have not completed this stmt and if we
 				 * are not in the middle of a declaration */
+#endif
     ps.use_ff = false;
-    ps.dumped_decl_indent = 0;
+    ps.dumped_decl_indent = false;
     *(lab.e = lab.s) = '\0';	/* reset buffers */
     *(code.e = code.s) = '\0';
     *(com.e = com.s = com.buf + 1) = '\0';
@@ -278,7 +284,7 @@ dump_line(void)
 	paren_indent = -ps.paren_indents[ps.paren_level - 1];
 	debug_println("paren_indent is now %d", paren_indent);
     }
-    not_first_line = 1;
+    not_first_line = true;
 }
 
 int
@@ -374,10 +380,14 @@ parse_indent_comment(void)
     if (com.s != com.e || lab.s != lab.e || code.s != code.e)
 	dump_line();
 
+#ifdef lint
+    if (!(inhibit_formatting = (on_off - 1) != 0)) {
+#else
     if (!(inhibit_formatting = on_off - 1)) {
+#endif
 	n_real_blanklines = 0;
-	postfix_blankline_requested = 0;
-	prefix_blankline_requested = 0;
+	postfix_blankline_requested = false;
+	prefix_blankline_requested = false;
 	suppress_blanklines = 1;
     }
 }
@@ -468,7 +478,7 @@ diag(int level, const char *msg, ...)
     va_list ap;
     const char *s, *e;
 
-    if (level)
+    if (level != 0)
 	found_err = 1;
 
     if (output == stdout) {

Index: src/usr.bin/indent/lexi.c
diff -u src/usr.bin/indent/lexi.c:1.53 src/usr.bin/indent/lexi.c:1.54
--- src/usr.bin/indent/lexi.c:1.53	Sat Sep 25 13:38:32 2021
+++ src/usr.bin/indent/lexi.c	Sat Sep 25 17:11:23 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: lexi.c,v 1.53 2021/09/25 13:38:32 rillig Exp $	*/
+/*	$NetBSD: lexi.c,v 1.54 2021/09/25 17:11:23 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.53 2021/09/25 13:38:32 rillig Exp $");
+__RCSID("$NetBSD: lexi.c,v 1.54 2021/09/25 17:11:23 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/lexi.c 337862 2018-08-15 18:19:45Z pstef $");
 #endif
@@ -336,7 +336,7 @@ lex_char_or_string(void)
 token_type
 lexi(struct parser_state *state)
 {
-    int         unary_delim;	/* this is set to 1 if the current token
+    ibool unary_delim;		/* whether the current token
 				 * forces a following operator to be unary */
     token_type  ttype;
 
@@ -378,7 +378,7 @@ lexi(struct parser_state *state)
 	    inbuf_next();
 	state->keyword = rw_0;
 	if (state->last_token == keyword_struct_union_enum &&
-	    !state->p_l_follow) {
+	    state->p_l_follow == 0) {
 	    /* if last token was 'struct' and we're not in parentheses, then
 	     * this token should be treated as a declaration */
 	    state->last_u_d = true;
@@ -398,7 +398,7 @@ lexi(struct parser_state *state)
 	    if ((opt.auto_typedefs && ((u = strrchr(token.s, '_')) != NULL) &&
 	        strcmp(u, "_t") == 0) || (typename_top >= 0 &&
 		  bsearch(token.s, typenames, (size_t)typename_top + 1,
-		    sizeof typenames[0], compare_string_array))) {
+		    sizeof typenames[0], compare_string_array) != NULL)) {
 		state->keyword = rw_type;
 		state->last_u_d = true;
 	        goto found_typename;
@@ -414,7 +414,7 @@ lexi(struct parser_state *state)
 	    case rw_struct_or_union_or_enum:
 	    case rw_type:
 	    found_typename:
-		if (state->p_l_follow) {
+		if (state->p_l_follow != 0) {
 		    /* inside parens: cast, param list, offsetof or sizeof */
 		    state->cast_mask |= (1 << state->p_l_follow) & ~state->not_cast_mask;
 		}
@@ -424,7 +424,7 @@ lexi(struct parser_state *state)
 		}
 		if (p != NULL && p->rwcode == rw_struct_or_union_or_enum)
 		    return lexi_end(keyword_struct_union_enum);
-		if (state->p_l_follow)
+		if (state->p_l_follow != 0)
 		    break;
 		return lexi_end(decl);
 
@@ -446,14 +446,14 @@ lexi(struct parser_state *state)
 	    }			/* end of switch */
 	}			/* end of if (found_it) */
 	if (*buf_ptr == '(' && state->tos <= 1 && state->ind_level == 0 &&
-	    state->in_parameter_declaration == 0 && state->block_init == 0) {
+	    !state->in_parameter_declaration && !state->block_init) {
 	    char *tp = buf_ptr;
 	    while (tp < buf_end)
 		if (*tp++ == ')' && (*tp == ';' || *tp == ','))
 		    goto not_proc;
 	    strncpy(state->procname, token.s, sizeof state->procname - 1);
 	    if (state->in_decl)
-		state->in_parameter_declaration = 1;
+		state->in_parameter_declaration = true;
 	    return lexi_end(funcname);
     not_proc:;
 	}
@@ -462,7 +462,7 @@ lexi(struct parser_state *state)
 	 * token is in fact a declaration keyword -- one that has been
 	 * typedefd
 	 */
-	else if (!state->p_l_follow && !state->block_init &&
+	else if (state->p_l_follow == 0 && !state->block_init &&
 	    !state->in_stmt &&
 	    ((*buf_ptr == '*' && buf_ptr[1] != '=') ||
 		isalpha((unsigned char)*buf_ptr)) &&
@@ -586,7 +586,7 @@ lexi(struct parser_state *state)
 
     case '=':
 	if (state->in_or_st)
-	    state->block_init = 1;
+	    state->block_init = true;
 	if (*buf_ptr == '=') {	/* == */
 	    *token.e++ = '=';	/* Flip =+ to += */
 	    buf_ptr++;

Index: src/usr.bin/indent/parse.c
diff -u src/usr.bin/indent/parse.c:1.23 src/usr.bin/indent/parse.c:1.24
--- src/usr.bin/indent/parse.c:1.23	Sat Sep 25 13:38:32 2021
+++ src/usr.bin/indent/parse.c	Sat Sep 25 17:11:23 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: parse.c,v 1.23 2021/09/25 13:38:32 rillig Exp $	*/
+/*	$NetBSD: parse.c,v 1.24 2021/09/25 17:11:23 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -234,7 +234,7 @@ parse(token_type ttype)
  * Try to combine the statement on the top of the parse stack with the symbol
  * directly below it, replacing these two symbols with a single symbol.
  */
-static int
+static ibool
 reduce_stmt(void)
 {
     switch (ps.p_stack[ps.tos - 1]) {

Index: src/usr.bin/indent/pr_comment.c
diff -u src/usr.bin/indent/pr_comment.c:1.42 src/usr.bin/indent/pr_comment.c:1.43
--- src/usr.bin/indent/pr_comment.c:1.42	Sat Sep 25 13:38:32 2021
+++ src/usr.bin/indent/pr_comment.c	Sat Sep 25 17:11:23 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: pr_comment.c,v 1.42 2021/09/25 13:38:32 rillig Exp $	*/
+/*	$NetBSD: pr_comment.c,v 1.43 2021/09/25 17:11:23 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.42 2021/09/25 13:38:32 rillig Exp $");
+__RCSID("$NetBSD: pr_comment.c,v 1.43 2021/09/25 17:11:23 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/pr_comment.c 334927 2018-06-10 16:44:18Z pstef $");
 #endif
@@ -94,7 +94,7 @@ process_comment(void)
 				 * that spill over the right margin */
     ssize_t last_blank;		/* index of the last blank in com.buf */
     char       *t_ptr;		/* used for moving string */
-    int         break_delim = opt.comment_delimiter_on_blankline;
+    ibool break_delim = opt.comment_delimiter_on_blankline;
     int         l_just_saw_decl = ps.just_saw_decl;
 
     adj_max_line_length = opt.max_line_length;
@@ -133,7 +133,7 @@ process_comment(void)
 	    ps.com_col = (ps.ind_level - opt.unindent_displace) * opt.indent_size + 1;
 	    adj_max_line_length = opt.block_comment_max_line_length;
 	    if (ps.com_col <= 1)
-		ps.com_col = 1 + !opt.format_col1_comments;
+		ps.com_col = 1 + (!opt.format_col1_comments ? 1 : 0);
 	} else {
 	    break_delim = false;
 
@@ -209,7 +209,7 @@ process_comment(void)
 	com.e = com.s + 2;
 	*com.e = 0;
 	if (opt.blanklines_before_blockcomments && ps.last_token != lbrace)
-	    prefix_blankline_requested = 1;
+	    prefix_blankline_requested = true;
 	dump_line();
 	com.e = com.s = t;
 	if (!ps.box_com && opt.star_comment_cont)
@@ -264,7 +264,7 @@ process_comment(void)
 		if (!ps.box_com && opt.star_comment_cont)
 		    *com.e++ = ' ', *com.e++ = '*', *com.e++ = ' ';
 	    } else {
-		ps.last_nl = 1;
+		ps.last_nl = true;
 		if (!(com.e[-1] == ' ' || com.e[-1] == '\t'))
 		    *com.e++ = ' ';
 		last_blank = com.e - 1 - com.buf;
@@ -326,7 +326,7 @@ process_comment(void)
 		    last_blank = com.e - com.buf; /* remember we saw a blank */
 		++com.e;
 		now_len++;
-	    } while (!memchr("*\n\r\b\t", *buf_ptr, 6) &&
+	    } while (memchr("*\n\r\b\t", *buf_ptr, 6) == NULL &&
 		(now_len < adj_max_line_length || last_blank == -1));
 	    ps.last_nl = false;
 	    /* XXX: signed character comparison '>' does not work for UTF-8 */

Reply via email to