Sun Nov 7 14:00:35 2021 UTC ()
indent: reduce negations in process_else, clean up comments

No functional change.


(rillig)
diff -r1.213 -r1.214 src/usr.bin/indent/indent.c
diff -r1.83 -r1.84 src/usr.bin/indent/indent.h

cvs diff -r1.213 -r1.214 src/usr.bin/indent/indent.c (expand / switch to unified diff)

--- src/usr.bin/indent/indent.c 2021/11/07 13:30:15 1.213
+++ src/usr.bin/indent/indent.c 2021/11/07 14:00:35 1.214
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: indent.c,v 1.213 2021/11/07 13:30:15 rillig Exp $ */ 1/* $NetBSD: indent.c,v 1.214 2021/11/07 14:00:35 rillig Exp $ */
2 2
3/*- 3/*-
4 * SPDX-License-Identifier: BSD-4-Clause 4 * SPDX-License-Identifier: BSD-4-Clause
5 * 5 *
6 * Copyright (c) 1985 Sun Microsystems, Inc. 6 * Copyright (c) 1985 Sun Microsystems, Inc.
7 * Copyright (c) 1976 Board of Trustees of the University of Illinois. 7 * Copyright (c) 1976 Board of Trustees of the University of Illinois.
8 * Copyright (c) 1980, 1993 8 * Copyright (c) 1980, 1993
9 * The Regents of the University of California. All rights reserved. 9 * The Regents of the University of California. All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions 12 * modification, are permitted provided that the following conditions
13 * are met: 13 * are met:
14 * 1. Redistributions of source code must retain the above copyright 14 * 1. Redistributions of source code must retain the above copyright
@@ -33,27 +33,27 @@ @@ -33,27 +33,27 @@
33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 * SUCH DAMAGE. 37 * SUCH DAMAGE.
38 */ 38 */
39 39
40#if 0 40#if 0
41static char sccsid[] = "@(#)indent.c 5.17 (Berkeley) 6/7/93"; 41static char sccsid[] = "@(#)indent.c 5.17 (Berkeley) 6/7/93";
42#endif 42#endif
43 43
44#include <sys/cdefs.h> 44#include <sys/cdefs.h>
45#if defined(__NetBSD__) 45#if defined(__NetBSD__)
46__RCSID("$NetBSD: indent.c,v 1.213 2021/11/07 13:30:15 rillig Exp $"); 46__RCSID("$NetBSD: indent.c,v 1.214 2021/11/07 14:00:35 rillig Exp $");
47#elif defined(__FreeBSD__) 47#elif defined(__FreeBSD__)
48__FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $"); 48__FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
49#endif 49#endif
50 50
51#include <sys/param.h> 51#include <sys/param.h>
52#if HAVE_CAPSICUM 52#if HAVE_CAPSICUM
53#include <sys/capsicum.h> 53#include <sys/capsicum.h>
54#include <capsicum_helpers.h> 54#include <capsicum_helpers.h>
55#endif 55#endif
56#include <assert.h> 56#include <assert.h>
57#include <ctype.h> 57#include <ctype.h>
58#include <err.h> 58#include <err.h>
59#include <errno.h> 59#include <errno.h>
@@ -474,27 +474,27 @@ search_stmt(lexer_symbol *lsym, bool *fo @@ -474,27 +474,27 @@ search_stmt(lexer_symbol *lsym, bool *fo
474 case lsym_newline: 474 case lsym_newline:
475 search_stmt_newline(force_nl); 475 search_stmt_newline(force_nl);
476 break; 476 break;
477 case lsym_form_feed: 477 case lsym_form_feed:
478 break; 478 break;
479 case lsym_comment: 479 case lsym_comment:
480 search_stmt_comment(); 480 search_stmt_comment();
481 comment_buffered = true; 481 comment_buffered = true;
482 break; 482 break;
483 case lsym_lbrace: 483 case lsym_lbrace:
484 if (search_stmt_lbrace()) 484 if (search_stmt_lbrace())
485 goto switch_buffer; 485 goto switch_buffer;
486 /* FALLTHROUGH */ 486 /* FALLTHROUGH */
487 default: /* it is the start of a normal statement */ 487 default:
488 if (!search_stmt_other(*lsym, force_nl, comment_buffered, 488 if (!search_stmt_other(*lsym, force_nl, comment_buffered,
489 *last_else)) 489 *last_else))
490 return; 490 return;
491 switch_buffer: 491 switch_buffer:
492 switch_buffer(); 492 switch_buffer();
493 } 493 }
494 search_stmt_lookahead(lsym); 494 search_stmt_lookahead(lsym);
495 } 495 }
496 496
497 *last_else = false; 497 *last_else = false;
498} 498}
499 499
500static void 500static void
@@ -1095,27 +1095,27 @@ process_do(bool *force_nl, bool *last_el @@ -1095,27 +1095,27 @@ process_do(bool *force_nl, bool *last_el
1095 ps.want_blank = false; 1095 ps.want_blank = false;
1096 } 1096 }
1097 1097
1098 *force_nl = true; /* following stuff must go onto new line */ 1098 *force_nl = true; /* following stuff must go onto new line */
1099 *last_else = false; 1099 *last_else = false;
1100 parse(psym_do); 1100 parse(psym_do);
1101} 1101}
1102 1102
1103static void 1103static void
1104process_else(bool *force_nl, bool *last_else) 1104process_else(bool *force_nl, bool *last_else)
1105{ 1105{
1106 ps.in_stmt = false; 1106 ps.in_stmt = false;
1107 1107
1108 if (code.e > code.s && (!opt.cuddle_else || code.e[-1] != '}')) { 1108 if (code.e > code.s && !(opt.cuddle_else && code.e[-1] == '}')) {
1109 if (opt.verbose) 1109 if (opt.verbose)
1110 diag(0, "Line broken"); 1110 diag(0, "Line broken");
1111 dump_line(); /* make sure this starts a line */ 1111 dump_line(); /* make sure this starts a line */
1112 ps.want_blank = false; 1112 ps.want_blank = false;
1113 } 1113 }
1114 1114
1115 *force_nl = true; /* following stuff must go onto new line */ 1115 *force_nl = true; /* following stuff must go onto new line */
1116 *last_else = true; 1116 *last_else = true;
1117 parse(psym_else); 1117 parse(psym_else);
1118} 1118}
1119 1119
1120static void 1120static void
1121process_type(int *decl_ind, bool *tabs_to_var) 1121process_type(int *decl_ind, bool *tabs_to_var)

cvs diff -r1.83 -r1.84 src/usr.bin/indent/indent.h (expand / switch to unified diff)

--- src/usr.bin/indent/indent.h 2021/11/07 13:43:11 1.83
+++ src/usr.bin/indent/indent.h 2021/11/07 14:00:35 1.84
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: indent.h,v 1.83 2021/11/07 13:43:11 rillig Exp $ */ 1/* $NetBSD: indent.h,v 1.84 2021/11/07 14:00:35 rillig Exp $ */
2 2
3/*- 3/*-
4 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 4 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
5 * 5 *
6 * Copyright (c) 2001 Jens Schweikhardt 6 * Copyright (c) 2001 Jens Schweikhardt
7 * All rights reserved. 7 * All rights reserved.
8 * 8 *
9 * Redistribution and use in source and binary forms, with or without 9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 10 * modification, are permitted provided that the following conditions
11 * are met: 11 * are met:
12 * 1. Redistributions of source code must retain the above copyright 12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer. 13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright 14 * 2. Redistributions in binary form must reproduce the above copyright
@@ -253,27 +253,28 @@ extern int blank_lines_to_output; @@ -253,27 +253,28 @@ extern int blank_lines_to_output;
253extern bool blank_line_before; 253extern bool blank_line_before;
254extern bool blank_line_after; 254extern bool blank_line_after;
255extern bool break_comma; /* when true and not in parentheses, break 255extern bool break_comma; /* when true and not in parentheses, break
256 * after a comma */ 256 * after a comma */
257extern float case_ind; /* indentation level to be used for a "case 257extern float case_ind; /* indentation level to be used for a "case
258 * n:" */ 258 * n:" */
259extern bool had_eof; /* whether input is exhausted */ 259extern bool had_eof; /* whether input is exhausted */
260extern int line_no; /* the current line number. */ 260extern int line_no; /* the current line number. */
261extern bool inhibit_formatting; /* true if INDENT OFF is in effect */ 261extern bool inhibit_formatting; /* true if INDENT OFF is in effect */
262 262
263#define STACKSIZE 256 263#define STACKSIZE 256
264 264
265extern struct parser_state { 265extern struct parser_state {
266 lexer_symbol prev_token; 266 lexer_symbol prev_token; /* the previous token, but never comment,
 267 * newline or preprocessing line */
267 bool curr_col_1; /* whether the current token started in column 268 bool curr_col_1; /* whether the current token started in column
268 * 1 of the unformatted input */ 269 * 1 of the unformatted input */
269 bool next_col_1; 270 bool next_col_1;
270 bool next_unary; /* whether the following operator should be 271 bool next_unary; /* whether the following operator should be
271 * unary */ 272 * unary */
272 273
273 char procname[100]; /* The name of the current procedure */ 274 char procname[100]; /* The name of the current procedure */
274 275
275 276
276 bool want_blank; /* whether the following token should be 277 bool want_blank; /* whether the following token should be
277 * prefixed by a blank. (Said prefixing is 278 * prefixed by a blank. (Said prefixing is
278 * ignored in some cases.) */ 279 * ignored in some cases.) */
279 280