Module Name:    src
Committed By:   rillig
Date:           Thu Oct  7 21:43:20 UTC 2021

Modified Files:
        src/usr.bin/indent: indent.c parse.c pr_comment.c

Log Message:
indent: clean up comments

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.117 -r1.118 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.30 -r1.31 src/usr.bin/indent/parse.c
cvs rdiff -u -r1.54 -r1.55 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/indent.c
diff -u src/usr.bin/indent/indent.c:1.117 src/usr.bin/indent/indent.c:1.118
--- src/usr.bin/indent/indent.c:1.117	Thu Oct  7 21:41:59 2021
+++ src/usr.bin/indent/indent.c	Thu Oct  7 21:43:20 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.117 2021/10/07 21:41:59 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.118 2021/10/07 21:43:20 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.117 2021/10/07 21:41:59 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.118 2021/10/07 21:43:20 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -577,11 +577,10 @@ process_comment_in_code(token_type ttype
 	*force_nl = false;
     }
 
-    ps.in_stmt = true;		/* turn on flag which causes an extra level of
-				 * indentation. this is turned off by a ';' or
-				 * '}' */
-    if (com.s != com.e) {	/* the turkey has embedded a comment in a
-				 * line. fix it */
+    /* add an extra level of indentation; turned off again by a ';' or '}' */
+    ps.in_stmt = true;
+
+    if (com.s != com.e) {	/* a comment embedded in a line */
 	buf_add_char(&code, ' ');
 	buf_add_buf(&code, &com);
 	buf_add_char(&code, ' ');
@@ -877,8 +876,7 @@ process_lbrace(bool *force_nl, bool *sp_
 	}
     }
     if (code.s == code.e)
-	ps.ind_stmt = false;	/* don't put extra indentation on a line
-				 * with '{' */
+	ps.ind_stmt = false;	/* don't indent the '{' itself */
     if (ps.in_decl && ps.in_or_st) {	/* this is either a structure
 					 * declaration or an init */
 	di_stack[ps.decl_nest] = *decl_ind;
@@ -1243,10 +1241,10 @@ main_loop(void)
 				 * read are stored in "token". */
 
 	/*
-	 * The following code moves newlines and comments following an if (),
-	 * while (), else, etc. up to the start of the following stmt to a
-	 * buffer. This allows proper handling of both kinds of brace
-	 * placement (-br, -bl) and cuddling "else" (-ce).
+	 * Move newlines and comments following an if (), while (), else, etc.
+	 * up to the start of the following stmt to a buffer. This allows
+	 * proper handling of both kinds of brace placement (-br, -bl) and
+	 * cuddling "else" (-ce).
 	 */
 	search_brace(&ttype, &force_nl, &comment_buffered, &last_else);
 
@@ -1352,7 +1350,7 @@ main_loop(void)
 	    if (ps.p_l_follow > 0)
 		goto copy_token;
 	    /* FALLTHROUGH */
-	case decl:		/* we have a declaration type (int, etc.) */
+	case decl:		/* a declaration type (int, etc.) */
 	    process_decl(&decl_ind, &tabs_to_var);
 	    goto copy_token;
 
@@ -1378,7 +1376,7 @@ main_loop(void)
 	    process_comma(decl_ind, tabs_to_var, &force_nl);
 	    break;
 
-	case preprocessing:	/* '#' */
+	case preprocessing:	/* the initial '#' */
 	    process_preprocessing();
 	    break;
 	case comment:		/* the initial '/' '*' or '//' of a comment */

Index: src/usr.bin/indent/parse.c
diff -u src/usr.bin/indent/parse.c:1.30 src/usr.bin/indent/parse.c:1.31
--- src/usr.bin/indent/parse.c:1.30	Thu Oct  7 21:38:25 2021
+++ src/usr.bin/indent/parse.c	Thu Oct  7 21:43:20 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: parse.c,v 1.30 2021/10/07 21:38:25 rillig Exp $	*/
+/*	$NetBSD: parse.c,v 1.31 2021/10/07 21:43:20 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -55,6 +55,10 @@ __FBSDID("$FreeBSD: head/usr.bin/indent/
 
 static void reduce(void);
 
+/*
+ * Shift the token onto the parser stack, or reduce it by combining it with
+ * previous tokens.
+ */
 void
 parse(token_type ttype)
 {
@@ -101,7 +105,6 @@ parse(token_type ttype)
 	     */
 	    ps.ind_level_follow = ps.il[ps.tos--];
 	}
-	/* the rest is the same as for keyword_do and for_exprs */
 	/* FALLTHROUGH */
     case keyword_do:
     case for_exprs:		/* 'for' (...) */
@@ -119,15 +122,13 @@ parse(token_type ttype)
 				 * group or a declaration */
 	else {
 	    if (code.s == code.e) {
+		/* it is a group as part of a while, for, etc. */
 		--ps.ind_level;
 		/*
-		 * it is a group as part of a while, for, etc.
+		 * for a switch, brace should be two levels out from the code
 		 */
 		if (ps.p_stack[ps.tos] == switch_expr && opt.case_indent >= 1)
 		    --ps.ind_level;
-		/*
-		 * for a switch, brace should be two levels out from the code
-		 */
 	    }
 	}
 

Index: src/usr.bin/indent/pr_comment.c
diff -u src/usr.bin/indent/pr_comment.c:1.54 src/usr.bin/indent/pr_comment.c:1.55
--- src/usr.bin/indent/pr_comment.c:1.54	Thu Oct  7 21:38:25 2021
+++ src/usr.bin/indent/pr_comment.c	Thu Oct  7 21:43:20 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: pr_comment.c,v 1.54 2021/10/07 21:38:25 rillig Exp $	*/
+/*	$NetBSD: pr_comment.c,v 1.55 2021/10/07 21:43:20 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.54 2021/10/07 21:38:25 rillig Exp $");
+__RCSID("$NetBSD: pr_comment.c,v 1.55 2021/10/07 21:43:20 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/pr_comment.c 334927 2018-06-10 16:44:18Z pstef $");
 #endif
@@ -169,9 +169,7 @@ process_comment(void)
     if (*buf_ptr != ' ' && !ps.box_com)
 	*com.e++ = ' ';
 
-    /*
-     * Don't put a break delimiter if this is a one-liner that won't wrap.
-     */
+    /* Don't put a break delimiter if this is a one-liner that won't wrap. */
     if (break_delim)
 	for (t_ptr = buf_ptr; *t_ptr != '\0' && *t_ptr != '\n'; t_ptr++) {
 	    if (t_ptr >= buf_end)
@@ -310,9 +308,7 @@ process_comment(void)
 	    /* XXX: signed character comparison '>' does not work for UTF-8 */
 	    if (now_len > adj_max_line_length &&
 		    !ps.box_com && com.e[-1] > ' ') {
-		/*
-		 * the comment is too long, it must be broken up
-		 */
+		/* the comment is too long, it must be broken up */
 		if (last_blank == -1) {
 		    dump_line();
 		    if (!ps.box_com && opt.star_comment_cont)

Reply via email to