Module Name:    src
Committed By:   rillig
Date:           Tue Mar  9 16:48:28 UTC 2021

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

Log Message:
indent: manually indent comments

It's strange that indent's own code is not formatted by indent itself,
which would be a good demonstration of its capabilities.

In its current state, I don't trust indent to get even the tokenization
correct, therefore the only safe way is to format the code manually.


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.18 src/usr.bin/indent/args.c
cvs rdiff -u -r1.35 -r1.36 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.27 -r1.28 src/usr.bin/indent/lexi.c
cvs rdiff -u -r1.14 -r1.15 src/usr.bin/indent/parse.c \
    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/args.c
diff -u src/usr.bin/indent/args.c:1.17 src/usr.bin/indent/args.c:1.18
--- src/usr.bin/indent/args.c:1.17	Sun Mar  7 20:52:11 2021
+++ src/usr.bin/indent/args.c	Tue Mar  9 16:48:28 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: args.c,v 1.17 2021/03/07 20:52:11 rillig Exp $	*/
+/*	$NetBSD: args.c,v 1.18 2021/03/09 16:48:28 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -46,7 +46,7 @@ static char sccsid[] = "@(#)args.c	8.1 (
 #include <sys/cdefs.h>
 #ifndef lint
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: args.c,v 1.17 2021/03/07 20:52:11 rillig Exp $");
+__RCSID("$NetBSD: args.c,v 1.18 2021/03/09 16:48:28 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/args.c 336318 2018-07-15 21:04:21Z pstef $");
 #endif
@@ -85,8 +85,8 @@ __FBSDID("$FreeBSD: head/usr.bin/indent/
 
 static void scan_profile(FILE *);
 
-#define	KEY_FILE		5	/* only used for args */
-#define VERSION			6	/* only used for args */
+#define	KEY_FILE	5	/* only used for args */
+#define VERSION		6	/* only used for args */
 
 const char *option_source = "?";
 

Index: src/usr.bin/indent/indent.c
diff -u src/usr.bin/indent/indent.c:1.35 src/usr.bin/indent/indent.c:1.36
--- src/usr.bin/indent/indent.c:1.35	Mon Mar  8 20:20:11 2021
+++ src/usr.bin/indent/indent.c	Tue Mar  9 16:48:28 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.35 2021/03/08 20:20:11 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.36 2021/03/09 16:48:28 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -46,7 +46,7 @@ static char sccsid[] = "@(#)indent.c	5.1
 #include <sys/cdefs.h>
 #ifndef lint
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: indent.c,v 1.35 2021/03/08 20:20:11 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.36 2021/03/09 16:48:28 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -435,7 +435,7 @@ main(int argc, char **argv)
 		comment_buffered = true;
 		*sc_end++ = '/';	/* copy in start of comment */
 		*sc_end++ = '*';
-		for (;;) {	/* loop until we get to the end of the comment */
+		for (;;) {	/* loop until the end of the comment */
 		    *sc_end = *buf_ptr++;
 		    if (buf_ptr >= buf_end)
 			fill_buffer();
@@ -525,7 +525,7 @@ main(int argc, char **argv)
 		    buf_ptr = save_com;	/* fix so that subsequent calls to
 					 * lexi will take tokens out of
 					 * save_com */
-		    *sc_end++ = ' ';/* add trailing blank, just in case */
+		    *sc_end++ = ' ';	/* add trailing blank, just in case */
 		    buf_end = sc_end;
 		    sc_end = NULL;
 		    break;
@@ -639,7 +639,7 @@ check_type:
 				 * final increment for the null character. */
 	switch (type_code) {	/* now, decide what to do with the token */
 
-	case form_feed:	/* found a form feed in line */
+	case form_feed:		/* found a form feed in line */
 	    ps.use_ff = true;	/* a form feed is treated much like a newline */
 	    dump_line();
 	    ps.want_blank = false;
@@ -716,7 +716,7 @@ check_type:
 	    if (sp_sw && (ps.p_l_follow == 0)) {	/* check for end of if
 							 * (...), or some such */
 		sp_sw = false;
-		force_nl = true;/* must force newline after if */
+		force_nl = true;	/* must force newline after if */
 		ps.last_u_d = true;	/* inform lexi that a following
 					 * operator is unary */
 		ps.in_stmt = false;	/* dont use stmt continuation
@@ -757,7 +757,7 @@ check_type:
 	    ps.want_blank = false;
 	    break;
 
-	case binary_op:	/* any binary operation */
+	case binary_op:		/* any binary operation */
 	    {
 		int len = e_token - s_token;
 
@@ -830,8 +830,8 @@ check_type:
 
 	case semicolon:	/* got a ';' */
 	    if (ps.dec_nest == 0)
-		ps.in_or_st = false;/* we are not in an initialization or
-				     * structure declaration */
+		ps.in_or_st = false;	/* we are not in an initialization or
+					 * structure declaration */
 	    scase = false;	/* these will only need resetting in an error */
 	    squest = 0;
 	    if (ps.last_token == rparen)
@@ -1004,7 +1004,7 @@ check_type:
 	     */
 	    goto copy_id;	/* copy the token into line */
 
-	case sp_nparen:	/* got else, do */
+	case sp_nparen:		/* got else, do */
 	    ps.in_stmt = false;
 	    if (*token == 'e') {
 		if (e_code != s_code && (!opt.cuddle_else || e_code[-1] != '}')) {

Index: src/usr.bin/indent/lexi.c
diff -u src/usr.bin/indent/lexi.c:1.27 src/usr.bin/indent/lexi.c:1.28
--- src/usr.bin/indent/lexi.c:1.27	Mon Mar  8 21:13:33 2021
+++ src/usr.bin/indent/lexi.c	Tue Mar  9 16:48:28 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: lexi.c,v 1.27 2021/03/08 21:13:33 rillig Exp $	*/
+/*	$NetBSD: lexi.c,v 1.28 2021/03/09 16:48:28 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -46,7 +46,7 @@ static char sccsid[] = "@(#)lexi.c	8.1 (
 #include <sys/cdefs.h>
 #ifndef lint
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: lexi.c,v 1.27 2021/03/08 21:13:33 rillig Exp $");
+__RCSID("$NetBSD: lexi.c,v 1.28 2021/03/09 16:48:28 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/lexi.c 337862 2018-08-15 18:19:45Z pstef $");
 #endif
@@ -438,8 +438,8 @@ lexi(struct parser_state *state)
 
     /* Scan a non-alphanumeric token */
 
-    check_size_token(3);		/* things like "<<=" */
-    *e_token++ = *buf_ptr;		/* if it is only a one-character token, it is
+    check_size_token(3);	/* things like "<<=" */
+    *e_token++ = *buf_ptr;	/* if it is only a one-character token, it is
 				 * moved here */
     *e_token = '\0';
     if (++buf_ptr >= buf_end)
@@ -582,7 +582,7 @@ stop_lit:
     case '=':
 	if (state->in_or_st)
 	    state->block_init = 1;
-	if (*buf_ptr == '=') {/* == */
+	if (*buf_ptr == '=') {	/* == */
 	    *e_token++ = '=';	/* Flip =+ to += */
 	    buf_ptr++;
 	    *e_token = 0;

Index: src/usr.bin/indent/parse.c
diff -u src/usr.bin/indent/parse.c:1.14 src/usr.bin/indent/parse.c:1.15
--- src/usr.bin/indent/parse.c:1.14	Sun Mar  7 11:32:05 2021
+++ src/usr.bin/indent/parse.c	Tue Mar  9 16:48:28 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: parse.c,v 1.14 2021/03/07 11:32:05 rillig Exp $	*/
+/*	$NetBSD: parse.c,v 1.15 2021/03/09 16:48:28 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -60,7 +60,7 @@ __FBSDID("$FreeBSD: head/usr.bin/indent/
 static void reduce(void);
 
 void
-parse(token_type tk) /* tk: the code for the construct scanned */
+parse(token_type tk)		/* tk: the code for the construct scanned */
 {
     int         i;
 
@@ -111,7 +111,7 @@ parse(token_type tk) /* tk: the code for
 		ps.i_l_follow = ps.il[ps.tos--];
 	/* the rest is the same as for dolit and forstmt */
 	/* FALLTHROUGH */
-    case dolit:		/* 'do' */
+    case dolit:			/* 'do' */
     case forstmt:		/* for (...) */
 	ps.p_stack[++ps.tos] = tk;
 	ps.il[ps.tos] = ps.ind_level = ps.i_l_follow;
@@ -269,7 +269,7 @@ parse(token_type tk) /* tk: the code for
  *
  */
 /*----------------------------------------------*\
-|   REDUCTION PHASE				    |
+|   REDUCTION PHASE				 |
 \*----------------------------------------------*/
 static void
 reduce(void)
@@ -284,19 +284,17 @@ reduce(void)
 	case stmt:
 	    switch (ps.p_stack[ps.tos - 1]) {
 
-	    case stmt:
-	    case stmtl:
-		/* stmtl stmt or stmt stmt */
+	    case stmt:		/* stmt stmt */
+	    case stmtl:		/* stmtl stmt */
 		ps.p_stack[--ps.tos] = stmtl;
 		break;
 
-	    case dolit:	/* <do> <stmt> */
+	    case dolit:		/* <do> <stmt> */
 		ps.p_stack[--ps.tos] = dohead;
 		ps.i_l_follow = ps.il[ps.tos];
 		break;
 
-	    case ifstmt:
-		/* <if> <stmt> */
+	    case ifstmt:	/* <if> <stmt> */
 		ps.p_stack[--ps.tos] = ifhead;
 		for (i = ps.tos - 1;
 			(
@@ -315,17 +313,13 @@ reduce(void)
 		 */
 		break;
 
-	    case swstmt:
-		/* <switch> <stmt> */
+	    case swstmt:	/* <switch> <stmt> */
 		case_ind = ps.cstk[ps.tos - 1];
 		/* FALLTHROUGH */
 	    case decl:		/* finish of a declaration */
-	    case elsehead:
-		/* <<if> <stmt> else> <stmt> */
-	    case forstmt:
-		/* <for> <stmt> */
-	    case whilestmt:
-		/* <while> <stmt> */
+	    case elsehead:	/* <if> <stmt> else> <stmt> */
+	    case forstmt:	/* <for> <stmt> */
+	    case whilestmt:	/* <while> <stmt> */
 		ps.p_stack[--ps.tos] = stmt;
 		ps.i_l_follow = ps.il[ps.tos];
 		break;
@@ -336,7 +330,7 @@ reduce(void)
 	    }			/* end of section for <stmt> on top of stack */
 	    break;
 
-	case whilestmt:	/* while (...) on top */
+	case whilestmt:		/* while (...) on top */
 	    if (ps.p_stack[ps.tos - 1] == dohead) {
 		/* it is termination of a do while */
 		ps.tos -= 2;
Index: src/usr.bin/indent/pr_comment.c
diff -u src/usr.bin/indent/pr_comment.c:1.14 src/usr.bin/indent/pr_comment.c:1.15
--- src/usr.bin/indent/pr_comment.c:1.14	Mon Mar  8 20:15:42 2021
+++ src/usr.bin/indent/pr_comment.c	Tue Mar  9 16:48:28 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: pr_comment.c,v 1.14 2021/03/08 20:15:42 rillig Exp $	*/
+/*	$NetBSD: pr_comment.c,v 1.15 2021/03/09 16:48:28 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -46,7 +46,7 @@ static char sccsid[] = "@(#)pr_comment.c
 #include <sys/cdefs.h>
 #ifndef lint
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: pr_comment.c,v 1.14 2021/03/08 20:15:42 rillig Exp $");
+__RCSID("$NetBSD: pr_comment.c,v 1.15 2021/03/09 16:48:28 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/pr_comment.c 334927 2018-06-10 16:44:18Z pstef $");
 #endif
@@ -128,8 +128,8 @@ pr_comment(void)
     ps.just_saw_decl = 0;
     last_bl = NULL;		/* no blanks found so far */
     ps.box_com = false;		/* at first, assume that we are not in
-					 * a boxed comment or some other
-					 * comment that should not be touched */
+				 * a boxed comment or some other
+				 * comment that should not be touched */
     ++ps.out_coms;		/* keep track of number of comments */
 
     /* Figure where to align and how to treat the comment */

Reply via email to