Fri Mar 12 23:10:18 2021 UTC ()
indent: use consistent indentation for 'else'

Half of the code used -ce, the other half the opposite -nce.

No functional change.


(rillig)
diff -r1.18 -r1.19 src/usr.bin/indent/args.c
diff -r1.18 -r1.19 src/usr.bin/indent/pr_comment.c
diff -r1.44 -r1.45 src/usr.bin/indent/indent.c
diff -r1.29 -r1.30 src/usr.bin/indent/io.c
diff -r1.37 -r1.38 src/usr.bin/indent/lexi.c
diff -r1.17 -r1.18 src/usr.bin/indent/parse.c

cvs diff -r1.18 -r1.19 src/usr.bin/indent/args.c (expand / switch to context diff)
--- src/usr.bin/indent/args.c 2021/03/09 16:48:28 1.18
+++ src/usr.bin/indent/args.c 2021/03/12 23:10:18 1.19
@@ -1,4 +1,4 @@
-/*	$NetBSD: args.c,v 1.18 2021/03/09 16:48:28 rillig Exp $	*/
+/*	$NetBSD: args.c,v 1.19 2021/03/12 23:10:18 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -46,7 +46,7 @@
 #include <sys/cdefs.h>
 #ifndef lint
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: args.c,v 1.18 2021/03/09 16:48:28 rillig Exp $");
+__RCSID("$NetBSD: args.c,v 1.19 2021/03/12 23:10:18 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/args.c 336318 2018-07-15 21:04:21Z pstef $");
 #endif
@@ -234,8 +234,7 @@
 	    if (opt.verbose)
 		printf("profile: %s\n", buf);
 	    set_option(buf);
-	}
-	else if (i == EOF)
+	} else if (i == EOF)
 	    return;
     }
 }

cvs diff -r1.18 -r1.19 src/usr.bin/indent/pr_comment.c (expand / switch to context diff)
--- src/usr.bin/indent/pr_comment.c 2021/03/11 22:32:06 1.18
+++ src/usr.bin/indent/pr_comment.c 2021/03/12 23:10:18 1.19
@@ -1,4 +1,4 @@
-/*	$NetBSD: pr_comment.c,v 1.18 2021/03/11 22:32:06 rillig Exp $	*/
+/*	$NetBSD: pr_comment.c,v 1.19 2021/03/12 23:10:18 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -46,7 +46,7 @@
 #include <sys/cdefs.h>
 #ifndef lint
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: pr_comment.c,v 1.18 2021/03/11 22:32:06 rillig Exp $");
+__RCSID("$NetBSD: pr_comment.c,v 1.19 2021/03/12 23:10:18 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/pr_comment.c 334927 2018-06-10 16:44:18Z pstef $");
 #endif
@@ -136,8 +136,7 @@
 	ps.box_com = true;
 	break_delim = false;
 	ps.com_col = 1;
-    }
-    else {
+    } else {
 	if (*buf_ptr == '-' || *buf_ptr == '*' || e_token[-1] == '/' ||
 	    (*buf_ptr == '\n' && !opt.format_block_comments)) {
 	    ps.box_com = true;	/* A comment with a '-' or '*' immediately
@@ -159,8 +158,7 @@
 	    adj_max_col = opt.block_comment_max_col;
 	    if (ps.com_col <= 1)
 		ps.com_col = 1 + !opt.format_col1_comments;
-	}
-	else {
+	} else {
 	    int target_col;
 	    break_delim = false;
 	    if (s_code != e_code)
@@ -191,8 +189,7 @@
 	start = buf_ptr >= save_com && buf_ptr < save_com + sc_size ?
 	    sc_buf : in_buffer;
 	ps.n_comment_delta = 1 - count_spaces_until(1, start, buf_ptr - 2);
-    }
-    else {
+    } else {
 	ps.n_comment_delta = 0;
 	while (*buf_ptr == ' ' || *buf_ptr == '\t')
 	    buf_ptr++;
@@ -245,8 +242,7 @@
 		    *e_com++ = ' ', *e_com++ = '*', *e_com++ = ' ';
 		while (*++buf_ptr == ' ' || *buf_ptr == '\t')
 		    ;
-	    }
-	    else {
+	    } else {
 		if (++buf_ptr >= buf_end)
 		    fill_buffer();
 		*e_com++ = 014;
@@ -277,8 +273,7 @@
 		dump_line();
 		if (!ps.box_com && opt.star_comment_cont)
 		    *e_com++ = ' ', *e_com++ = '*', *e_com++ = ' ';
-	    }
-	    else {
+	    } else {
 		ps.last_nl = 1;
 		if (e_com[-1] == ' ' || e_com[-1] == '\t')
 		    last_bl = e_com - 1;
@@ -305,8 +300,7 @@
 			    goto end_of_comment;
 		    }
 		} while (*buf_ptr == ' ' || *buf_ptr == '\t');
-	    }
-	    else if (++buf_ptr >= buf_end)
+	    } else if (++buf_ptr >= buf_end)
 		fill_buffer();
 	    break;		/* end of case for newline */
 
@@ -320,9 +314,8 @@
 		if (++buf_ptr >= buf_end)
 		    fill_buffer();
 		if (break_delim) {
-		    if (e_com > s_com + 3) {
+		    if (e_com > s_com + 3)
 			dump_line();
-		    }
 		    else
 			s_com = e_com;
 		    *e_com++ = ' ';
@@ -335,8 +328,7 @@
 		    *e_com++ = '*', *e_com++ = '/', *e_com = '\0';
 		ps.just_saw_decl = l_just_saw_decl;
 		return;
-	    }
-	    else		/* handle isolated '*' */
+	    } else		/* handle isolated '*' */
 		*e_com++ = '*';
 	    break;
 	default:		/* we have a random char */

cvs diff -r1.44 -r1.45 src/usr.bin/indent/indent.c (expand / switch to context diff)
--- src/usr.bin/indent/indent.c 2021/03/12 00:15:34 1.44
+++ src/usr.bin/indent/indent.c 2021/03/12 23:10:18 1.45
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.44 2021/03/12 00:15:34 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.45 2021/03/12 23:10:18 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -46,7 +46,7 @@
 #include <sys/cdefs.h>
 #ifndef lint
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: indent.c,v 1.44 2021/03/12 00:15:34 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.45 2021/03/12 23:10:18 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -507,8 +507,7 @@
 		if (input == NULL)	/* check for open error */
 			err(1, "%s", in_name);
 		continue;
-	    }
-	    else if (output == NULL) {	/* we have the output file */
+	    } else if (output == NULL) {	/* we have the output file */
 		out_name = argv[i];	/* remember name of output file */
 		if (strcmp(in_name, out_name) == 0) {	/* attempt to overwrite
 							 * the file */
@@ -520,8 +519,7 @@
 		continue;
 	    }
 	    errx(1, "unknown parameter: %s", argv[i]);
-	}
-	else
+	} else
 	    set_option(argv[i]);
     }				/* end of for */
     if (input == NULL)
@@ -636,8 +634,7 @@
 		ps.want_blank = false;
 		e_com = s_com;
 	    }
-	}
-	else if (type_code != comment)	/* preserve force_nl thru a comment */
+	} else if (type_code != comment) /* preserve force_nl thru a comment */
 	    force_nl = false;	/* cancel forced newline after newline, form
 				 * feed, etc */
 
@@ -681,8 +678,7 @@
 		/* function pointer declarations */
 		indent_declaration(dec_ind, tabs_to_var);
 		ps.dumped_decl_indent = true;
-	    }
-	    else if (ps.want_blank &&
+	    } else if (ps.want_blank &&
 		    ((ps.last_token != ident && ps.last_token != funcname) ||
 		    opt.proc_calls_space ||
 		    (ps.keyword == rw_sizeof ? opt.Bill_Shannon :
@@ -756,8 +752,7 @@
 		    /* find length of token */;
 		indent_declaration(dec_ind - i, tabs_to_var);
 		ps.dumped_decl_indent = true;
-	    }
-	    else if (ps.want_blank)
+	    } else if (ps.want_blank)
 		*e_code++ = ' ';
 
 	    {
@@ -906,8 +901,7 @@
 		if (!opt.btype_2) {
 		    dump_line();
 		    ps.want_blank = false;
-		}
-		else if (ps.in_parameter_declaration && !ps.in_or_st) {
+		} else if (ps.in_parameter_declaration && !ps.in_or_st) {
 		    ps.i_l_follow = 0;
 		    if (opt.function_brace_split) { /* dump the line prior
 				 * to the brace ... */
@@ -942,8 +936,7 @@
 		    ps.dec_nest--;
 		}
 		/* ?		dec_ind = 0; */
-	    }
-	    else {
+	    } else {
 		ps.decl_on_line = false;	/* we can't be in the middle of
 						 * a declaration, so don't do
 						 * special indentation of
@@ -1030,8 +1023,7 @@
 		force_nl = true;/* also, following stuff must go onto new line */
 		last_else = 1;
 		parse(keyword_else);
-	    }
-	    else {
+	    } else {
 		if (e_code != s_code) {	/* make sure this starts a line */
 		    if (opt.verbose)
 			diag(0, "Line broken");
@@ -1092,21 +1084,18 @@
 		    if (opt.procnames_start_line && s_code != e_code) {
 			*e_code = '\0';
 			dump_line();
-		    }
-		    else if (ps.want_blank) {
+		    } else if (ps.want_blank) {
 			*e_code++ = ' ';
 		    }
 		    ps.want_blank = false;
-		}
-		else if (!ps.block_init && !ps.dumped_decl_indent &&
+		} else if (!ps.block_init && !ps.dumped_decl_indent &&
 		    ps.paren_level == 0) { /* if we are in a declaration, we
 					    * must indent identifier */
 		    indent_declaration(dec_ind, tabs_to_var);
 		    ps.dumped_decl_indent = true;
 		    ps.want_blank = false;
 		}
-	    }
-	    else if (sp_sw && ps.p_l_follow == 0) {
+	    } else if (sp_sw && ps.p_l_follow == 0) {
 		sp_sw = false;
 		force_nl = true;
 		ps.last_u_d = true;
@@ -1231,8 +1220,7 @@
 						 * we must set up the buffer */
 			save_com = sc_buf;
 			sc_end = &save_com[0];
-		    }
-		    else {
+		    } else {
 			*sc_end++ = '\n';	/* add newline between
 						 * comments */
 			*sc_end++ = ' ';
@@ -1263,19 +1251,16 @@
 		if ((size_t)ifdef_level < nitems(state_stack)) {
 		    match_state[ifdef_level].tos = -1;
 		    state_stack[ifdef_level++] = ps;
-		}
-		else
+		} else
 		    diag(1, "#if stack overflow");
-	    }
-	    else if (strncmp(s_lab, "#el", 3) == 0) { /* else, elif */
+	    } else if (strncmp(s_lab, "#el", 3) == 0) { /* else, elif */
 		if (ifdef_level <= 0)
 		    diag(1, s_lab[3] == 'i' ? "Unmatched #elif" : "Unmatched #else");
 		else {
 		    match_state[ifdef_level - 1] = ps;
 		    ps = state_stack[ifdef_level - 1];
 		}
-	    }
-	    else if (strncmp(s_lab, "#endif", 6) == 0) {
+	    } else if (strncmp(s_lab, "#endif", 6) == 0) {
 		if (ifdef_level <= 0)
 		    diag(1, "Unmatched #endif");
 		else
@@ -1304,8 +1289,7 @@
 	    if (opt.blanklines_around_conditional_compilation) {
 		postfix_blankline_requested++;
 		n_real_blanklines = 0;
-	    }
-	    else {
+	    } else {
 		postfix_blankline_requested = 0;
 		prefix_blankline_requested = 0;
 	    }

cvs diff -r1.29 -r1.30 src/usr.bin/indent/io.c (expand / switch to context diff)
--- src/usr.bin/indent/io.c 2021/03/12 19:14:18 1.29
+++ src/usr.bin/indent/io.c 2021/03/12 23:10:18 1.30
@@ -1,4 +1,4 @@
-/*	$NetBSD: io.c,v 1.29 2021/03/12 19:14:18 rillig Exp $	*/
+/*	$NetBSD: io.c,v 1.30 2021/03/12 23:10:18 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -46,7 +46,7 @@
 #include <sys/cdefs.h>
 #ifndef lint
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: io.c,v 1.29 2021/03/12 19:14:18 rillig Exp $");
+__RCSID("$NetBSD: io.c,v 1.30 2021/03/12 23:10:18 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/io.c 334927 2018-06-10 16:44:18Z pstef $");
 #endif
@@ -104,6 +104,7 @@
 	ps.ind_level = 0;
 	ps.procname[0] = 0;
     }
+
     if (s_code == e_code && s_lab == e_lab && s_com == e_com) {
 	if (suppress_blanklines > 0)
 	    suppress_blanklines--;
@@ -111,16 +112,14 @@
 	    ps.bl_line = true;
 	    n_real_blanklines++;
 	}
-    }
-    else if (!inhibit_formatting) {
+    } else if (!inhibit_formatting) {
 	suppress_blanklines = 0;
 	ps.bl_line = false;
 	if (prefix_blankline_requested && not_first_line) {
 	    if (opt.swallow_optional_blanklines) {
 		if (n_real_blanklines == 1)
 		    n_real_blanklines = 0;
-	    }
-	    else {
+	    } else {
 		if (n_real_blanklines == 0)
 		    n_real_blanklines = 1;
 	    }
@@ -168,8 +167,7 @@
 	    } else
 	        output_range(s_lab, e_lab);
 	    cur_col = count_spaces(cur_col, s_lab);
-	}
-	else
+	} else
 	    cur_col = 1;	/* there is no label section */
 
 	ps.pcase = false;
@@ -211,8 +209,7 @@
 		else if (*com_st == '\t') {
 		    target = opt.tabsize * (1 + (target - 1) / opt.tabsize) + 1;
 		    com_st++;
-		}
-		else
+		} else
 		    target = 1;
 	    if (cur_col > target) {	/* if comment can't fit on this line,
 				     * put it on next line */
@@ -235,8 +232,7 @@
 	if (ps.just_saw_decl == 1 && opt.blanklines_after_declarations) {
 	    prefix_blankline_requested = 1;
 	    ps.just_saw_decl = 0;
-	}
-	else
+	} else
 	    prefix_blankline_requested = postfix_blankline_requested;
 	postfix_blankline_requested = 0;
     }
@@ -270,7 +266,7 @@
 {
     int target_col = opt.ind_size * ps.ind_level + 1;
 
-    if (ps.paren_level)
+    if (ps.paren_level) {
 	if (!opt.lineup_to_parens)
 	    target_col += opt.continuation_indent *
 		(2 * opt.continuation_indent == opt.ind_size ? 1 : ps.paren_level);
@@ -285,11 +281,10 @@
 		t -= w + 1;
 		if (t > target_col)
 		    target_col = t;
-	    }
-	    else
+	    } else
 		target_col = t;
 	}
-    else if (ps.ind_stmt)
+    } else if (ps.ind_stmt)
 	target_col += opt.continuation_indent;
     return target_col;
 }

cvs diff -r1.37 -r1.38 src/usr.bin/indent/lexi.c (expand / switch to context diff)
--- src/usr.bin/indent/lexi.c 2021/03/12 18:11:50 1.37
+++ src/usr.bin/indent/lexi.c 2021/03/12 23:10:18 1.38
@@ -1,4 +1,4 @@
-/*	$NetBSD: lexi.c,v 1.37 2021/03/12 18:11:50 rillig Exp $	*/
+/*	$NetBSD: lexi.c,v 1.38 2021/03/12 23:10:18 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -46,7 +46,7 @@
 #include <sys/cdefs.h>
 #ifndef lint
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: lexi.c,v 1.37 2021/03/12 18:11:50 rillig Exp $");
+__RCSID("$NetBSD: lexi.c,v 1.38 2021/03/12 23:10:18 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/lexi.c 337862 2018-08-15 18:19:45Z pstef $");
 #endif
@@ -341,11 +341,10 @@
 		*e_token++ = inbuf_next();
 	    }
 	    /* s now indicates the type: f(loating), i(integer), u(nknown) */
-	}
-	else
+	} else {
 	    while (isalnum((unsigned char)*buf_ptr) ||
-	        *buf_ptr == '\\' ||
-		*buf_ptr == '_' || *buf_ptr == '$') {
+		   *buf_ptr == '\\' ||
+		   *buf_ptr == '_' || *buf_ptr == '$') {
 		/* fill_buffer() terminates buffer with newline */
 		if (*buf_ptr == '\\') {
 		    if (buf_ptr[1] == '\n') {
@@ -358,6 +357,7 @@
 		check_size_token(1);
 		*e_token++ = inbuf_next();
 	    }
+	}
 	*e_token = '\0';
 
 	if (s_token[0] == 'L' && s_token[1] == '\0' &&
@@ -504,8 +504,7 @@
 		    *++e_token = inbuf_next();
 		    ++e_token;	/* we must increment this again because we
 				 * copied two chars */
-		}
-		else
+		} else
 		    break;	/* we copied one character */
 	    }			/* end of while (1) */
 	} while (*e_token++ != qchar);
@@ -591,8 +590,7 @@
 		/* check for following ++ or -- */
 		unary_delim = false;
 	    }
-	}
-	else if (*buf_ptr == '=')
+	} else if (*buf_ptr == '=')
 	    /* check for operator += */
 	    *e_token++ = *buf_ptr++;
 	else if (*buf_ptr == '>') {
@@ -715,8 +713,7 @@
 	if (comparison == 0)	/* remove duplicates */
 	    return;
 	typenames[++typename_top] = copy = strdup(key);
-    }
-    else {
+    } else {
 	int p;
 
 	for (p = 0; (comparison = strcmp(key, typenames[p])) > 0; p++)

cvs diff -r1.17 -r1.18 src/usr.bin/indent/parse.c (expand / switch to context diff)
--- src/usr.bin/indent/parse.c 2021/03/09 19:14:39 1.17
+++ src/usr.bin/indent/parse.c 2021/03/12 23:10:18 1.18
@@ -1,4 +1,4 @@
-/*	$NetBSD: parse.c,v 1.17 2021/03/09 19:14:39 rillig Exp $	*/
+/*	$NetBSD: parse.c,v 1.18 2021/03/12 23:10:18 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -156,8 +156,7 @@
 	    ps.ind_level = ps.i_l_follow = ps.il[ps.tos];
 	    ps.p_stack[++ps.tos] = while_expr;
 	    ps.il[ps.tos] = ps.ind_level = ps.i_l_follow;
-	}
-	else {			/* it is a while loop */
+	} else {		/* it is a while loop */
 	    ps.p_stack[++ps.tos] = while_expr;
 	    ps.il[ps.tos] = ps.i_l_follow;
 	    ++ps.i_l_follow;
@@ -185,8 +184,7 @@
 	if (ps.tos > 0 && ps.p_stack[ps.tos - 1] == lbrace) {
 	    ps.ind_level = ps.i_l_follow = ps.il[--ps.tos];
 	    ps.p_stack[ps.tos] = stmt;
-	}
-	else
+	} else
 	    diag(1, "Statement nesting error");
 	break;