CVS commit: src/usr.bin/indent

2021-10-07 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Oct  7 23:18:47 UTC 2021

Modified Files:
src/usr.bin/indent: indent.c indent_globs.h io.c

Log Message:
indent: rename bp_save to saved_inp_s, be_save to saved_inp_e

Using the same naming convention makes it easier to relate the
variables.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.124 -r1.125 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.47 -r1.48 src/usr.bin/indent/indent_globs.h
cvs rdiff -u -r1.79 -r1.80 src/usr.bin/indent/io.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/indent

2021-10-07 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Oct  7 23:18:47 UTC 2021

Modified Files:
src/usr.bin/indent: indent.c indent_globs.h io.c

Log Message:
indent: rename bp_save to saved_inp_s, be_save to saved_inp_e

Using the same naming convention makes it easier to relate the
variables.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.124 -r1.125 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.47 -r1.48 src/usr.bin/indent/indent_globs.h
cvs rdiff -u -r1.79 -r1.80 src/usr.bin/indent/io.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.124 src/usr.bin/indent/indent.c:1.125
--- src/usr.bin/indent/indent.c:1.124	Thu Oct  7 23:15:15 2021
+++ src/usr.bin/indent/indent.c	Thu Oct  7 23:18:47 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.124 2021/10/07 23:15:15 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.125 2021/10/07 23:18:47 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@ static char sccsid[] = "@(#)indent.c	5.1
 
 #include 
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: indent.c,v 1.124 2021/10/07 23:15:15 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.125 2021/10/07 23:18:47 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -98,8 +98,8 @@ char sc_buf[sc_size];
 char *save_com;
 static char *sc_end;		/* pointer into save_com buffer */
 
-char *bp_save;
-char *be_save;
+char *saved_inp_s;
+char *saved_inp_e;
 
 bool found_err;
 int next_blank_lines;
@@ -276,8 +276,8 @@ static void
 switch_buffer(void)
 {
 ps.search_brace = false;	/* stop looking for start of stmt */
-bp_save = inp.s;		/* save current input buffer */
-be_save = inp.e;
+saved_inp_s = inp.s;		/* save current input buffer */
+saved_inp_e = inp.e;
 inp.s = save_com;		/* fix so that subsequent calls to lexi will
  * take tokens out of save_com */
 *sc_end++ = ' ';		/* add trailing blank, just in case */
@@ -451,8 +451,8 @@ main_init_globals(void)
 ps.is_case_label = false;
 
 sc_end = NULL;
-bp_save = NULL;
-be_save = NULL;
+saved_inp_s = NULL;
+saved_inp_e = NULL;
 
 output = NULL;
 
@@ -1163,7 +1163,7 @@ read_preprocessing_line(void)
 
 while (lab.e > lab.s && is_hspace(lab.e[-1]))
 	lab.e--;
-if (lab.e - lab.s == com_end && bp_save == NULL) {
+if (lab.e - lab.s == com_end && saved_inp_s == NULL) {
 	/* comment on preprocessor line */
 	if (sc_end == NULL) {	/* if this is the first comment, we must set
  * up the buffer */
@@ -1181,8 +1181,8 @@ read_preprocessing_line(void)
 	lab.e = lab.s + com_start;
 	while (lab.e > lab.s && is_hspace(lab.e[-1]))
 	lab.e--;
-	bp_save = inp.s;	/* save current input buffer */
-	be_save = inp.e;
+	saved_inp_s = inp.s;	/* save current input buffer */
+	saved_inp_e = inp.e;
 	inp.s = save_com;	/* fix so that subsequent calls to lexi will
  * take tokens out of save_com */
 	*sc_end++ = ' ';	/* add trailing blank, just in case */

Index: src/usr.bin/indent/indent_globs.h
diff -u src/usr.bin/indent/indent_globs.h:1.47 src/usr.bin/indent/indent_globs.h:1.48
--- src/usr.bin/indent/indent_globs.h:1.47	Thu Oct  7 23:15:15 2021
+++ src/usr.bin/indent/indent_globs.h	Thu Oct  7 23:18:47 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent_globs.h,v 1.47 2021/10/07 23:15:15 rillig Exp $	*/
+/*	$NetBSD: indent_globs.h,v 1.48 2021/10/07 23:18:47 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -64,11 +64,11 @@ extern struct buffer inp;
 
 extern charsc_buf[sc_size];	/* input text is saved here when looking for
  * the brace after an if, while, etc */
-extern char   *save_com;		/* start of the comment stored in sc_buf */
+extern char   *save_com;	/* start of the comment stored in sc_buf */
 
-extern char   *bp_save;		/* saved value of inp.s when taking input
+extern char   *saved_inp_s;	/* saved value of inp.s when taking input
  * from save_com */
-extern char   *be_save;		/* similarly saved value of inp.e */
+extern char   *saved_inp_e;	/* similarly saved value of inp.e */
 
 
 extern struct options {

Index: src/usr.bin/indent/io.c
diff -u src/usr.bin/indent/io.c:1.79 src/usr.bin/indent/io.c:1.80
--- src/usr.bin/indent/io.c:1.79	Thu Oct  7 23:15:15 2021
+++ src/usr.bin/indent/io.c	Thu Oct  7 23:18:47 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: io.c,v 1.79 2021/10/07 23:15:15 rillig Exp $	*/
+/*	$NetBSD: io.c,v 1.80 2021/10/07 23:18:47 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@ static char sccsid[] = "@(#)io.c	8.1 (Be
 
 #include 
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: io.c,v 1.79 2021/10/07 23:15:15 rillig Exp $");
+__RCSID("$NetBSD: io.c,v 1.80 2021/10/07 23:18:47 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: 

CVS commit: src/usr.bin/indent

2021-10-07 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Oct  7 23:15:16 UTC 2021

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

Log Message:
indent: group variables for the input buffer

The input buffer follows the same concept as the intermediate buffers
for label, code, comment and token, so use the same type for it.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.123 -r1.124 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.46 -r1.47 src/usr.bin/indent/indent_globs.h
cvs rdiff -u -r1.78 -r1.79 src/usr.bin/indent/io.c
cvs rdiff -u -r1.77 -r1.78 src/usr.bin/indent/lexi.c
cvs rdiff -u -r1.57 -r1.58 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.123 src/usr.bin/indent/indent.c:1.124
--- src/usr.bin/indent/indent.c:1.123	Thu Oct  7 23:01:32 2021
+++ src/usr.bin/indent/indent.c	Thu Oct  7 23:15:15 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.123 2021/10/07 23:01:32 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.124 2021/10/07 23:15:15 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@ static char sccsid[] = "@(#)indent.c	5.1
 
 #include 
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: indent.c,v 1.123 2021/10/07 23:01:32 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.124 2021/10/07 23:15:15 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -92,10 +92,7 @@ struct buffer code;
 struct buffer com;
 struct buffer token;
 
-char *in_buffer;
-char *in_buffer_limit;
-char *buf_ptr;
-char *buf_end;
+struct buffer inp;
 
 char sc_buf[sc_size];
 char *save_com;
@@ -176,8 +173,8 @@ search_brace_comment(bool *comment_buffe
 	 * process_comment() will use that to calculate original indentation
 	 * of a boxed comment.
 	 */
-	memcpy(sc_buf, in_buffer, (size_t)(buf_ptr - in_buffer) - 4);
-	save_com = sc_buf + (buf_ptr - in_buffer - 4);
+	memcpy(sc_buf, inp.buf, (size_t)(inp.s - inp.buf) - 4);
+	save_com = sc_buf + (inp.s - inp.buf - 4);
 	save_com[0] = save_com[1] = ' ';
 	sc_end = _com[2];
 }
@@ -188,7 +185,7 @@ search_brace_comment(bool *comment_buffe
 
 for (;;) {			/* loop until the end of the comment */
 	*sc_end++ = inbuf_next();
-	if (sc_end[-1] == '*' && *buf_ptr == '/')
+	if (sc_end[-1] == '*' && *inp.s == '/')
 	break;		/* we are at end of comment */
 	if (sc_end >= _com[sc_size]) {	/* check for temp buffer
 		 * overflow */
@@ -216,9 +213,9 @@ search_brace_lbrace(void)
 	 * will be moved into "the else's line", so if there was a newline
 	 * resulting from the "{" before, it must be scanned now and ignored.
 	 */
-	while (isspace((unsigned char)*buf_ptr)) {
+	while (isspace((unsigned char)*inp.s)) {
 	inbuf_skip();
-	if (*buf_ptr == '\n')
+	if (*inp.s == '\n')
 		break;
 	}
 	return true;
@@ -279,14 +276,14 @@ static void
 switch_buffer(void)
 {
 ps.search_brace = false;	/* stop looking for start of stmt */
-bp_save = buf_ptr;		/* save current input buffer */
-be_save = buf_end;
-buf_ptr = save_com;		/* fix so that subsequent calls to lexi will
+bp_save = inp.s;		/* save current input buffer */
+be_save = inp.e;
+inp.s = save_com;		/* fix so that subsequent calls to lexi will
  * take tokens out of save_com */
 *sc_end++ = ' ';		/* add trailing blank, just in case */
-buf_end = sc_end;
+inp.e = sc_end;
 sc_end = NULL;
-debug_println("switched buf_ptr to save_com");
+debug_println("switched inp.s to save_com");
 }
 
 static void
@@ -314,12 +311,12 @@ search_brace_lookahead(token_type *ttype
  * into the buffer so that the later lexi() call will read them.
  */
 if (sc_end != NULL) {
-	while (is_hspace(*buf_ptr)) {
-	*sc_end++ = *buf_ptr++;
+	while (is_hspace(*inp.s)) {
+	*sc_end++ = *inp.s++;
 	if (sc_end >= _com[sc_size])
 		errx(1, "input too long");
 	}
-	if (buf_ptr >= buf_end)
+	if (inp.s >= inp.e)
 	fill_buffer();
 }
 
@@ -443,9 +440,9 @@ main_init_globals(void)
 
 opt.else_if = true;		/* XXX: redundant? */
 
-in_buffer = xmalloc(10);
-in_buffer_limit = in_buffer + 8;
-buf_ptr = buf_end = in_buffer;
+inp.buf = xmalloc(10);
+inp.l = inp.buf + 8;
+inp.s = inp.e = inp.buf;
 line_no = 1;
 had_eof = ps.in_decl = ps.decl_on_line = break_comma = false;
 
@@ -536,7 +533,7 @@ main_prepare_parsing(void)
 
 parse(semicolon);
 
-char *p = buf_ptr;
+char *p = inp.s;
 int ind = 0;
 
 for (;;) {
@@ -1124,10 +1121,10 @@ read_preprocessing_line(void)
 int com_start = 0, com_end = 0;
 char quote = '\0';
 
-while (is_hspace(*buf_ptr))
+while (is_hspace(*inp.s))
 	inbuf_skip();
 
-while (*buf_ptr != '\n' || (in_comment && !had_eof)) {
+while (*inp.s 

CVS commit: src/usr.bin/indent

2021-10-07 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Oct  7 23:15:16 UTC 2021

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

Log Message:
indent: group variables for the input buffer

The input buffer follows the same concept as the intermediate buffers
for label, code, comment and token, so use the same type for it.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.123 -r1.124 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.46 -r1.47 src/usr.bin/indent/indent_globs.h
cvs rdiff -u -r1.78 -r1.79 src/usr.bin/indent/io.c
cvs rdiff -u -r1.77 -r1.78 src/usr.bin/indent/lexi.c
cvs rdiff -u -r1.57 -r1.58 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.



CVS commit: src/usr.bin/indent

2021-10-07 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Oct  7 23:01:32 UTC 2021

Modified Files:
src/usr.bin/indent: indent.c indent_globs.h

Log Message:
indent: move definition of bufsize from header to implementation

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.122 -r1.123 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.45 -r1.46 src/usr.bin/indent/indent_globs.h

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.122 src/usr.bin/indent/indent.c:1.123
--- src/usr.bin/indent/indent.c:1.122	Thu Oct  7 22:56:49 2021
+++ src/usr.bin/indent/indent.c	Thu Oct  7 23:01:32 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.122 2021/10/07 22:56:49 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.123 2021/10/07 23:01:32 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@ static char sccsid[] = "@(#)indent.c	5.1
 
 #include 
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: indent.c,v 1.122 2021/10/07 22:56:49 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.123 2021/10/07 23:01:32 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -366,12 +366,13 @@ search_brace(token_type *ttype, bool *fo
 static void
 buf_init(struct buffer *buf)
 {
-buf->buf = xmalloc(bufsize);
+size_t size = 200;
+buf->buf = xmalloc(size);
 buf->buf[0] = ' ';		/* allow accessing buf->e[-1] */
 buf->buf[1] = '\0';
 buf->s = buf->buf + 1;
 buf->e = buf->s;
-buf->l = buf->buf + bufsize - 5;	/* safety margin, though unreliable */
+buf->l = buf->buf + size - 5;	/* safety margin */
 }
 
 static size_t

Index: src/usr.bin/indent/indent_globs.h
diff -u src/usr.bin/indent/indent_globs.h:1.45 src/usr.bin/indent/indent_globs.h:1.46
--- src/usr.bin/indent/indent_globs.h:1.45	Thu Oct  7 22:56:49 2021
+++ src/usr.bin/indent/indent_globs.h	Thu Oct  7 23:01:32 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent_globs.h,v 1.45 2021/10/07 22:56:49 rillig Exp $	*/
+/*	$NetBSD: indent_globs.h,v 1.46 2021/10/07 23:01:32 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -40,7 +40,6 @@
  * $FreeBSD: head/usr.bin/indent/indent_globs.h 337651 2018-08-11 19:20:06Z pstef $
  */
 
-#define bufsize 200		/* size of internal buffers */
 #define sc_size 5000		/* size of save_com buffer */
 #define label_offset 2		/* number of levels a label is placed to left
  * of code */



CVS commit: src/usr.bin/indent

2021-10-07 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Oct  7 23:01:32 UTC 2021

Modified Files:
src/usr.bin/indent: indent.c indent_globs.h

Log Message:
indent: move definition of bufsize from header to implementation

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.122 -r1.123 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.45 -r1.46 src/usr.bin/indent/indent_globs.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/indent

2021-10-07 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Oct  7 22:56:49 UTC 2021

Modified Files:
src/usr.bin/indent: args.c indent.c indent_globs.h parse.c

Log Message:
indent: rename opt.btype_2 to brace_same_line

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.50 -r1.51 src/usr.bin/indent/args.c
cvs rdiff -u -r1.121 -r1.122 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.44 -r1.45 src/usr.bin/indent/indent_globs.h
cvs rdiff -u -r1.32 -r1.33 src/usr.bin/indent/parse.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.50 src/usr.bin/indent/args.c:1.51
--- src/usr.bin/indent/args.c:1.50	Thu Oct  7 21:41:59 2021
+++ src/usr.bin/indent/args.c	Thu Oct  7 22:56:49 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: args.c,v 1.50 2021/10/07 21:41:59 rillig Exp $	*/
+/*	$NetBSD: args.c,v 1.51 2021/10/07 22:56:49 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@ static char sccsid[] = "@(#)args.c	8.1 (
 
 #include 
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: args.c,v 1.50 2021/10/07 21:41:59 rillig Exp $");
+__RCSID("$NetBSD: args.c,v 1.51 2021/10/07 22:56:49 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/args.c 336318 2018-07-15 21:04:21Z pstef $");
 #endif
@@ -94,8 +94,8 @@ static const struct pro {
 bool_options("bap", blanklines_after_procs),
 bool_options("bbb", blanklines_before_blockcomments),
 bool_options("bc", break_after_comma),
-bool_option("bl", false, btype_2),
-bool_option("br", true, btype_2),
+bool_option("bl", false, brace_same_line),
+bool_option("br", true, brace_same_line),
 bool_options("bs", blank_after_sizeof),
 int_option("c", comment_column),
 int_option("cd", decl_comment_column),

Index: src/usr.bin/indent/indent.c
diff -u src/usr.bin/indent/indent.c:1.121 src/usr.bin/indent/indent.c:1.122
--- src/usr.bin/indent/indent.c:1.121	Thu Oct  7 22:52:13 2021
+++ src/usr.bin/indent/indent.c	Thu Oct  7 22:56:49 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.121 2021/10/07 22:52:13 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.122 2021/10/07 22:56:49 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@ static char sccsid[] = "@(#)indent.c	5.1
 
 #include 
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: indent.c,v 1.121 2021/10/07 22:52:13 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.122 2021/10/07 22:56:49 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -65,7 +65,7 @@ __FBSDID("$FreeBSD: head/usr.bin/indent/
 #include "indent.h"
 
 struct options opt = {
-.btype_2 = true,
+.brace_same_line = true,
 .comment_delimiter_on_blankline = true,
 .cuddle_else = true,
 .comment_column = 33,
@@ -209,7 +209,7 @@ search_brace_lbrace(void)
  * Put KNF-style lbraces before the buffered up tokens and jump out of
  * this loop in order to avoid copying the token again.
  */
-if (sc_end != NULL && opt.btype_2) {
+if (sc_end != NULL && opt.brace_same_line) {
 	save_com[0] = '{';
 	/*
 	 * Originally the lbrace may have been alone on its own line, but it
@@ -576,7 +576,7 @@ process_comment_in_code(token_type ttype
 {
 if (*force_nl &&
 	ttype != semicolon &&
-	(ttype != lbrace || !opt.btype_2)) {
+	(ttype != lbrace || !opt.brace_same_line)) {
 
 	/* we should force a broken line here */
 	if (opt.verbose)
@@ -712,10 +712,12 @@ process_rparen_or_rbracket(bool *sp_sw, 
 
 	parse(hd_type);		/* let parser worry about if, or whatever */
 }
-ps.search_brace = opt.btype_2;	/* this should ensure that constructs
-	 * such as main(){...} and int[]{...}
-	 * have their braces put in the right
-	 * place */
+
+/*
+ * This should ensure that constructs such as main(){...} and int[]{...}
+ * have their braces put in the right place.
+ */
+ps.search_brace = opt.brace_same_line;
 }
 
 static void
@@ -863,7 +865,7 @@ process_lbrace(bool *force_nl, bool *sp_
 	ps.block_init_level++;
 
 if (code.s != code.e && !ps.block_init) {
-	if (!opt.btype_2) {
+	if (!opt.brace_same_line) {
 	dump_line();
 	ps.want_blank = false;
 	} else if (ps.in_parameter_declaration && !ps.in_or_st) {

Index: src/usr.bin/indent/indent_globs.h
diff -u src/usr.bin/indent/indent_globs.h:1.44 src/usr.bin/indent/indent_globs.h:1.45
--- src/usr.bin/indent/indent_globs.h:1.44	Thu Oct  7 21:41:59 2021
+++ src/usr.bin/indent/indent_globs.h	Thu Oct  7 22:56:49 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent_globs.h,v 1.44 2021/10/07 21:41:59 rillig Exp $	*/
+/*	$NetBSD: indent_globs.h,v 1.45 2021/10/07 22:56:49 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -90,7 +90,7 @@ extern struct options {
 bool	blanklines_before_blockcomments;
 bool	

CVS commit: src/usr.bin/indent

2021-10-07 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Oct  7 22:56:49 UTC 2021

Modified Files:
src/usr.bin/indent: args.c indent.c indent_globs.h parse.c

Log Message:
indent: rename opt.btype_2 to brace_same_line

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.50 -r1.51 src/usr.bin/indent/args.c
cvs rdiff -u -r1.121 -r1.122 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.44 -r1.45 src/usr.bin/indent/indent_globs.h
cvs rdiff -u -r1.32 -r1.33 src/usr.bin/indent/parse.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/indent

2021-10-07 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Oct  7 22:52:13 UTC 2021

Modified Files:
src/usr.bin/indent: indent.c lexi.c

Log Message:
indent: clean up code, remove outdated wrong comments

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.120 -r1.121 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.76 -r1.77 src/usr.bin/indent/lexi.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.120 src/usr.bin/indent/indent.c:1.121
--- src/usr.bin/indent/indent.c:1.120	Thu Oct  7 21:57:21 2021
+++ src/usr.bin/indent/indent.c	Thu Oct  7 22:52:13 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.120 2021/10/07 21:57:21 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.121 2021/10/07 22:52:13 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@ static char sccsid[] = "@(#)indent.c	5.1
 
 #include 
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: indent.c,v 1.120 2021/10/07 21:57:21 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.121 2021/10/07 22:52:13 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -446,7 +446,7 @@ main_init_globals(void)
 in_buffer_limit = in_buffer + 8;
 buf_ptr = buf_end = in_buffer;
 line_no = 1;
-had_eof = ps.in_decl = ps.decl_on_line = (break_comma = false);
+had_eof = ps.in_decl = ps.decl_on_line = break_comma = false;
 
 ps.in_or_st = false;
 ps.want_blank = ps.in_stmt = ps.ind_stmt = false;

Index: src/usr.bin/indent/lexi.c
diff -u src/usr.bin/indent/lexi.c:1.76 src/usr.bin/indent/lexi.c:1.77
--- src/usr.bin/indent/lexi.c:1.76	Thu Oct  7 21:57:21 2021
+++ src/usr.bin/indent/lexi.c	Thu Oct  7 22:52:13 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: lexi.c,v 1.76 2021/10/07 21:57:21 rillig Exp $	*/
+/*	$NetBSD: lexi.c,v 1.77 2021/10/07 22:52:13 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@ static char sccsid[] = "@(#)lexi.c	8.1 (
 
 #include 
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: lexi.c,v 1.76 2021/10/07 21:57:21 rillig Exp $");
+__RCSID("$NetBSD: lexi.c,v 1.77 2021/10/07 22:52:13 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/lexi.c 337862 2018-08-15 18:19:45Z pstef $");
 #endif
@@ -478,8 +478,7 @@ lexi(struct parser_state *state)
 	if (*buf_ptr == '(' && state->tos <= 1 && state->ind_level == 0 &&
 	!state->in_parameter_declaration && !state->block_init) {
 
-	char *tp = buf_ptr;
-	while (tp < buf_end)
+	for (char *tp = buf_ptr; tp < buf_end;)
 		if (*tp++ == ')' && (*tp == ';' || *tp == ','))
 		goto not_proc;
 
@@ -614,14 +613,12 @@ lexi(struct parser_state *state)
 	if (state->in_or_st)
 	state->block_init = true;
 	if (*buf_ptr == '=') {	/* == */
-	*token.e++ = '=';	/* Flip =+ to += */
-	buf_ptr++;
+	*token.e++ = *buf_ptr++;
 	*token.e = '\0';
 	}
 	ttype = binary_op;
 	unary_delim = true;
 	break;
-	/* can drop thru!!! */
 
 case '>':
 case '<':



CVS commit: src/usr.bin/indent

2021-10-07 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Oct  7 22:52:13 UTC 2021

Modified Files:
src/usr.bin/indent: indent.c lexi.c

Log Message:
indent: clean up code, remove outdated wrong comments

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.120 -r1.121 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.76 -r1.77 src/usr.bin/indent/lexi.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/indent

2021-10-07 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Oct  7 21:57:21 UTC 2021

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

Log Message:
indent: use braces around multi-line statements

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.119 -r1.120 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.77 -r1.78 src/usr.bin/indent/io.c
cvs rdiff -u -r1.75 -r1.76 src/usr.bin/indent/lexi.c
cvs rdiff -u -r1.56 -r1.57 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.119 src/usr.bin/indent/indent.c:1.120
--- src/usr.bin/indent/indent.c:1.119	Thu Oct  7 21:52:54 2021
+++ src/usr.bin/indent/indent.c	Thu Oct  7 21:57:21 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.119 2021/10/07 21:52:54 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.120 2021/10/07 21:57:21 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@ static char sccsid[] = "@(#)indent.c	5.1
 
 #include 
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: indent.c,v 1.119 2021/10/07 21:52:54 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.120 2021/10/07 21:57:21 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -248,9 +248,8 @@ search_brace_other(token_type ttype, boo
 	return false;
 }
 
-while (sc_end > save_com && isblank((unsigned char)sc_end[-1])) {
+while (sc_end > save_com && isblank((unsigned char)sc_end[-1]))
 	sc_end--;
-}
 
 if (opt.swallow_optional_blanklines ||
 	(!comment_buffered && remove_newlines)) {
@@ -1430,9 +1429,7 @@ main_loop(void)
 	}
 
 	*code.e = '\0';
-	if (ttype != comment &&
-	ttype != newline &&
-	ttype != preprocessing)
+	if (ttype != comment && ttype != newline && ttype != preprocessing)
 	ps.last_token = ttype;
 }
 }

Index: src/usr.bin/indent/io.c
diff -u src/usr.bin/indent/io.c:1.77 src/usr.bin/indent/io.c:1.78
--- src/usr.bin/indent/io.c:1.77	Thu Oct  7 21:52:54 2021
+++ src/usr.bin/indent/io.c	Thu Oct  7 21:57:21 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: io.c,v 1.77 2021/10/07 21:52:54 rillig Exp $	*/
+/*	$NetBSD: io.c,v 1.78 2021/10/07 21:57:21 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@ static char sccsid[] = "@(#)io.c	8.1 (Be
 
 #include 
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: io.c,v 1.77 2021/10/07 21:52:54 rillig Exp $");
+__RCSID("$NetBSD: io.c,v 1.78 2021/10/07 21:57:21 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/io.c 334927 2018-06-10 16:44:18Z pstef $");
 #endif
@@ -296,13 +296,13 @@ compute_code_indent(void)
 int target_ind = opt.indent_size * ps.ind_level;
 
 if (ps.paren_level != 0) {
-	if (!opt.lineup_to_parens)
+	if (!opt.lineup_to_parens) {
 	if (2 * opt.continuation_indent == opt.indent_size)
 		target_ind += opt.continuation_indent;
 	else
 		target_ind += opt.continuation_indent * ps.paren_level;
 
-	else if (opt.lineup_to_parens_always)
+	} else if (opt.lineup_to_parens_always) {
 	/*
 	 * XXX: where does this '- 1' come from?  It looks strange but is
 	 * nevertheless needed for proper indentation, as demonstrated in
@@ -310,7 +310,7 @@ compute_code_indent(void)
 	 */
 	target_ind = paren_indent - 1;
 
-	else {
+	} else {
 	int w;
 	int t = paren_indent;
 

Index: src/usr.bin/indent/lexi.c
diff -u src/usr.bin/indent/lexi.c:1.75 src/usr.bin/indent/lexi.c:1.76
--- src/usr.bin/indent/lexi.c:1.75	Thu Oct  7 21:52:54 2021
+++ src/usr.bin/indent/lexi.c	Thu Oct  7 21:57:21 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: lexi.c,v 1.75 2021/10/07 21:52:54 rillig Exp $	*/
+/*	$NetBSD: lexi.c,v 1.76 2021/10/07 21:57:21 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@ static char sccsid[] = "@(#)lexi.c	8.1 (
 
 #include 
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: lexi.c,v 1.75 2021/10/07 21:52:54 rillig Exp $");
+__RCSID("$NetBSD: lexi.c,v 1.76 2021/10/07 21:57:21 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/lexi.c 337862 2018-08-15 18:19:45Z pstef $");
 #endif
@@ -596,11 +596,11 @@ lexi(struct parser_state *state)
 		unary_delim = false;
 	}
 
-	} else if (*buf_ptr == '=')
+	} else if (*buf_ptr == '=') {
 	/* check for operator += */
 	*token.e++ = *buf_ptr++;
 
-	else if (*buf_ptr == '>') {
+	} else if (*buf_ptr == '>') {
 	/* check for operator -> */
 	*token.e++ = *buf_ptr++;
 	unary_delim = false;

Index: src/usr.bin/indent/pr_comment.c
diff -u src/usr.bin/indent/pr_comment.c:1.56 src/usr.bin/indent/pr_comment.c:1.57
--- src/usr.bin/indent/pr_comment.c:1.56	Thu Oct  7 21:52:54 2021
+++ src/usr.bin/indent/pr_comment.c	Thu Oct  7 21:57:21 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: pr_comment.c,v 1.56 2021/10/07 21:52:54 rillig 

CVS commit: src/usr.bin/indent

2021-10-07 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Oct  7 21:57:21 UTC 2021

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

Log Message:
indent: use braces around multi-line statements

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.119 -r1.120 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.77 -r1.78 src/usr.bin/indent/io.c
cvs rdiff -u -r1.75 -r1.76 src/usr.bin/indent/lexi.c
cvs rdiff -u -r1.56 -r1.57 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.



CVS commit: src/usr.bin/indent

2021-10-07 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Oct  7 21:52:54 UTC 2021

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

Log Message:
indent: let the code breathe a bit by inserting empty lines

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.118 -r1.119 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.76 -r1.77 src/usr.bin/indent/io.c
cvs rdiff -u -r1.74 -r1.75 src/usr.bin/indent/lexi.c
cvs rdiff -u -r1.31 -r1.32 src/usr.bin/indent/parse.c
cvs rdiff -u -r1.55 -r1.56 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.118 src/usr.bin/indent/indent.c:1.119
--- src/usr.bin/indent/indent.c:1.118	Thu Oct  7 21:43:20 2021
+++ src/usr.bin/indent/indent.c	Thu Oct  7 21:52:54 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.118 2021/10/07 21:43:20 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.119 2021/10/07 21:52:54 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@ static char sccsid[] = "@(#)indent.c	5.1
 
 #include 
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: indent.c,v 1.118 2021/10/07 21:43:20 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.119 2021/10/07 21:52:54 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -181,9 +181,11 @@ search_brace_comment(bool *comment_buffe
 	save_com[0] = save_com[1] = ' ';
 	sc_end = _com[2];
 }
+
 *comment_buffered = true;
 *sc_end++ = '/';		/* copy in start of comment */
 *sc_end++ = '*';
+
 for (;;) {			/* loop until the end of the comment */
 	*sc_end++ = inbuf_next();
 	if (sc_end[-1] == '*' && *buf_ptr == '/')
@@ -195,6 +197,7 @@ search_brace_comment(bool *comment_buffe
 	exit(1);
 	}
 }
+
 *sc_end++ = '/';		/* add ending slash */
 inbuf_skip();		/* get past / in buffer */
 }
@@ -238,14 +241,17 @@ search_brace_other(token_type ttype, boo
 		*token.s == 'i' && last_else && opt.else_if);
 if (remove_newlines)
 	*force_nl = false;
+
 if (sc_end == NULL) {	/* ignore buffering if comment wasn't saved
  * up */
 	ps.search_brace = false;
 	return false;
 }
+
 while (sc_end > save_com && isblank((unsigned char)sc_end[-1])) {
 	sc_end--;
 }
+
 if (opt.swallow_optional_blanklines ||
 	(!comment_buffered && remove_newlines)) {
 	*force_nl = !remove_newlines;
@@ -253,6 +259,7 @@ search_brace_other(token_type ttype, boo
 	sc_end--;
 	}
 }
+
 if (*force_nl) {		/* if we should insert a nl here, put it into
  * the buffer */
 	*force_nl = false;
@@ -263,6 +270,7 @@ search_brace_other(token_type ttype, boo
 	if (opt.verbose)	/* warn if the line was not already broken */
 	diag(0, "Line broken");
 }
+
 for (const char *t_ptr = token.s; *t_ptr != '\0'; ++t_ptr)
 	*sc_end++ = *t_ptr;
 return true;
@@ -432,6 +440,7 @@ main_init_globals(void)
 buf_init();
 buf_init();
 buf_init();
+
 opt.else_if = true;		/* XXX: redundant? */
 
 in_buffer = xmalloc(10);
@@ -439,10 +448,11 @@ main_init_globals(void)
 buf_ptr = buf_end = in_buffer;
 line_no = 1;
 had_eof = ps.in_decl = ps.decl_on_line = (break_comma = false);
+
 ps.in_or_st = false;
 ps.want_blank = ps.in_stmt = ps.ind_stmt = false;
-
 ps.is_case_label = false;
+
 sc_end = NULL;
 bp_save = NULL;
 be_save = NULL;
@@ -633,6 +643,7 @@ process_lparen_or_lbracket(int decl_ind,
 	nitems(ps.paren_indents));
 	ps.p_l_follow--;
 }
+
 if (token.s[0] == '(' && ps.in_decl
 	&& !ps.block_init && !ps.dumped_decl_indent &&
 	ps.procname[0] == '\0' && ps.paren_level == 0) {
@@ -654,6 +665,7 @@ process_lparen_or_lbracket(int decl_ind,
 	ps.paren_indents[0] = (short)(2 * opt.indent_size);
 	debug_println("paren_indent[0] is now %d", ps.paren_indents[0]);
 }
+
 if (ps.in_or_st && *token.s == '(' && ps.tos <= 2) {
 	/*
 	 * this is a kluge to make sure that declarations will be aligned
@@ -663,6 +675,7 @@ process_lparen_or_lbracket(int decl_ind,
 	ps.in_or_st = false;	/* turn off flag for structure decl or
  * initialization */
 }
+
 /* parenthesized type following sizeof or offsetof is not a cast */
 if (ps.keyword == kw_offsetof || ps.keyword == kw_sizeof)
 	ps.not_cast_mask |= 1 << ps.p_l_follow;
@@ -841,6 +854,7 @@ process_lbrace(bool *force_nl, bool *sp_
 int *di_stack, int di_stack_cap, int *decl_ind)
 {
 ps.in_stmt = false;		/* don't indent the {} */
+
 if (!ps.block_init)
 	*force_nl = true;	/* force other stuff on same line as '{' onto
  * new line */
@@ -863,6 +877,7 @@ process_lbrace(bool *force_nl, bool *sp_
 		ps.want_blank = true;
 	}
 }
+
 if (ps.in_parameter_declaration)
 	prefix_blankline_requested = false;
 
@@ -875,6 +890,7 @@ process_lbrace(bool *force_nl, 

CVS commit: src/usr.bin/indent

2021-10-07 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Oct  7 21:52:54 UTC 2021

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

Log Message:
indent: let the code breathe a bit by inserting empty lines

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.118 -r1.119 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.76 -r1.77 src/usr.bin/indent/io.c
cvs rdiff -u -r1.74 -r1.75 src/usr.bin/indent/lexi.c
cvs rdiff -u -r1.31 -r1.32 src/usr.bin/indent/parse.c
cvs rdiff -u -r1.55 -r1.56 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.



CVS commit: src/usr.bin/indent

2021-10-07 Thread Roland Illig
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 
 #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(, ' ');
 	buf_add_buf(, );
 	buf_add_char(, ' ');
@@ -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(, _nl, _buffered, _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(_ind, _to_var);
 	goto copy_token;
 
@@ -1378,7 +1376,7 @@ main_loop(void)
 	process_comma(decl_ind, tabs_to_var, _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 

CVS commit: src/usr.bin/indent

2021-10-07 Thread Roland Illig
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.



CVS commit: src/usr.bin/indent

2021-10-07 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Oct  7 21:41:59 UTC 2021

Modified Files:
src/usr.bin/indent: args.c indent.c indent_globs.h lexi.c

Log Message:
indent: fix wrong or outdated comments

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.49 -r1.50 src/usr.bin/indent/args.c
cvs rdiff -u -r1.116 -r1.117 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.43 -r1.44 src/usr.bin/indent/indent_globs.h
cvs rdiff -u -r1.73 -r1.74 src/usr.bin/indent/lexi.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.49 src/usr.bin/indent/args.c:1.50
--- src/usr.bin/indent/args.c:1.49	Thu Oct  7 19:42:41 2021
+++ src/usr.bin/indent/args.c	Thu Oct  7 21:41:59 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: args.c,v 1.49 2021/10/07 19:42:41 rillig Exp $	*/
+/*	$NetBSD: args.c,v 1.50 2021/10/07 21:41:59 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,15 +43,12 @@ static char sccsid[] = "@(#)args.c	8.1 (
 
 #include 
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: args.c,v 1.49 2021/10/07 19:42:41 rillig Exp $");
+__RCSID("$NetBSD: args.c,v 1.50 2021/10/07 21:41:59 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/args.c 336318 2018-07-15 21:04:21Z pstef $");
 #endif
 
-/*
- * Argument scanning and profile reading code.  Default parameters are set
- * here as well.
- */
+/* Read options from profile files and from the command line. */
 
 #include 
 #include 

Index: src/usr.bin/indent/indent.c
diff -u src/usr.bin/indent/indent.c:1.116 src/usr.bin/indent/indent.c:1.117
--- src/usr.bin/indent/indent.c:1.116	Thu Oct  7 21:38:25 2021
+++ src/usr.bin/indent/indent.c	Thu Oct  7 21:41:59 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.116 2021/10/07 21:38:25 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.117 2021/10/07 21:41:59 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@ static char sccsid[] = "@(#)indent.c	5.1
 
 #include 
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: indent.c,v 1.116 2021/10/07 21:38:25 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.117 2021/10/07 21:41:59 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -204,8 +204,7 @@ search_brace_lbrace(void)
 {
 /*
  * Put KNF-style lbraces before the buffered up tokens and jump out of
- * this loop in order to avoid copying the token again under the default
- * case of the switch below.
+ * this loop in order to avoid copying the token again.
  */
 if (sc_end != NULL && opt.btype_2) {
 	save_com[0] = '{';
@@ -254,15 +253,14 @@ search_brace_other(token_type ttype, boo
 	sc_end--;
 	}
 }
-if (*force_nl) {	/* if we should insert a nl here, put it into
+if (*force_nl) {		/* if we should insert a nl here, put it into
  * the buffer */
 	*force_nl = false;
 	--line_no;		/* this will be re-increased when the newline
  * is read from the buffer */
 	*sc_end++ = '\n';
 	*sc_end++ = ' ';
-	if (opt.verbose)	/* print error msg if the line was not already
- * broken */
+	if (opt.verbose)	/* warn if the line was not already broken */
 	diag(0, "Line broken");
 }
 for (const char *t_ptr = token.s; *t_ptr != '\0'; ++t_ptr)
@@ -1359,7 +1357,7 @@ main_loop(void)
 	goto copy_token;
 
 	case funcname:
-	case ident:		/* got an identifier or constant */
+	case ident:		/* an identifier, constant or string */
 	process_ident(ttype, decl_ind, tabs_to_var, _sw, _nl,
 		hd_type);
 copy_token:

Index: src/usr.bin/indent/indent_globs.h
diff -u src/usr.bin/indent/indent_globs.h:1.43 src/usr.bin/indent/indent_globs.h:1.44
--- src/usr.bin/indent/indent_globs.h:1.43	Thu Oct  7 19:35:50 2021
+++ src/usr.bin/indent/indent_globs.h	Thu Oct  7 21:41:59 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent_globs.h,v 1.43 2021/10/07 19:35:50 rillig Exp $	*/
+/*	$NetBSD: indent_globs.h,v 1.44 2021/10/07 21:41:59 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -188,7 +188,7 @@ extern boolinhibit_formatting;	/
 
 extern struct parser_state {
 token_type  last_token;
-token_type	p_stack[STACKSIZE];	/* this is the parsers stack */
+token_type	p_stack[STACKSIZE];	/* this is the parser's stack */
 int il[STACKSIZE];	/* this stack stores indentation levels */
 float   cstk[STACKSIZE];/* used to store case stmt indentation levels */
 bool	box_com;	/* whether we are in a "boxed" comment. In

Index: src/usr.bin/indent/lexi.c
diff -u src/usr.bin/indent/lexi.c:1.73 src/usr.bin/indent/lexi.c:1.74
--- src/usr.bin/indent/lexi.c:1.73	Thu Oct  7 18:32:09 2021
+++ src/usr.bin/indent/lexi.c	Thu Oct  7 21:41:59 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: lexi.c,v 1.73 2021/10/07 18:32:09 rillig Exp $	*/
+/*	$NetBSD: lexi.c,v 1.74 2021/10/07 21:41:59 

CVS commit: src/usr.bin/indent

2021-10-07 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Oct  7 21:41:59 UTC 2021

Modified Files:
src/usr.bin/indent: args.c indent.c indent_globs.h lexi.c

Log Message:
indent: fix wrong or outdated comments

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.49 -r1.50 src/usr.bin/indent/args.c
cvs rdiff -u -r1.116 -r1.117 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.43 -r1.44 src/usr.bin/indent/indent_globs.h
cvs rdiff -u -r1.73 -r1.74 src/usr.bin/indent/lexi.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/indent

2021-10-07 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Oct  7 21:38:25 UTC 2021

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

Log Message:
indent: remove redundant comments

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.115 -r1.116 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.75 -r1.76 src/usr.bin/indent/io.c
cvs rdiff -u -r1.29 -r1.30 src/usr.bin/indent/parse.c
cvs rdiff -u -r1.53 -r1.54 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.115 src/usr.bin/indent/indent.c:1.116
--- src/usr.bin/indent/indent.c:1.115	Thu Oct  7 21:16:36 2021
+++ src/usr.bin/indent/indent.c	Thu Oct  7 21:38:25 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.115 2021/10/07 21:16:36 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.116 2021/10/07 21:38:25 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@ static char sccsid[] = "@(#)indent.c	5.1
 
 #include 
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: indent.c,v 1.115 2021/10/07 21:16:36 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.116 2021/10/07 21:38:25 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -427,9 +427,8 @@ main_init_globals(void)
 {
 found_err = false;
 
-ps.p_stack[0] = stmt;	/* this is the parser's stack */
-ps.last_nl = true;		/* this is true if the last thing scanned was
- * a newline */
+ps.p_stack[0] = stmt;
+ps.last_nl = true;
 ps.last_token = semicolon;
 buf_init();
 buf_init();
@@ -597,7 +596,7 @@ process_comment_in_code(token_type ttype
 static void
 process_form_feed(void)
 {
-ps.use_ff = true;		/* a form feed is treated much like a newline */
+ps.use_ff = true;
 dump_line();
 ps.want_blank = false;
 }
@@ -610,7 +609,7 @@ process_newline(void)
 	dump_line();
 	ps.want_blank = false;
 }
-++line_no;			/* keep track of input line number */
+++line_no;
 }
 
 static bool
@@ -901,9 +900,8 @@ process_lbrace(bool *force_nl, bool *sp_
 	ps.in_decl = false;
 }
 *decl_ind = 0;
-parse(lbrace);		/* let parser know about this */
-if (ps.want_blank)		/* put a blank before '{' if '{' is not at
- * start of line */
+parse(lbrace);
+if (ps.want_blank)
 	*code.e++ = ' ';
 ps.want_blank = false;
 *code.e++ = '{';
@@ -1290,41 +1288,41 @@ main_loop(void)
 	process_rparen_or_rbracket(_sw, _nl, hd_type);
 	break;
 
-	case unary_op:		/* this could be any unary operation */
+	case unary_op:
 	process_unary_op(decl_ind, tabs_to_var);
 	break;
 
-	case binary_op:		/* any binary operation */
+	case binary_op:
 	process_binary_op();
 	break;
 
-	case postfix_op:	/* got a trailing ++ or -- */
+	case postfix_op:
 	process_postfix_op();
 	break;
 
-	case question:		/* got a ? */
+	case question:
 	process_question(_quest);
 	break;
 
 	case case_label:	/* got word 'case' or 'default' */
-	seen_case = true;	/* so we can process the later colon properly */
+	seen_case = true;
 	goto copy_token;
 
-	case colon:		/* got a ':' */
+	case colon:
 	process_colon(_quest, _nl, _case);
 	break;
 
-	case semicolon:		/* got a ';' */
+	case semicolon:
 	process_semicolon(_case, _quest, decl_ind, tabs_to_var,
 		_sw, hd_type, _nl);
 	break;
 
-	case lbrace:		/* got a '{' */
+	case lbrace:
 	process_lbrace(_nl, _sw, hd_type, di_stack,
 		(int)nitems(di_stack), _ind);
 	break;
 
-	case rbrace:		/* got a '}' */
+	case rbrace:
 	process_rbrace(_sw, _ind, di_stack);
 	break;
 

Index: src/usr.bin/indent/io.c
diff -u src/usr.bin/indent/io.c:1.75 src/usr.bin/indent/io.c:1.76
--- src/usr.bin/indent/io.c:1.75	Thu Oct  7 19:35:50 2021
+++ src/usr.bin/indent/io.c	Thu Oct  7 21:38:25 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: io.c,v 1.75 2021/10/07 19:35:50 rillig Exp $	*/
+/*	$NetBSD: io.c,v 1.76 2021/10/07 21:38:25 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@ static char sccsid[] = "@(#)io.c	8.1 (Be
 
 #include 
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: io.c,v 1.75 2021/10/07 19:35:50 rillig Exp $");
+__RCSID("$NetBSD: io.c,v 1.76 2021/10/07 21:38:25 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/io.c 334927 2018-06-10 16:44:18Z pstef $");
 #endif
@@ -257,14 +257,8 @@ dump_line(void)
 	&& token.s < token.e && isspace((unsigned char)token.s[0]))
 	output_range(token.s, token.e);
 
-ps.decl_on_line = ps.in_decl;	/* if we are in the middle of a
-	 * declaration, remember that fact for
-	 * proper comment indentation */
-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 

CVS commit: src/usr.bin/indent

2021-10-07 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Oct  7 21:38:25 UTC 2021

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

Log Message:
indent: remove redundant comments

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.115 -r1.116 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.75 -r1.76 src/usr.bin/indent/io.c
cvs rdiff -u -r1.29 -r1.30 src/usr.bin/indent/parse.c
cvs rdiff -u -r1.53 -r1.54 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.



CVS commit: src/usr.bin/indent

2021-10-07 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Oct  7 21:16:36 UTC 2021

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

Log Message:
indent: reduce indentation

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.114 -r1.115 src/usr.bin/indent/indent.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/indent

2021-10-07 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Oct  7 21:16:36 UTC 2021

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

Log Message:
indent: reduce indentation

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.114 -r1.115 src/usr.bin/indent/indent.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.114 src/usr.bin/indent/indent.c:1.115
--- src/usr.bin/indent/indent.c:1.114	Thu Oct  7 19:42:41 2021
+++ src/usr.bin/indent/indent.c	Thu Oct  7 21:16:36 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.114 2021/10/07 19:42:41 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.115 2021/10/07 21:16:36 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@ static char sccsid[] = "@(#)indent.c	5.1
 
 #include 
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: indent.c,v 1.114 2021/10/07 19:42:41 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.115 2021/10/07 21:16:36 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -287,46 +287,43 @@ switch_buffer(void)
 static void
 search_brace_lookahead(token_type *ttype)
 {
+if (*ttype == end_of_file)
+	return;
+
 /*
- * We must make this check, just in case there was an unexpected EOF.
+ * The only intended purpose of calling lexi() below is to categorize
+ * the next token in order to decide whether to continue buffering
+ * forthcoming tokens. Once the buffering is over, lexi() will be
+ * called again elsewhere on all of the tokens - this time for normal
+ * processing.
+ *
+ * Calling it for this purpose is a bug, because lexi() also changes
+ * the parser state and discards leading whitespace, which is needed
+ * mostly for comment-related considerations.
+ *
+ * Work around the former problem by giving lexi() a copy of the
+ * current parser state and discard it if the call turned out to be
+ * just a lookahead.
+ *
+ * Work around the latter problem by copying all whitespace characters
+ * into the buffer so that the later lexi() call will read them.
  */
-if (*ttype != end_of_file) {
-	/*
-	 * The only intended purpose of calling lexi() below is to categorize
-	 * the next token in order to decide whether to continue buffering
-	 * forthcoming tokens. Once the buffering is over, lexi() will be
-	 * called again elsewhere on all of the tokens - this time for normal
-	 * processing.
-	 *
-	 * Calling it for this purpose is a bug, because lexi() also changes
-	 * the parser state and discards leading whitespace, which is needed
-	 * mostly for comment-related considerations.
-	 *
-	 * Work around the former problem by giving lexi() a copy of the
-	 * current parser state and discard it if the call turned out to be
-	 * just a look ahead.
-	 *
-	 * Work around the latter problem by copying all whitespace characters
-	 * into the buffer so that the later lexi() call will read them.
-	 */
-	if (sc_end != NULL) {
-	while (is_hspace(*buf_ptr)) {
-		*sc_end++ = *buf_ptr++;
-		if (sc_end >= _com[sc_size]) {
-		errx(1, "input too long");
-		}
-	}
-	if (buf_ptr >= buf_end)
-		fill_buffer();
+if (sc_end != NULL) {
+	while (is_hspace(*buf_ptr)) {
+	*sc_end++ = *buf_ptr++;
+	if (sc_end >= _com[sc_size])
+		errx(1, "input too long");
 	}
+	if (buf_ptr >= buf_end)
+	fill_buffer();
+}
 
-	struct parser_state transient_state;
-	transient_state = ps;
-	*ttype = lexi(_state);	/* read another token */
-	if (*ttype != newline && *ttype != form_feed &&
-	*ttype != comment && !transient_state.search_brace) {
-	ps = transient_state;
-	}
+struct parser_state transient_state;
+transient_state = ps;
+*ttype = lexi(_state);	/* read another token */
+if (*ttype != newline && *ttype != form_feed &&
+	*ttype != comment && !transient_state.search_brace) {
+	ps = transient_state;
 }
 }
 
@@ -346,13 +343,13 @@ search_brace(token_type *ttype, bool *fo
 	break;
 	case lbrace:
 	if (search_brace_lbrace())
-		goto sw_buffer;
+		goto switch_buffer;
 	/* FALLTHROUGH */
 	default:		/* it is the start of a normal statement */
 	if (!search_brace_other(*ttype, force_nl,
 		*comment_buffered, *last_else))
 		return;
-	sw_buffer:
+	switch_buffer:
 	switch_buffer();
 	}
 	search_brace_lookahead(ttype);
@@ -1086,91 +1083,95 @@ process_comma(int decl_ind, bool tabs_to
 
 /* move the whole line to the 'label' buffer */
 static void
-process_preprocessing(void)
+read_preprocessing_line(void)
 {
-if (com.s != com.e || lab.s != lab.e || code.s != code.e)
-	dump_line();
-
 buf_add_char(, '#');
 
-{
-	bool in_comment = false;
-	int com_start = 0;
-	char quote = '\0';
-	int com_end = 0;
-
-	while (is_hspace(*buf_ptr))
-	inbuf_skip();
-

CVS commit: src/usr.bin/indent

2021-10-07 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Oct  7 19:42:42 UTC 2021

Modified Files:
src/usr.bin/indent: args.c indent.c indent.h

Log Message:
indent: remove global variable option_source

It is only needed at startup, while parsing the options. The string "?"
was not needed at all.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.48 -r1.49 src/usr.bin/indent/args.c
cvs rdiff -u -r1.113 -r1.114 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.29 -r1.30 src/usr.bin/indent/indent.h

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.48 src/usr.bin/indent/args.c:1.49
--- src/usr.bin/indent/args.c:1.48	Thu Oct  7 18:32:09 2021
+++ src/usr.bin/indent/args.c	Thu Oct  7 19:42:41 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: args.c,v 1.48 2021/10/07 18:32:09 rillig Exp $	*/
+/*	$NetBSD: args.c,v 1.49 2021/10/07 19:42:41 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@ static char sccsid[] = "@(#)args.c	8.1 (
 
 #include 
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: args.c,v 1.48 2021/10/07 18:32:09 rillig Exp $");
+__RCSID("$NetBSD: args.c,v 1.49 2021/10/07 19:42:41 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/args.c 336318 2018-07-15 21:04:21Z pstef $");
 #endif
@@ -66,8 +66,6 @@ __FBSDID("$FreeBSD: head/usr.bin/indent/
 
 void add_typedefs_from_file(const char *);
 
-static const char *option_source = "?";
-
 #if __STDC_VERSION__ >= 201112L
 #define assert_type(expr, type) _Generic((expr), type : (expr))
 #else
@@ -149,7 +147,6 @@ load_profile(const char *fname, bool mus
 	err(EXIT_FAILURE, "profile %s", fname);
 	return;
 }
-option_source = fname;
 
 for (;;) {
 	char buf[BUFSIZ];
@@ -166,7 +163,7 @@ load_profile(const char *fname, bool mus
 		break;
 	} else if (n >= nitems(buf) - 5) {
 		diag(1, "buffer overflow in %s, starting with '%.10s'",
-		 option_source, buf);
+		 fname, buf);
 		exit(1);
 	} else
 		buf[n++] = (char)ch;
@@ -176,7 +173,7 @@ load_profile(const char *fname, bool mus
 	buf[n] = '\0';
 	if (opt.verbose)
 		printf("profile: %s\n", buf);
-	set_option(buf);
+	set_option(buf, fname);
 	} else if (ch == EOF)
 	break;
 }
@@ -195,7 +192,6 @@ load_profiles(const char *profile_name)
 	load_profile(fname, false);
 }
 load_profile(".indent.pro", false);
-option_source = "Command line";
 }
 
 static const char *
@@ -211,7 +207,7 @@ skip_over(const char *s, bool may_negate
 }
 
 static bool
-set_special_option(const char *arg)
+set_special_option(const char *arg, const char *option_source)
 {
 const char *arg_end;
 
@@ -265,13 +261,13 @@ need_param:
 }
 
 void
-set_option(const char *arg)
+set_option(const char *arg, const char *option_source)
 {
 const struct pro *p;
 const char *param_start;
 
 arg++;			/* skip leading '-' */
-if (set_special_option(arg))
+if (set_special_option(arg, option_source))
 	return;
 
 for (p = pro + nitems(pro); p-- != pro;) {

Index: src/usr.bin/indent/indent.c
diff -u src/usr.bin/indent/indent.c:1.113 src/usr.bin/indent/indent.c:1.114
--- src/usr.bin/indent/indent.c:1.113	Thu Oct  7 19:35:50 2021
+++ src/usr.bin/indent/indent.c	Thu Oct  7 19:42:41 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.113 2021/10/07 19:35:50 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.114 2021/10/07 19:42:41 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@ static char sccsid[] = "@(#)indent.c	5.1
 
 #include 
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: indent.c,v 1.113 2021/10/07 19:35:50 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.114 2021/10/07 19:42:41 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -476,7 +476,7 @@ main_parse_command_line(int argc, char *
 
 for (i = 1; i < argc; ++i) {
 	if (argv[i][0] == '-') {
-	set_option(argv[i]);
+	set_option(argv[i], "Command line");
 
 	} else if (input == NULL) {
 	in_name = argv[i];

Index: src/usr.bin/indent/indent.h
diff -u src/usr.bin/indent/indent.h:1.29 src/usr.bin/indent/indent.h:1.30
--- src/usr.bin/indent/indent.h:1.29	Tue Oct  5 06:09:42 2021
+++ src/usr.bin/indent/indent.h	Thu Oct  7 19:42:41 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.h,v 1.29 2021/10/05 06:09:42 rillig Exp $	*/
+/*	$NetBSD: indent.h,v 1.30 2021/10/07 19:42:41 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -65,7 +65,7 @@ void		dump_line(void);
 void		fill_buffer(void);
 void		parse(token_type);
 void		process_comment(void);
-void		set_option(const char *);
+void		set_option(const char *, const char *);
 void		load_profiles(const char *);
 
 void		*xmalloc(size_t);



CVS commit: src/usr.bin/indent

2021-10-07 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Oct  7 19:42:42 UTC 2021

Modified Files:
src/usr.bin/indent: args.c indent.c indent.h

Log Message:
indent: remove global variable option_source

It is only needed at startup, while parsing the options. The string "?"
was not needed at all.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.48 -r1.49 src/usr.bin/indent/args.c
cvs rdiff -u -r1.113 -r1.114 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.29 -r1.30 src/usr.bin/indent/indent.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/indent

2021-10-07 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Oct  7 19:35:50 UTC 2021

Modified Files:
src/usr.bin/indent: indent.c indent_globs.h io.c

Log Message:
indent: clean up colon handling

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.112 -r1.113 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.42 -r1.43 src/usr.bin/indent/indent_globs.h
cvs rdiff -u -r1.74 -r1.75 src/usr.bin/indent/io.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.112 src/usr.bin/indent/indent.c:1.113
--- src/usr.bin/indent/indent.c:1.112	Thu Oct  7 19:17:07 2021
+++ src/usr.bin/indent/indent.c	Thu Oct  7 19:35:50 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.112 2021/10/07 19:17:07 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.113 2021/10/07 19:35:50 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@ static char sccsid[] = "@(#)indent.c	5.1
 
 #include 
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: indent.c,v 1.112 2021/10/07 19:17:07 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.113 2021/10/07 19:35:50 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -448,7 +448,7 @@ main_init_globals(void)
 ps.in_or_st = false;
 ps.want_blank = ps.in_stmt = ps.ind_stmt = false;
 
-ps.pcase = false;
+ps.is_case_label = false;
 sc_end = NULL;
 bp_save = NULL;
 be_save = NULL;
@@ -760,7 +760,7 @@ process_question(int *seen_quest)
 static void
 process_colon(int *seen_quest, bool *force_nl, bool *seen_case)
 {
-if (*seen_quest > 0) {	/* it is part of the ?:  construct */
+if (*seen_quest > 0) {	/* part of a '?:' operator */
 	--*seen_quest;
 	if (ps.want_blank)
 	*code.e++ = ' ';
@@ -768,24 +768,21 @@ process_colon(int *seen_quest, bool *for
 	ps.want_blank = true;
 	return;
 }
-if (ps.in_or_st) {
+
+if (ps.in_or_st) {		/* bit-field */
 	*code.e++ = ':';
 	ps.want_blank = false;
 	return;
 }
-ps.in_stmt = false;		/* seeing a label does not imply we are in a
- * stmt */
 
-/* turn everything so far into a label */
-buf_add_buf(, );
+buf_add_buf(, );	/* 'case' or 'default' or named label */
 buf_add_char(, ':');
 buf_terminate();
 buf_reset();
 
-ps.pcase = *seen_case;	/* will be used by dump_line to decide how to
- * indent the label. */
-*force_nl = *seen_case;	/* will force a 'case n:' to be on a
- * line by itself */
+ps.in_stmt = false;
+ps.is_case_label = *seen_case;
+*force_nl = *seen_case;
 *seen_case = false;
 ps.want_blank = false;
 }
@@ -1172,7 +1169,7 @@ process_preprocessing(void)
 	debug_println("switched buf_ptr to save_com");
 	}
 	buf_terminate();
-	ps.pcase = false;
+	ps.is_case_label = false;
 }
 
 if (strncmp(lab.s, "#if", 3) == 0) {	/* also ifdef, ifndef */

Index: src/usr.bin/indent/indent_globs.h
diff -u src/usr.bin/indent/indent_globs.h:1.42 src/usr.bin/indent/indent_globs.h:1.43
--- src/usr.bin/indent/indent_globs.h:1.42	Tue Oct  5 18:50:42 2021
+++ src/usr.bin/indent/indent_globs.h	Thu Oct  7 19:35:50 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent_globs.h,v 1.42 2021/10/05 18:50:42 rillig Exp $	*/
+/*	$NetBSD: indent_globs.h,v 1.43 2021/10/07 19:35:50 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -240,9 +240,8 @@ extern struct parser_state {
 short   paren_indents[20]; /* indentation of the operand/argument of
  * each level of parentheses or brackets,
  * relative to the enclosing statement */
-bool	pcase;		/* whether the current line label is a
- * case.  It is printed differently from a
- * regular label */
+bool	is_case_label;	/* 'case' and 'default' labels are indented
+ * differently from regular labels */
 bool	search_brace;	/* whether it is necessary
  * to buffer up all info up to the start of a
  * stmt after an if, while, etc */

Index: src/usr.bin/indent/io.c
diff -u src/usr.bin/indent/io.c:1.74 src/usr.bin/indent/io.c:1.75
--- src/usr.bin/indent/io.c:1.74	Thu Oct  7 18:32:09 2021
+++ src/usr.bin/indent/io.c	Thu Oct  7 19:35:50 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: io.c,v 1.74 2021/10/07 18:32:09 rillig Exp $	*/
+/*	$NetBSD: io.c,v 1.75 2021/10/07 19:35:50 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@ static char sccsid[] = "@(#)io.c	8.1 (Be
 
 #include 
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: io.c,v 1.74 2021/10/07 18:32:09 rillig Exp $");
+__RCSID("$NetBSD: io.c,v 1.75 2021/10/07 19:35:50 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/io.c 334927 2018-06-10 16:44:18Z pstef $");
 #endif
@@ -181,7 +181,7 @@ dump_line(void)
 	} else
 	cur_col = 1;	/* there is no label section */
 
-	ps.pcase = false;
+	ps.is_case_label = 

CVS commit: src/usr.bin/indent

2021-10-07 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Oct  7 19:35:50 UTC 2021

Modified Files:
src/usr.bin/indent: indent.c indent_globs.h io.c

Log Message:
indent: clean up colon handling

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.112 -r1.113 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.42 -r1.43 src/usr.bin/indent/indent_globs.h
cvs rdiff -u -r1.74 -r1.75 src/usr.bin/indent/io.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/indent

2021-10-07 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Oct  7 19:17:07 UTC 2021

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

Log Message:
indent: add high-level API for working with buffers

This makes the code more boring to read, which is actually good. Less
fiddling with memcpy and pointer arithmetics.

Since indent is not a high-performance tool used for bulk operations on
terabytes of source code, there is no need to squeeze out every possible
CPU cycle.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.111 -r1.112 src/usr.bin/indent/indent.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.111 src/usr.bin/indent/indent.c:1.112
--- src/usr.bin/indent/indent.c:1.111	Thu Oct  7 18:48:31 2021
+++ src/usr.bin/indent/indent.c	Thu Oct  7 19:17:07 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.111 2021/10/07 18:48:31 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.112 2021/10/07 19:17:07 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@ static char sccsid[] = "@(#)indent.c	5.1
 
 #include 
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: indent.c,v 1.111 2021/10/07 18:48:31 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.112 2021/10/07 19:17:07 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -128,20 +128,6 @@ static const char *out_name = "Standard 
 static const char *backup_suffix = ".BAK";
 static char bakfile[MAXPATHLEN] = "";
 
-static void
-check_size_code(size_t desired_size)
-{
-if (code.e + desired_size >= code.l)
-	buf_expand(, desired_size);
-}
-
-static void
-check_size_label(size_t desired_size)
-{
-if (lab.e + desired_size >= lab.l)
-	buf_expand(, desired_size);
-}
-
 #if HAVE_CAPSICUM
 static void
 init_capsicum(void)
@@ -404,6 +390,42 @@ buf_expand(struct buffer *buf, size_t de
 }
 
 static void
+buf_reserve(struct buffer *buf, size_t n)
+{
+if (buf->e + n >= buf->l)
+	buf_expand(buf, n);
+}
+
+static void
+buf_add_char(struct buffer *buf, char ch)
+{
+buf_reserve(buf, 1);
+*buf->e++ = ch;
+}
+
+static void
+buf_add_buf(struct buffer *buf, const struct buffer *add)
+{
+size_t len = buf_len(add);
+buf_reserve(buf, len);
+memcpy(buf->e, add->s, len);
+buf->e += len;
+}
+
+static void
+buf_terminate(struct buffer *buf)
+{
+buf_reserve(buf, 1);
+*buf->e = '\0';
+}
+
+static void
+buf_reset(struct buffer *buf)
+{
+buf->e = buf->s;
+}
+
+static void
 main_init_globals(void)
 {
 found_err = false;
@@ -566,16 +588,12 @@ process_comment_in_code(token_type ttype
  * '}' */
 if (com.s != com.e) {	/* the turkey has embedded a comment in a
  * line. fix it */
-	size_t len = buf_len();
-
-	check_size_code(len + 3);
-	*code.e++ = ' ';
-	memcpy(code.e, com.s, len);
-	code.e += len;
-	*code.e++ = ' ';
-	*code.e = '\0';
+	buf_add_char(, ' ');
+	buf_add_buf(, );
+	buf_add_char(, ' ');
+	buf_terminate();
+	buf_reset();
 	ps.want_blank = false;
-	com.e = com.s;
 }
 }
 
@@ -706,27 +724,16 @@ process_unary_op(int decl_ind, bool tabs
 } else if (ps.want_blank)
 	*code.e++ = ' ';
 
-{
-	size_t len = buf_len();
-
-	check_size_code(len);
-	memcpy(code.e, token.s, len);
-	code.e += len;
-}
+buf_add_buf(, );
 ps.want_blank = false;
 }
 
 static void
 process_binary_op(void)
 {
-size_t len = buf_len();
-
-check_size_code(len + 1);
 if (ps.want_blank)
-	*code.e++ = ' ';
-memcpy(code.e, token.s, len);
-code.e += len;
-
+	buf_add_char(, ' ');
+buf_add_buf(, );
 ps.want_blank = true;
 }
 
@@ -768,19 +775,13 @@ process_colon(int *seen_quest, bool *for
 }
 ps.in_stmt = false;		/* seeing a label does not imply we are in a
  * stmt */
-/*
- * turn everything so far into a label
- */
-{
-	size_t len = buf_len();
 
-	check_size_label(len + 3);
-	memcpy(lab.e, code.s, len);
-	lab.e += len;
-	*lab.e++ = ':';
-	*lab.e = '\0';
-	code.e = code.s;
-}
+/* turn everything so far into a label */
+buf_add_buf(, );
+buf_add_char(, ':');
+buf_terminate();
+buf_reset();
+
 ps.pcase = *seen_case;	/* will be used by dump_line to decide how to
  * indent the label. */
 *force_nl = *seen_case;	/* will force a 'case n:' to be on a
@@ -1042,26 +1043,15 @@ process_ident(token_type ttype, int decl
 static void
 copy_token(void)
 {
-size_t len = buf_len();
-
-check_size_code(len + 1);
 if (ps.want_blank)
-	*code.e++ = ' ';
-memcpy(code.e, token.s, len);
-code.e += len;
+	buf_add_char(, ' ');
+buf_add_buf(, );
 }
 
 static void
 process_string_prefix(void)
 {
-size_t len = buf_len();
-
-check_size_code(len + 1);
-if (ps.want_blank)
-	*code.e++ = ' ';
-memcpy(code.e, token.s, len);
-code.e += len;
-
+copy_token();

CVS commit: src/usr.bin/indent

2021-10-07 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Oct  7 19:17:07 UTC 2021

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

Log Message:
indent: add high-level API for working with buffers

This makes the code more boring to read, which is actually good. Less
fiddling with memcpy and pointer arithmetics.

Since indent is not a high-performance tool used for bulk operations on
terabytes of source code, there is no need to squeeze out every possible
CPU cycle.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.111 -r1.112 src/usr.bin/indent/indent.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/indent

2021-10-07 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Oct  7 18:48:32 UTC 2021

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

Log Message:
indent: rename copy_id to copy_token

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.110 -r1.111 src/usr.bin/indent/indent.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/indent

2021-10-07 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Oct  7 18:48:32 UTC 2021

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

Log Message:
indent: rename copy_id to copy_token

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.110 -r1.111 src/usr.bin/indent/indent.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.110 src/usr.bin/indent/indent.c:1.111
--- src/usr.bin/indent/indent.c:1.110	Thu Oct  7 18:32:09 2021
+++ src/usr.bin/indent/indent.c	Thu Oct  7 18:48:31 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.110 2021/10/07 18:32:09 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.111 2021/10/07 18:48:31 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@ static char sccsid[] = "@(#)indent.c	5.1
 
 #include 
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: indent.c,v 1.110 2021/10/07 18:32:09 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.111 2021/10/07 18:48:31 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -1040,7 +1040,7 @@ process_ident(token_type ttype, int decl
 }
 
 static void
-copy_id(void)
+copy_token(void)
 {
 size_t len = buf_len();
 
@@ -1327,7 +1327,7 @@ main_loop(void)
 
 	case case_label:	/* got word 'case' or 'default' */
 	seen_case = true;	/* so we can process the later colon properly */
-	goto copy_id;
+	goto copy_token;
 
 	case colon:		/* got a ':' */
 	process_colon(_quest, _nl, _case);
@@ -1351,7 +1351,7 @@ main_loop(void)
 	sp_sw = true;
 	hd_type = switch_expr;	/* keep this for when we have seen the
 	 * expression */
-	goto copy_id;	/* go move the token into buffer */
+	goto copy_token;
 
 	case keyword_for_if_while:
 	sp_sw = true;	/* the interesting stuff is done after the
@@ -1360,31 +1360,31 @@ main_loop(void)
 		(*token.s == 'w' ? while_expr : for_exprs));
 
 	/* remember the type of header for later use by parser */
-	goto copy_id;	/* copy the token into line */
+	goto copy_token;
 
 	case keyword_do_else:
 	process_keyword_do_else(_nl, _else);
-	goto copy_id;	/* move the token into line */
+	goto copy_token;
 
 	case type_def:
 	case storage_class:
 	prefix_blankline_requested = false;
-	goto copy_id;
+	goto copy_token;
 
 	case keyword_struct_union_enum:
 	if (ps.p_l_follow > 0)
-		goto copy_id;
+		goto copy_token;
 	/* FALLTHROUGH */
 	case decl:		/* we have a declaration type (int, etc.) */
 	process_decl(_ind, _to_var);
-	goto copy_id;
+	goto copy_token;
 
 	case funcname:
 	case ident:		/* got an identifier or constant */
 	process_ident(ttype, decl_ind, tabs_to_var, _sw, _nl,
 		hd_type);
-copy_id:
-	copy_id();
+copy_token:
+	copy_token();
 	if (ttype != funcname)
 		ps.want_blank = true;
 	break;



CVS commit: src/usr.bin/indent

2021-10-07 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Oct  7 18:32:09 UTC 2021

Modified Files:
src/usr.bin/indent: Makefile args.c indent.c io.c lexi.c

Log Message:
indent: raise WARNS from the default 5 up to 6


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/usr.bin/indent/Makefile
cvs rdiff -u -r1.47 -r1.48 src/usr.bin/indent/args.c
cvs rdiff -u -r1.109 -r1.110 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.73 -r1.74 src/usr.bin/indent/io.c
cvs rdiff -u -r1.72 -r1.73 src/usr.bin/indent/lexi.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.13 src/usr.bin/indent/Makefile:1.14
--- src/usr.bin/indent/Makefile:1.13	Sat Sep 25 17:11:23 2021
+++ src/usr.bin/indent/Makefile	Thu Oct  7 18:32:09 2021
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.13 2021/09/25 17:11:23 rillig Exp $
+#	$NetBSD: Makefile,v 1.14 2021/10/07 18:32:09 rillig Exp $
 #	from: @(#)Makefile	8.1 (Berkeley) 6/6/93
 
 PROG=	indent
@@ -6,5 +6,6 @@ SRCS=	indent.c io.c lexi.c parse.c pr_co
 
 CPPFLAGS+=	${DEBUG:D-Ddebug}
 LINTFLAGS+=	-e -w -T
+WARNS=		6
 
 .include 

Index: src/usr.bin/indent/args.c
diff -u src/usr.bin/indent/args.c:1.47 src/usr.bin/indent/args.c:1.48
--- src/usr.bin/indent/args.c:1.47	Thu Oct  7 18:07:25 2021
+++ src/usr.bin/indent/args.c	Thu Oct  7 18:32:09 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: args.c,v 1.47 2021/10/07 18:07:25 rillig Exp $	*/
+/*	$NetBSD: args.c,v 1.48 2021/10/07 18:32:09 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@ static char sccsid[] = "@(#)args.c	8.1 (
 
 #include 
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: args.c,v 1.47 2021/10/07 18:07:25 rillig Exp $");
+__RCSID("$NetBSD: args.c,v 1.48 2021/10/07 18:32:09 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/args.c 336318 2018-07-15 21:04:21Z pstef $");
 #endif
@@ -228,7 +228,7 @@ set_special_option(const char *arg)
 	arg_end = arg + 3;
 	if (arg_end[0] == '\0')
 	goto need_param;
-	opt.case_indent = atof(arg_end);
+	opt.case_indent = (float)atof(arg_end);
 	return true;
 }
 

Index: src/usr.bin/indent/indent.c
diff -u src/usr.bin/indent/indent.c:1.109 src/usr.bin/indent/indent.c:1.110
--- src/usr.bin/indent/indent.c:1.109	Thu Oct  7 18:19:07 2021
+++ src/usr.bin/indent/indent.c	Thu Oct  7 18:32:09 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.109 2021/10/07 18:19:07 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.110 2021/10/07 18:32:09 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@ static char sccsid[] = "@(#)indent.c	5.1
 
 #include 
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: indent.c,v 1.109 2021/10/07 18:19:07 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.110 2021/10/07 18:32:09 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -386,13 +386,19 @@ buf_init(struct buffer *buf)
 buf->l = buf->buf + bufsize - 5;	/* safety margin, though unreliable */
 }
 
+static size_t
+buf_len(const struct buffer *buf)
+{
+return (size_t)(buf->e - buf->s);
+}
+
 void
 buf_expand(struct buffer *buf, size_t desired_size)
 {
-size_t nsize = buf->l - buf->s + 400 + desired_size;
-size_t code_len = buf->e - buf->s;
+size_t nsize = (size_t)(buf->l - buf->s) + 400 + desired_size;
+size_t len = buf_len(buf);
 buf->buf = xrealloc(buf->buf, nsize);
-buf->e = buf->buf + code_len + 1;
+buf->e = buf->buf + len + 1;
 buf->l = buf->buf + nsize - 5;
 buf->s = buf->buf + 1;
 }
@@ -560,7 +566,7 @@ process_comment_in_code(token_type ttype
  * '}' */
 if (com.s != com.e) {	/* the turkey has embedded a comment in a
  * line. fix it */
-	size_t len = com.e - com.s;
+	size_t len = buf_len();
 
 	check_size_code(len + 3);
 	*code.e++ = ' ';
@@ -701,7 +707,7 @@ process_unary_op(int decl_ind, bool tabs
 	*code.e++ = ' ';
 
 {
-	size_t len = token.e - token.s;
+	size_t len = buf_len();
 
 	check_size_code(len);
 	memcpy(code.e, token.s, len);
@@ -713,7 +719,7 @@ process_unary_op(int decl_ind, bool tabs
 static void
 process_binary_op(void)
 {
-size_t len = token.e - token.s;
+size_t len = buf_len();
 
 check_size_code(len + 1);
 if (ps.want_blank)
@@ -766,7 +772,7 @@ process_colon(int *seen_quest, bool *for
  * turn everything so far into a label
  */
 {
-	size_t len = code.e - code.s;
+	size_t len = buf_len();
 
 	check_size_label(len + 3);
 	memcpy(lab.e, code.s, len);
@@ -1036,7 +1042,7 @@ process_ident(token_type ttype, int decl
 static void
 copy_id(void)
 {
-size_t len = token.e - token.s;
+size_t len = buf_len();
 
 check_size_code(len + 1);
 if (ps.want_blank)
@@ -1048,7 +1054,7 @@ copy_id(void)
 static void
 process_string_prefix(void)
 {
-size_t len = token.e - token.s;
+size_t len = 

CVS commit: src/usr.bin/indent

2021-10-07 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Oct  7 18:32:09 UTC 2021

Modified Files:
src/usr.bin/indent: Makefile args.c indent.c io.c lexi.c

Log Message:
indent: raise WARNS from the default 5 up to 6


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/usr.bin/indent/Makefile
cvs rdiff -u -r1.47 -r1.48 src/usr.bin/indent/args.c
cvs rdiff -u -r1.109 -r1.110 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.73 -r1.74 src/usr.bin/indent/io.c
cvs rdiff -u -r1.72 -r1.73 src/usr.bin/indent/lexi.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/indent

2021-10-07 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Oct  7 18:19:07 UTC 2021

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

Log Message:
indent: prevent division by zero


To generate a diff of this commit:
cvs rdiff -u -r1.108 -r1.109 src/usr.bin/indent/indent.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.108 src/usr.bin/indent/indent.c:1.109
--- src/usr.bin/indent/indent.c:1.108	Tue Oct  5 18:50:42 2021
+++ src/usr.bin/indent/indent.c	Thu Oct  7 18:19:07 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.108 2021/10/05 18:50:42 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.109 2021/10/07 18:19:07 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@ static char sccsid[] = "@(#)indent.c	5.1
 
 #include 
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: indent.c,v 1.108 2021/10/05 18:50:42 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.109 2021/10/07 18:19:07 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -491,6 +491,10 @@ main_parse_command_line(int argc, char *
 	: opt.comment_column;
 if (opt.continuation_indent == 0)
 	opt.continuation_indent = opt.indent_size;
+if (!(1 <= opt.tabsize && opt.tabsize <= 80))
+	errx(EXIT_FAILURE, "invalid tabsize %d", opt.tabsize);
+if (!(1 <= opt.indent_size && opt.indent_size <= 80))
+	errx(EXIT_FAILURE, "invalid indentation %d", opt.indent_size);
 }
 
 static void



CVS commit: src/usr.bin/indent

2021-10-07 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Oct  7 18:19:07 UTC 2021

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

Log Message:
indent: prevent division by zero


To generate a diff of this commit:
cvs rdiff -u -r1.108 -r1.109 src/usr.bin/indent/indent.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src

2021-10-07 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Oct  7 18:07:25 UTC 2021

Modified Files:
src/distrib/sets/lists/tests: mi
src/tests/usr.bin/indent: Makefile
src/usr.bin/indent: args.c
Added Files:
src/tests/usr.bin/indent: opt.0 opt.0.pro opt.0.stdout

Log Message:
tests/indent: test parsing of command line options in profile file


To generate a diff of this commit:
cvs rdiff -u -r1.1132 -r1.1133 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.12 -r1.13 src/tests/usr.bin/indent/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/usr.bin/indent/opt.0 \
src/tests/usr.bin/indent/opt.0.pro src/tests/usr.bin/indent/opt.0.stdout
cvs rdiff -u -r1.46 -r1.47 src/usr.bin/indent/args.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/distrib/sets/lists/tests/mi
diff -u src/distrib/sets/lists/tests/mi:1.1132 src/distrib/sets/lists/tests/mi:1.1133
--- src/distrib/sets/lists/tests/mi:1.1132	Tue Oct  5 17:09:45 2021
+++ src/distrib/sets/lists/tests/mi	Thu Oct  7 18:07:25 2021
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1132 2021/10/05 17:09:45 rillig Exp $
+# $NetBSD: mi,v 1.1133 2021/10/07 18:07:25 rillig Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -4985,6 +4985,9 @@
 ./usr/tests/usr.bin/indent/opt-v.0	tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/indent/opt-v.0.pro	tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/indent/opt-v.0.stdouttests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/indent/opt.0	tests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/indent/opt.0.pro	tests-usr.bin-tests	compattestfile,atf
+./usr/tests/usr.bin/indent/opt.0.stdout	tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/indent/parens.0	tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/indent/parens.0.pro	tests-usr.bin-tests	compattestfile,atf
 ./usr/tests/usr.bin/indent/parens.0.stdouttests-usr.bin-tests	compattestfile,atf

Index: src/tests/usr.bin/indent/Makefile
diff -u src/tests/usr.bin/indent/Makefile:1.12 src/tests/usr.bin/indent/Makefile:1.13
--- src/tests/usr.bin/indent/Makefile:1.12	Tue Oct  5 17:09:45 2021
+++ src/tests/usr.bin/indent/Makefile	Thu Oct  7 18:07:25 2021
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.12 2021/10/05 17:09:45 rillig Exp $
+#	$NetBSD: Makefile,v 1.13 2021/10/07 18:07:25 rillig Exp $
 
 .include 
 
@@ -261,6 +261,9 @@ FILES+=		opt-ut.0.stdout
 FILES+=		opt-v.0
 FILES+=		opt-v.0.pro
 FILES+=		opt-v.0.stdout
+FILES+=		opt.0
+FILES+=		opt.0.pro
+FILES+=		opt.0.stdout
 FILES+=		parens.0
 FILES+=		parens.0.stdout
 FILES+=		parens.0.pro

Index: src/usr.bin/indent/args.c
diff -u src/usr.bin/indent/args.c:1.46 src/usr.bin/indent/args.c:1.47
--- src/usr.bin/indent/args.c:1.46	Thu Oct  7 17:38:21 2021
+++ src/usr.bin/indent/args.c	Thu Oct  7 18:07:25 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: args.c,v 1.46 2021/10/07 17:38:21 rillig Exp $	*/
+/*	$NetBSD: args.c,v 1.47 2021/10/07 18:07:25 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@ static char sccsid[] = "@(#)args.c	8.1 (
 
 #include 
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: args.c,v 1.46 2021/10/07 17:38:21 rillig Exp $");
+__RCSID("$NetBSD: args.c,v 1.47 2021/10/07 18:07:25 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/args.c 336318 2018-07-15 21:04:21Z pstef $");
 #endif
@@ -282,9 +282,10 @@ set_option(const char *arg)
 errx(1, "%s: unknown parameter \"%s\"", option_source, arg - 1);
 
 found:
-if (p->p_is_bool)
+if (p->p_is_bool) {
+	/* XXX: Trailing garbage in param_start is silently ignored. */
 	*(bool *)p->p_var = p->p_may_negate ? arg[0] != 'n' : p->p_bool_value;
-else {
+} else {
 	if (!isdigit((unsigned char)*param_start))
 	errx(1, "%s: ``%s'' requires a parameter",
 		option_source, p->p_name);

Added files:

Index: src/tests/usr.bin/indent/opt.0
diff -u /dev/null src/tests/usr.bin/indent/opt.0:1.1
--- /dev/null	Thu Oct  7 18:07:25 2021
+++ src/tests/usr.bin/indent/opt.0	Thu Oct  7 18:07:25 2021
@@ -0,0 +1,12 @@
+/* $NetBSD: opt.0,v 1.1 2021/10/07 18:07:25 rillig Exp $ */
+/* $FreeBSD$ */
+
+/*
+ * Test parsing of command line options from a profile file.
+ */
+
+int global_var;
+
+int function(int expr) {
+switch (expr) { case 1: return 1; default: return 0; }
+}
Index: src/tests/usr.bin/indent/opt.0.pro
diff -u /dev/null src/tests/usr.bin/indent/opt.0.pro:1.1
--- /dev/null	Thu Oct  7 18:07:25 2021
+++ src/tests/usr.bin/indent/opt.0.pro	Thu Oct  7 18:07:25 2021
@@ -0,0 +1,27 @@
+/* $NetBSD: opt.0.pro,v 1.1 2021/10/07 18:07:25 rillig Exp $ */
+/* $FreeBSD$ */
+
+/* The latter of the two options wins. */
+-di5
+-di12
+
+/* It is possible to embed comments in the options, but nobody does that. */
+-/* comment */bacc
+-T/* define a type */custom_type
+
+/*
+ * For int or float options, trailing garbage is 

CVS commit: src

2021-10-07 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Oct  7 18:07:25 UTC 2021

Modified Files:
src/distrib/sets/lists/tests: mi
src/tests/usr.bin/indent: Makefile
src/usr.bin/indent: args.c
Added Files:
src/tests/usr.bin/indent: opt.0 opt.0.pro opt.0.stdout

Log Message:
tests/indent: test parsing of command line options in profile file


To generate a diff of this commit:
cvs rdiff -u -r1.1132 -r1.1133 src/distrib/sets/lists/tests/mi
cvs rdiff -u -r1.12 -r1.13 src/tests/usr.bin/indent/Makefile
cvs rdiff -u -r0 -r1.1 src/tests/usr.bin/indent/opt.0 \
src/tests/usr.bin/indent/opt.0.pro src/tests/usr.bin/indent/opt.0.stdout
cvs rdiff -u -r1.46 -r1.47 src/usr.bin/indent/args.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/indent

2021-10-07 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Oct  7 17:38:21 UTC 2021

Modified Files:
src/usr.bin/indent: args.c

Log Message:
indent: complain if the profile from the command line does not exist


To generate a diff of this commit:
cvs rdiff -u -r1.45 -r1.46 src/usr.bin/indent/args.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.45 src/usr.bin/indent/args.c:1.46
--- src/usr.bin/indent/args.c:1.45	Thu Oct  7 17:31:33 2021
+++ src/usr.bin/indent/args.c	Thu Oct  7 17:38:21 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: args.c,v 1.45 2021/10/07 17:31:33 rillig Exp $	*/
+/*	$NetBSD: args.c,v 1.46 2021/10/07 17:38:21 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@ static char sccsid[] = "@(#)args.c	8.1 (
 
 #include 
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: args.c,v 1.45 2021/10/07 17:31:33 rillig Exp $");
+__RCSID("$NetBSD: args.c,v 1.46 2021/10/07 17:38:21 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/args.c 336318 2018-07-15 21:04:21Z pstef $");
 #endif
@@ -140,12 +140,15 @@ static const struct pro {
 };
 
 static void
-load_profile(const char *fname)
+load_profile(const char *fname, bool must_exist)
 {
 FILE *f;
 
-if ((f = fopen(fname, "r")) == NULL)
+if ((f = fopen(fname, "r")) == NULL) {
+	if (must_exist)
+	err(EXIT_FAILURE, "profile %s", fname);
 	return;
+}
 option_source = fname;
 
 for (;;) {
@@ -186,12 +189,12 @@ load_profiles(const char *profile_name)
 char fname[PATH_MAX];
 
 if (profile_name != NULL)
-	load_profile(profile_name);
+	load_profile(profile_name, true);
 else {
 	snprintf(fname, sizeof(fname), "%s/.indent.pro", getenv("HOME"));
-	load_profile(fname);
+	load_profile(fname, false);
 }
-load_profile(".indent.pro");
+load_profile(".indent.pro", false);
 option_source = "Command line";
 }
 
@@ -267,7 +270,7 @@ set_option(const char *arg)
 const struct pro *p;
 const char *param_start;
 
-arg++;			/* ignore leading "-" */
+arg++;			/* skip leading '-' */
 if (set_special_option(arg))
 	return;
 



CVS commit: src/usr.bin/indent

2021-10-07 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Oct  7 17:38:21 UTC 2021

Modified Files:
src/usr.bin/indent: args.c

Log Message:
indent: complain if the profile from the command line does not exist


To generate a diff of this commit:
cvs rdiff -u -r1.45 -r1.46 src/usr.bin/indent/args.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/indent

2021-10-07 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Oct  7 17:31:33 UTC 2021

Modified Files:
src/usr.bin/indent: args.c

Log Message:
indent: allow long comments in profile files

When reading a comment in a profile file, don't store the characters of
the comment in the buffer, just skip them. This allows for long comments
without triggering overflow errors.


To generate a diff of this commit:
cvs rdiff -u -r1.44 -r1.45 src/usr.bin/indent/args.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.44 src/usr.bin/indent/args.c:1.45
--- src/usr.bin/indent/args.c:1.44	Thu Oct  7 16:45:38 2021
+++ src/usr.bin/indent/args.c	Thu Oct  7 17:31:33 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: args.c,v 1.44 2021/10/07 16:45:38 rillig Exp $	*/
+/*	$NetBSD: args.c,v 1.45 2021/10/07 17:31:33 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@ static char sccsid[] = "@(#)args.c	8.1 (
 
 #include 
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: args.c,v 1.44 2021/10/07 16:45:38 rillig Exp $");
+__RCSID("$NetBSD: args.c,v 1.45 2021/10/07 17:31:33 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/args.c 336318 2018-07-15 21:04:21Z pstef $");
 #endif
@@ -143,45 +143,41 @@ static void
 load_profile(const char *fname)
 {
 FILE *f;
-int comment_index, ch;
-char *p;
-char buf[BUFSIZ];
 
 if ((f = fopen(fname, "r")) == NULL)
 	return;
 option_source = fname;
 
 for (;;) {
-	p = buf;
-	comment_index = 0;
+	char buf[BUFSIZ];
+	size_t n = 0;
+	int ch, comment_ch = -1;
+
 	while ((ch = getc(f)) != EOF) {
-	if (ch == '*' && comment_index == 0 && p > buf && p[-1] == '/') {
-		comment_index = (int)(p - buf);
-		*p++ = (char)ch;
-	} else if (ch == '/' && comment_index != 0 && p > buf && p[-1] == '*') {
-		p = buf + comment_index - 1;
-		comment_index = 0;
+	if (ch == '*' && comment_ch < 0 && n > 0 && buf[n - 1] == '/') {
+		n--;
+		comment_ch = ch;
+	} else if (comment_ch >= 0) {
+		comment_ch = ch == '/' && comment_ch == '*' ? -1 : ch;
 	} else if (isspace((unsigned char)ch)) {
-		if (p > buf && comment_index == 0)
-		break;
-	} else if ((size_t)(p - buf) >= nitems(buf) - 5) {
+		break;
+	} else if (n >= nitems(buf) - 5) {
 		diag(1, "buffer overflow in %s, starting with '%.10s'",
 		 option_source, buf);
 		exit(1);
-	} else {
-		*p++ = (char)ch;
-	}
+	} else
+		buf[n++] = (char)ch;
 	}
-	if (p != buf) {
-	*p++ = '\0';
+
+	if (n > 0) {
+	buf[n] = '\0';
 	if (opt.verbose)
 		printf("profile: %s\n", buf);
 	set_option(buf);
-	} else if (ch == EOF) {
-	(void)fclose(f);
-	return;
-	}
+	} else if (ch == EOF)
+	break;
 }
+(void)fclose(f);
 }
 
 void



CVS commit: src/usr.bin/indent

2021-10-07 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Oct  7 17:31:33 UTC 2021

Modified Files:
src/usr.bin/indent: args.c

Log Message:
indent: allow long comments in profile files

When reading a comment in a profile file, don't store the characters of
the comment in the buffer, just skip them. This allows for long comments
without triggering overflow errors.


To generate a diff of this commit:
cvs rdiff -u -r1.44 -r1.45 src/usr.bin/indent/args.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/usr.bin/indent

2021-10-07 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Oct  7 16:45:38 UTC 2021

Modified Files:
src/usr.bin/indent: args.c

Log Message:
indent: prevent buffer overflow when reading profile


To generate a diff of this commit:
cvs rdiff -u -r1.43 -r1.44 src/usr.bin/indent/args.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.43 src/usr.bin/indent/args.c:1.44
--- src/usr.bin/indent/args.c:1.43	Sun Oct  3 19:09:59 2021
+++ src/usr.bin/indent/args.c	Thu Oct  7 16:45:38 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: args.c,v 1.43 2021/10/03 19:09:59 rillig Exp $	*/
+/*	$NetBSD: args.c,v 1.44 2021/10/07 16:45:38 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@ static char sccsid[] = "@(#)args.c	8.1 (
 
 #include 
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: args.c,v 1.43 2021/10/03 19:09:59 rillig Exp $");
+__RCSID("$NetBSD: args.c,v 1.44 2021/10/07 16:45:38 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/args.c 336318 2018-07-15 21:04:21Z pstef $");
 #endif
@@ -164,6 +164,10 @@ load_profile(const char *fname)
 	} else if (isspace((unsigned char)ch)) {
 		if (p > buf && comment_index == 0)
 		break;
+	} else if ((size_t)(p - buf) >= nitems(buf) - 5) {
+		diag(1, "buffer overflow in %s, starting with '%.10s'",
+		 option_source, buf);
+		exit(1);
 	} else {
 		*p++ = (char)ch;
 	}



CVS commit: src/usr.bin/indent

2021-10-07 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Oct  7 16:45:38 UTC 2021

Modified Files:
src/usr.bin/indent: args.c

Log Message:
indent: prevent buffer overflow when reading profile


To generate a diff of this commit:
cvs rdiff -u -r1.43 -r1.44 src/usr.bin/indent/args.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src

2021-10-07 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Thu Oct  7 13:04:18 UTC 2021

Modified Files:
src/sys/arch/x86/include: cacheinfo.h cpu.h
src/sys/arch/x86/x86: identcpu.c identcpu_subr.c
src/usr.sbin/cpuctl/arch: cpuctl_i386.h i386.c

Log Message:
Move some common functions into x86/identcpu_subr.c. No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 src/sys/arch/x86/include/cacheinfo.h
cvs rdiff -u -r1.131 -r1.132 src/sys/arch/x86/include/cpu.h
cvs rdiff -u -r1.122 -r1.123 src/sys/arch/x86/x86/identcpu.c
cvs rdiff -u -r1.8 -r1.9 src/sys/arch/x86/x86/identcpu_subr.c
cvs rdiff -u -r1.5 -r1.6 src/usr.sbin/cpuctl/arch/cpuctl_i386.h
cvs rdiff -u -r1.121 -r1.122 src/usr.sbin/cpuctl/arch/i386.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src

2021-10-07 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Thu Oct  7 13:04:18 UTC 2021

Modified Files:
src/sys/arch/x86/include: cacheinfo.h cpu.h
src/sys/arch/x86/x86: identcpu.c identcpu_subr.c
src/usr.sbin/cpuctl/arch: cpuctl_i386.h i386.c

Log Message:
Move some common functions into x86/identcpu_subr.c. No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 src/sys/arch/x86/include/cacheinfo.h
cvs rdiff -u -r1.131 -r1.132 src/sys/arch/x86/include/cpu.h
cvs rdiff -u -r1.122 -r1.123 src/sys/arch/x86/x86/identcpu.c
cvs rdiff -u -r1.8 -r1.9 src/sys/arch/x86/x86/identcpu_subr.c
cvs rdiff -u -r1.5 -r1.6 src/usr.sbin/cpuctl/arch/cpuctl_i386.h
cvs rdiff -u -r1.121 -r1.122 src/usr.sbin/cpuctl/arch/i386.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/x86/include/cacheinfo.h
diff -u src/sys/arch/x86/include/cacheinfo.h:1.29 src/sys/arch/x86/include/cacheinfo.h:1.30
--- src/sys/arch/x86/include/cacheinfo.h:1.29	Mon Sep 27 16:52:15 2021
+++ src/sys/arch/x86/include/cacheinfo.h	Thu Oct  7 13:04:18 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: cacheinfo.h,v 1.29 2021/09/27 16:52:15 msaitoh Exp $	*/
+/*	$NetBSD: cacheinfo.h,v 1.30 2021/10/07 13:04:18 msaitoh Exp $	*/
 
 #ifndef _X86_CACHEINFO_H_
 #define _X86_CACHEINFO_H_
@@ -359,4 +359,7 @@ __CI_TBL(0, 0x0f, 0xff, 0, 0, NULL), \
 __CI_TBL(0, 0x00,0, 0, 0, NULL)  \
 }
 
+const struct x86_cache_info *cpu_cacheinfo_lookup(
+	const struct x86_cache_info *, uint8_t);
+
 #endif /* _X86_CACHEINFO_H_ */

Index: src/sys/arch/x86/include/cpu.h
diff -u src/sys/arch/x86/include/cpu.h:1.131 src/sys/arch/x86/include/cpu.h:1.132
--- src/sys/arch/x86/include/cpu.h:1.131	Sat Aug 14 17:51:20 2021
+++ src/sys/arch/x86/include/cpu.h	Thu Oct  7 13:04:18 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.h,v 1.131 2021/08/14 17:51:20 ryo Exp $	*/
+/*	$NetBSD: cpu.h,v 1.132 2021/10/07 13:04:18 msaitoh Exp $	*/
 
 /*
  * Copyright (c) 1990 The Regents of the University of California.
@@ -496,6 +496,7 @@ void	identify_hypervisor(void);
 
 /* identcpu_subr.c */
 uint64_t cpu_tsc_freq_cpuid(struct cpu_info *);
+void	cpu_dcp_cacheinfo(struct cpu_info *, uint32_t);
 
 typedef enum vm_guest {
 	VM_GUEST_NO = 0,

Index: src/sys/arch/x86/x86/identcpu.c
diff -u src/sys/arch/x86/x86/identcpu.c:1.122 src/sys/arch/x86/x86/identcpu.c:1.123
--- src/sys/arch/x86/x86/identcpu.c:1.122	Thu Oct  7 12:52:27 2021
+++ src/sys/arch/x86/x86/identcpu.c	Thu Oct  7 13:04:18 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: identcpu.c,v 1.122 2021/10/07 12:52:27 msaitoh Exp $	*/
+/*	$NetBSD: identcpu.c,v 1.123 2021/10/07 13:04:18 msaitoh Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: identcpu.c,v 1.122 2021/10/07 12:52:27 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: identcpu.c,v 1.123 2021/10/07 13:04:18 msaitoh Exp $");
 
 #include "opt_xen.h"
 
@@ -101,79 +101,6 @@ static const char cpu_vendor_names[][10]
 	"Vortex86"
 };
 
-static const struct x86_cache_info *
-cache_info_lookup(const struct x86_cache_info *cai, uint8_t desc)
-{
-	int i;
-
-	for (i = 0; cai[i].cai_desc != 0; i++) {
-		if (cai[i].cai_desc == desc)
-			return ([i]);
-	}
-
-	return (NULL);
-}
-
-/*
- * Get cache info from one of the following:
- *	Intel Deterministic Cache Parameter Leaf (0x04)
- *	AMD Cache Topology Information Leaf (0x801d)
- */
-static void
-cpu_dcp_cacheinfo(struct cpu_info *ci, uint32_t leaf)
-{
-	u_int descs[4];
-	int type, level, ways, partitions, linesize, sets, totalsize;
-	int caitype = -1;
-	int i;
-
-	for (i = 0; ; i++) {
-		x86_cpuid2(leaf, i, descs);
-		type = __SHIFTOUT(descs[0], CPUID_DCP_CACHETYPE);
-		if (type == CPUID_DCP_CACHETYPE_N)
-			break;
-		level = __SHIFTOUT(descs[0], CPUID_DCP_CACHELEVEL);
-		switch (level) {
-		case 1:
-			if (type == CPUID_DCP_CACHETYPE_I)
-caitype = CAI_ICACHE;
-			else if (type == CPUID_DCP_CACHETYPE_D)
-caitype = CAI_DCACHE;
-			else
-caitype = -1;
-			break;
-		case 2:
-			if (type == CPUID_DCP_CACHETYPE_U)
-caitype = CAI_L2CACHE;
-			else
-caitype = -1;
-			break;
-		case 3:
-			if (type == CPUID_DCP_CACHETYPE_U)
-caitype = CAI_L3CACHE;
-			else
-caitype = -1;
-			break;
-		default:
-			caitype = -1;
-			break;
-		}
-		if (caitype == -1)
-			continue;
-
-		ways = __SHIFTOUT(descs[1], CPUID_DCP_WAYS) + 1;
-		partitions =__SHIFTOUT(descs[1], CPUID_DCP_PARTITIONS)
-		+ 1;
-		linesize = __SHIFTOUT(descs[1], CPUID_DCP_LINESIZE)
-		+ 1;
-		sets = descs[2] + 1;
-		totalsize = ways * partitions * linesize * sets;
-		ci->ci_cinfo[caitype].cai_totalsize = totalsize;
-		ci->ci_cinfo[caitype].cai_associativity = ways;
-		ci->ci_cinfo[caitype].cai_linesize = linesize;
-	}
-}
-
 static void
 cpu_probe_intel_cache(struct cpu_info *ci)
 {
@@ -196,7 +123,7 @@ cpu_probe_intel_cache(struct cpu_info *c
 	desc = (descs[i] 

CVS commit: src/sys/arch/x86/x86

2021-10-07 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Thu Oct  7 12:52:27 UTC 2021

Modified Files:
src/sys/arch/x86/x86: bus_dma.c bus_space.c consinit.c coretemp.c cpu.c
cpu_rng.c db_memrw.c efi.c errata.c est.c identcpu.c
intel_busclock.c intr.c ioapic.c lapic.c linux_trap.c mp.c mpacpi.c
mpbios.c mtrr_i686.c multiboot2.c pmap.c powernow.c
procfs_machdep.c spectre.c svs.c sys_machdep.c syscall.c
viac7temp.c x86_autoconf.c x86_ipmi.c x86_machdep.c x86_tlb.c

Log Message:
KNF. No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.82 -r1.83 src/sys/arch/x86/x86/bus_dma.c
cvs rdiff -u -r1.45 -r1.46 src/sys/arch/x86/x86/bus_space.c
cvs rdiff -u -r1.33 -r1.34 src/sys/arch/x86/x86/consinit.c
cvs rdiff -u -r1.37 -r1.38 src/sys/arch/x86/x86/coretemp.c
cvs rdiff -u -r1.201 -r1.202 src/sys/arch/x86/x86/cpu.c
cvs rdiff -u -r1.19 -r1.20 src/sys/arch/x86/x86/cpu_rng.c
cvs rdiff -u -r1.11 -r1.12 src/sys/arch/x86/x86/db_memrw.c \
src/sys/arch/x86/x86/linux_trap.c src/sys/arch/x86/x86/powernow.c
cvs rdiff -u -r1.21 -r1.22 src/sys/arch/x86/x86/efi.c
cvs rdiff -u -r1.26 -r1.27 src/sys/arch/x86/x86/errata.c
cvs rdiff -u -r1.32 -r1.33 src/sys/arch/x86/x86/est.c
cvs rdiff -u -r1.121 -r1.122 src/sys/arch/x86/x86/identcpu.c
cvs rdiff -u -r1.24 -r1.25 src/sys/arch/x86/x86/intel_busclock.c
cvs rdiff -u -r1.155 -r1.156 src/sys/arch/x86/x86/intr.c
cvs rdiff -u -r1.64 -r1.65 src/sys/arch/x86/x86/ioapic.c
cvs rdiff -u -r1.85 -r1.86 src/sys/arch/x86/x86/lapic.c
cvs rdiff -u -r1.6 -r1.7 src/sys/arch/x86/x86/mp.c
cvs rdiff -u -r1.107 -r1.108 src/sys/arch/x86/x86/mpacpi.c
cvs rdiff -u -r1.70 -r1.71 src/sys/arch/x86/x86/mpbios.c
cvs rdiff -u -r1.31 -r1.32 src/sys/arch/x86/x86/mtrr_i686.c
cvs rdiff -u -r1.7 -r1.8 src/sys/arch/x86/x86/multiboot2.c
cvs rdiff -u -r1.411 -r1.412 src/sys/arch/x86/x86/pmap.c
cvs rdiff -u -r1.41 -r1.42 src/sys/arch/x86/x86/procfs_machdep.c
cvs rdiff -u -r1.35 -r1.36 src/sys/arch/x86/x86/spectre.c
cvs rdiff -u -r1.39 -r1.40 src/sys/arch/x86/x86/svs.c
cvs rdiff -u -r1.56 -r1.57 src/sys/arch/x86/x86/sys_machdep.c
cvs rdiff -u -r1.18 -r1.19 src/sys/arch/x86/x86/syscall.c \
src/sys/arch/x86/x86/x86_tlb.c
cvs rdiff -u -r1.8 -r1.9 src/sys/arch/x86/x86/viac7temp.c
cvs rdiff -u -r1.84 -r1.85 src/sys/arch/x86/x86/x86_autoconf.c
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/x86/x86/x86_ipmi.c
cvs rdiff -u -r1.148 -r1.149 src/sys/arch/x86/x86/x86_machdep.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/x86/x86/bus_dma.c
diff -u src/sys/arch/x86/x86/bus_dma.c:1.82 src/sys/arch/x86/x86/bus_dma.c:1.83
--- src/sys/arch/x86/x86/bus_dma.c:1.82	Sat Mar 14 18:08:38 2020
+++ src/sys/arch/x86/x86/bus_dma.c	Thu Oct  7 12:52:27 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: bus_dma.c,v 1.82 2020/03/14 18:08:38 ad Exp $	*/
+/*	$NetBSD: bus_dma.c,v 1.83 2021/10/07 12:52:27 msaitoh Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2007, 2020 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: bus_dma.c,v 1.82 2020/03/14 18:08:38 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bus_dma.c,v 1.83 2021/10/07 12:52:27 msaitoh Exp $");
 
 /*
  * The following is included because _bus_dma_uiomove is derived from
@@ -212,8 +212,8 @@ _bus_dmamem_alloc_range(bus_dma_tag_t t,
 	 * Allocate pages from the VM system.
 	 * We accept boundaries < size, splitting in multiple segments
 	 * if needed. uvm_pglistalloc does not, so compute an appropriate
- * boundary: next power of 2 >= size
- */
+	 * boundary: next power of 2 >= size
+	 */
 
 	if (boundary == 0)
 		uboundary = 0;
@@ -1172,8 +1172,8 @@ _bus_dmamem_unmap(bus_dma_tag_t t, void 
 	eva = sva + size;
 
 	/*
- * mark pages cacheable again.
- */
+	 * mark pages cacheable again.
+	 */
 	for (va = sva; va < eva; va += PAGE_SIZE) {
 		pte = kvtopte(va);
 		opte = *pte;

Index: src/sys/arch/x86/x86/bus_space.c
diff -u src/sys/arch/x86/x86/bus_space.c:1.45 src/sys/arch/x86/x86/bus_space.c:1.46
--- src/sys/arch/x86/x86/bus_space.c:1.45	Sat Apr 25 15:26:18 2020
+++ src/sys/arch/x86/x86/bus_space.c	Thu Oct  7 12:52:27 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: bus_space.c,v 1.45 2020/04/25 15:26:18 bouyer Exp $	*/
+/*	$NetBSD: bus_space.c,v 1.46 2021/10/07 12:52:27 msaitoh Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: bus_space.c,v 1.45 2020/04/25 15:26:18 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bus_space.c,v 1.46 2021/10/07 12:52:27 msaitoh Exp $");
 
 #include 
 #include 
@@ -57,7 +57,7 @@ __KERNEL_RCSID(0, "$NetBSD: bus_space.c,
  * could lead to performance improvements, and help catch problems
  * with drivers that would creep up on other architectures.
  */
-#ifdef BUS_SPACE_DEBUG 
+#ifdef BUS_SPACE_DEBUG
 #define	BUS_SPACE_ALIGNED_ADDRESS(p, t)\
 	

CVS commit: src/sys/arch/x86/x86

2021-10-07 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Thu Oct  7 12:52:27 UTC 2021

Modified Files:
src/sys/arch/x86/x86: bus_dma.c bus_space.c consinit.c coretemp.c cpu.c
cpu_rng.c db_memrw.c efi.c errata.c est.c identcpu.c
intel_busclock.c intr.c ioapic.c lapic.c linux_trap.c mp.c mpacpi.c
mpbios.c mtrr_i686.c multiboot2.c pmap.c powernow.c
procfs_machdep.c spectre.c svs.c sys_machdep.c syscall.c
viac7temp.c x86_autoconf.c x86_ipmi.c x86_machdep.c x86_tlb.c

Log Message:
KNF. No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.82 -r1.83 src/sys/arch/x86/x86/bus_dma.c
cvs rdiff -u -r1.45 -r1.46 src/sys/arch/x86/x86/bus_space.c
cvs rdiff -u -r1.33 -r1.34 src/sys/arch/x86/x86/consinit.c
cvs rdiff -u -r1.37 -r1.38 src/sys/arch/x86/x86/coretemp.c
cvs rdiff -u -r1.201 -r1.202 src/sys/arch/x86/x86/cpu.c
cvs rdiff -u -r1.19 -r1.20 src/sys/arch/x86/x86/cpu_rng.c
cvs rdiff -u -r1.11 -r1.12 src/sys/arch/x86/x86/db_memrw.c \
src/sys/arch/x86/x86/linux_trap.c src/sys/arch/x86/x86/powernow.c
cvs rdiff -u -r1.21 -r1.22 src/sys/arch/x86/x86/efi.c
cvs rdiff -u -r1.26 -r1.27 src/sys/arch/x86/x86/errata.c
cvs rdiff -u -r1.32 -r1.33 src/sys/arch/x86/x86/est.c
cvs rdiff -u -r1.121 -r1.122 src/sys/arch/x86/x86/identcpu.c
cvs rdiff -u -r1.24 -r1.25 src/sys/arch/x86/x86/intel_busclock.c
cvs rdiff -u -r1.155 -r1.156 src/sys/arch/x86/x86/intr.c
cvs rdiff -u -r1.64 -r1.65 src/sys/arch/x86/x86/ioapic.c
cvs rdiff -u -r1.85 -r1.86 src/sys/arch/x86/x86/lapic.c
cvs rdiff -u -r1.6 -r1.7 src/sys/arch/x86/x86/mp.c
cvs rdiff -u -r1.107 -r1.108 src/sys/arch/x86/x86/mpacpi.c
cvs rdiff -u -r1.70 -r1.71 src/sys/arch/x86/x86/mpbios.c
cvs rdiff -u -r1.31 -r1.32 src/sys/arch/x86/x86/mtrr_i686.c
cvs rdiff -u -r1.7 -r1.8 src/sys/arch/x86/x86/multiboot2.c
cvs rdiff -u -r1.411 -r1.412 src/sys/arch/x86/x86/pmap.c
cvs rdiff -u -r1.41 -r1.42 src/sys/arch/x86/x86/procfs_machdep.c
cvs rdiff -u -r1.35 -r1.36 src/sys/arch/x86/x86/spectre.c
cvs rdiff -u -r1.39 -r1.40 src/sys/arch/x86/x86/svs.c
cvs rdiff -u -r1.56 -r1.57 src/sys/arch/x86/x86/sys_machdep.c
cvs rdiff -u -r1.18 -r1.19 src/sys/arch/x86/x86/syscall.c \
src/sys/arch/x86/x86/x86_tlb.c
cvs rdiff -u -r1.8 -r1.9 src/sys/arch/x86/x86/viac7temp.c
cvs rdiff -u -r1.84 -r1.85 src/sys/arch/x86/x86/x86_autoconf.c
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/x86/x86/x86_ipmi.c
cvs rdiff -u -r1.148 -r1.149 src/sys/arch/x86/x86/x86_machdep.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



Re: CVS commit: src/sys/arch/arm/arm

2021-10-07 Thread Rin Okuyama

Oops, forgot to mention: No binary changes.

On 2021/10/07 18:58, Rin Okuyama wrote:

Module Name:src
Committed By:   rin
Date:   Thu Oct  7 09:58:27 UTC 2021

Modified Files:
src/sys/arch/arm/arm: cpufunc_asm_armv5_ec.S

Log Message:
Reduce diff with cpufunc_asm_armv5.S, from which this file was derived.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/arch/arm/arm/cpufunc_asm_armv5_ec.S

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.


CVS commit: src/sys/arch/arm/arm

2021-10-07 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Thu Oct  7 09:58:27 UTC 2021

Modified Files:
src/sys/arch/arm/arm: cpufunc_asm_armv5_ec.S

Log Message:
Reduce diff with cpufunc_asm_armv5.S, from which this file was derived.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/arch/arm/arm/cpufunc_asm_armv5_ec.S

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/arm/arm/cpufunc_asm_armv5_ec.S
diff -u src/sys/arch/arm/arm/cpufunc_asm_armv5_ec.S:1.6 src/sys/arch/arm/arm/cpufunc_asm_armv5_ec.S:1.7
--- src/sys/arch/arm/arm/cpufunc_asm_armv5_ec.S:1.6	Sun Mar 30 01:15:03 2014
+++ src/sys/arch/arm/arm/cpufunc_asm_armv5_ec.S	Thu Oct  7 09:58:27 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpufunc_asm_armv5_ec.S,v 1.6 2014/03/30 01:15:03 matt Exp $	*/
+/*	$NetBSD: cpufunc_asm_armv5_ec.S,v 1.7 2021/10/07 09:58:27 rin Exp $	*/
 
 /*
  * Copyright (c) 2002, 2005 ARM Limited
@@ -58,16 +58,16 @@ ENTRY(armv5_ec_setttb)
 	 * For armv5_ec_settb, the idcache_wbinv_all is simple enough, I just
 	 * do it directly and entirely avoid the problem.
 	 */
-	cmp	r1, #0			@ need to flush cache / TLB?
-	beq	2f			@   nope, so don't
+	cmp	r1, #0
+	beq	1f
 
 	mcr	p15, 0, r0, c7, c5, 0	/* Invalidate ICache */
-1:	mrc	p15, 0, APSR_nzcv, c7, c14, 3	/* Test, clean and invalidate DCache */
-	bne	1b			/* More to do? */
+2:	mrc	p15, 0, APSR_nzcv, c7, c14, 3	/* Test, clean and invalidate DCache */
+	bne	2b			/* More to do? */
 	mcr	p15, 0, r0, c7, c10, 4	/* drain the write buffer */
 	cmp	r0, #1
 
-2:	mcr	p15, 0, r0, c2, c0, 0	/* load new TTB */
+1:	mcr	p15, 0, r0, c2, c0, 0	/* load new TTB */
 	mcrne	p15, 0, r0, c8, c7, 0	/* invalidate I+D TLBs */
 	RET
 
@@ -199,7 +199,7 @@ ENTRY_NP(armv5_ec_idcache_wbinv_all)
 	 * dcache, so that we can safely flush the Icache and fall through
 	 * into the Dcache purging code.
 	 */
-	mcr	p15, 0, r0, c7, c5, 0	/* Invalidate ICache */
+	mcr	p15, 0, r0, c7, c5, 0	/* Flush I cache */
 	/* Fall through to purge Dcache. */
 
 ENTRY(armv5_ec_dcache_wbinv_all)



CVS commit: src/sys/arch/arm/arm

2021-10-07 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Thu Oct  7 09:58:27 UTC 2021

Modified Files:
src/sys/arch/arm/arm: cpufunc_asm_armv5_ec.S

Log Message:
Reduce diff with cpufunc_asm_armv5.S, from which this file was derived.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/sys/arch/arm/arm/cpufunc_asm_armv5_ec.S

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/arm/arm

2021-10-07 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Thu Oct  7 09:57:27 UTC 2021

Modified Files:
src/sys/arch/arm/arm: cpufunc_asm_armv5.S

Log Message:
trailing whitespace/tab


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/arch/arm/arm/cpufunc_asm_armv5.S

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/arm/arm/cpufunc_asm_armv5.S
diff -u src/sys/arch/arm/arm/cpufunc_asm_armv5.S:1.7 src/sys/arch/arm/arm/cpufunc_asm_armv5.S:1.8
--- src/sys/arch/arm/arm/cpufunc_asm_armv5.S:1.7	Sun Mar 30 01:15:03 2014
+++ src/sys/arch/arm/arm/cpufunc_asm_armv5.S	Thu Oct  7 09:57:27 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpufunc_asm_armv5.S,v 1.7 2014/03/30 01:15:03 matt Exp $	*/
+/*	$NetBSD: cpufunc_asm_armv5.S,v 1.8 2021/10/07 09:57:27 rin Exp $	*/
 
 /*
  * Copyright (c) 2002, 2005 ARM Limited
@@ -32,7 +32,7 @@
  * These routines can be used by any core that supports the set/index
  * operations.
  */
- 
+
 #include "assym.h"
 #include 
 #include 
@@ -130,7 +130,7 @@ ENTRY(armv5_dcache_wb_range)
 	bpl	1b
 	mcr	p15, 0, r0, c7, c10, 4	/* drain the write buffer */
 	RET
-	
+
 ENTRY(armv5_dcache_wbinv_range)
 	ldr	ip, .Larmv5_line_size
 	cmp	r1, #0x4000
@@ -148,7 +148,7 @@ ENTRY(armv5_dcache_wbinv_range)
 	bpl	1b
 	mcr	p15, 0, r0, c7, c10, 4	/* drain the write buffer */
 	RET
-	
+
 /*
  * Note, we must not invalidate everything.  If the range is too big we
  * must use wb-inv of the entire cache.



CVS commit: src/sys/arch/arm/arm

2021-10-07 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Thu Oct  7 09:57:27 UTC 2021

Modified Files:
src/sys/arch/arm/arm: cpufunc_asm_armv5.S

Log Message:
trailing whitespace/tab


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/arch/arm/arm/cpufunc_asm_armv5.S

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/arch/riscv/riscv

2021-10-07 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Thu Oct  7 07:13:35 UTC 2021

Modified Files:
src/sys/arch/riscv/riscv: pmap_machdep.c riscv_machdep.c syscall.c
trap.c

Log Message:
Hacky build fixes


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/arch/riscv/riscv/pmap_machdep.c
cvs rdiff -u -r1.14 -r1.15 src/sys/arch/riscv/riscv/riscv_machdep.c
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/riscv/riscv/syscall.c
cvs rdiff -u -r1.15 -r1.16 src/sys/arch/riscv/riscv/trap.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/riscv/riscv/pmap_machdep.c
diff -u src/sys/arch/riscv/riscv/pmap_machdep.c:1.8 src/sys/arch/riscv/riscv/pmap_machdep.c:1.9
--- src/sys/arch/riscv/riscv/pmap_machdep.c:1.8	Sat Oct  2 14:28:05 2021
+++ src/sys/arch/riscv/riscv/pmap_machdep.c	Thu Oct  7 07:13:35 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap_machdep.c,v 1.8 2021/10/02 14:28:05 skrll Exp $ */
+/* $NetBSD: pmap_machdep.c,v 1.9 2021/10/07 07:13:35 skrll Exp $ */
 
 /*
  * Copyright (c) 2014, 2019, 2021 The NetBSD Foundation, Inc.
@@ -34,7 +34,7 @@
 
 #include 
 
-__RCSID("$NetBSD: pmap_machdep.c,v 1.8 2021/10/02 14:28:05 skrll Exp $");
+__RCSID("$NetBSD: pmap_machdep.c,v 1.9 2021/10/07 07:13:35 skrll Exp $");
 
 #include 
 
@@ -57,22 +57,30 @@ pmap_bootstrap(void)
 void
 pmap_zero_page(paddr_t pa)
 {
+#ifdef _LP64
 #ifdef PMAP_DIRECT_MAP
 	memset((void *)PMAP_DIRECT_MAP(pa), 0, PAGE_SIZE);
 #else
 #error "no direct map"
 #endif
+#else
+	KASSERT(false);
+#endif
 }
 
 void
 pmap_copy_page(paddr_t src, paddr_t dst)
 {
+#ifdef _LP64
 #ifdef PMAP_DIRECT_MAP
 	memcpy((void *)PMAP_DIRECT_MAP(dst), (const void *)PMAP_DIRECT_MAP(src),
 	PAGE_SIZE);
 #else
 #error "no direct map"
 #endif
+#else
+	KASSERT(false);
+#endif
 }
 
 struct vm_page *
@@ -113,10 +121,15 @@ paddr_t
 pmap_md_direct_mapped_vaddr_to_paddr(vaddr_t va)
 {
 #ifdef _LP64
+#ifdef PMAP_DIRECT_MAP
 	return PMAP_DIRECT_UNMAP(va);
 #else
 #error "no direct map"
 #endif
+#else
+	KASSERT(false);
+	return 0;
+#endif
 }
 
 vaddr_t

Index: src/sys/arch/riscv/riscv/riscv_machdep.c
diff -u src/sys/arch/riscv/riscv/riscv_machdep.c:1.14 src/sys/arch/riscv/riscv/riscv_machdep.c:1.15
--- src/sys/arch/riscv/riscv/riscv_machdep.c:1.14	Sat May  1 06:53:08 2021
+++ src/sys/arch/riscv/riscv/riscv_machdep.c	Thu Oct  7 07:13:35 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: riscv_machdep.c,v 1.14 2021/05/01 06:53:08 skrll Exp $	*/
+/*	$NetBSD: riscv_machdep.c,v 1.15 2021/10/07 07:13:35 skrll Exp $	*/
 
 /*-
  * Copyright (c) 2014, 2019 The NetBSD Foundation, Inc.
@@ -33,7 +33,7 @@
 
 #include "opt_modular.h"
 
-__RCSID("$NetBSD: riscv_machdep.c,v 1.14 2021/05/01 06:53:08 skrll Exp $");
+__RCSID("$NetBSD: riscv_machdep.c,v 1.15 2021/10/07 07:13:35 skrll Exp $");
 
 #include 
 #include 
@@ -157,7 +157,9 @@ startlwp(void *arg)
 // We've worked hard to make sure struct reg and __gregset_t are the same.
 // Ditto for struct fpreg and fregset_t.
 
+#ifdef _LP64
 CTASSERT(sizeof(struct reg) == sizeof(__gregset_t));
+#endif
 CTASSERT(sizeof(struct fpreg) == sizeof(__fregset_t));
 
 void

Index: src/sys/arch/riscv/riscv/syscall.c
diff -u src/sys/arch/riscv/riscv/syscall.c:1.2 src/sys/arch/riscv/riscv/syscall.c:1.3
--- src/sys/arch/riscv/riscv/syscall.c:1.2	Sat Mar 14 16:12:16 2020
+++ src/sys/arch/riscv/riscv/syscall.c	Thu Oct  7 07:13:35 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: syscall.c,v 1.2 2020/03/14 16:12:16 skrll Exp $	*/
+/*	$NetBSD: syscall.c,v 1.3 2021/10/07 07:13:35 skrll Exp $	*/
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include 
-__KERNEL_RCSID(0, "$NetBSD: syscall.c,v 1.2 2020/03/14 16:12:16 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: syscall.c,v 1.3 2021/10/07 07:13:35 skrll Exp $");
 
 #include 
 #include 
@@ -81,7 +81,6 @@ EMULNAME(syscall)(struct trapframe *tf)
 	register_t retval[2];
 	const struct sysent *callp;
 	int code, error;
-	size_t i;
 #ifdef _LP64
 	const bool pk32_p = (p->p_flag & PK_32) != 0;
 	register_t copyargs[EMULNAME(SYS_MAXSYSARGS)];
@@ -110,8 +109,8 @@ EMULNAME(syscall)(struct trapframe *tf)
 	else
 		callp += code;
 
-	const size_t nargs = callp->sy_narg;
 #ifdef _LP64
+	const size_t nargs = callp->sy_narg;
 	/*
 	 * If there are no 64bit arguments, we still need "sanitize" the
 	 * 32-bit arguments in case they try to slip through a 64-bit pointer.
@@ -141,7 +140,7 @@ EMULNAME(syscall)(struct trapframe *tf)
 		 * encounter a 64 bit argument, we grab two adjacent 32bit
 		 * values and synthesize the 64bit argument.
 		 */
-		for (i = 0; i < nargs + narg64; ) {
+		for (size_t i = 0; i < nargs + narg64; ) {
 			register_t arg = *args32++;
 			if (__predict_true((arg64mask & 1) == 0)) {
 /*

Index: src/sys/arch/riscv/riscv/trap.c
diff -u src/sys/arch/riscv/riscv/trap.c:1.15 src/sys/arch/riscv/riscv/trap.c:1.16
--- src/sys/arch/riscv/riscv/trap.c:1.15	Sun Dec 20 16:38:26 

CVS commit: src/sys/arch/riscv/riscv

2021-10-07 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Thu Oct  7 07:13:35 UTC 2021

Modified Files:
src/sys/arch/riscv/riscv: pmap_machdep.c riscv_machdep.c syscall.c
trap.c

Log Message:
Hacky build fixes


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/sys/arch/riscv/riscv/pmap_machdep.c
cvs rdiff -u -r1.14 -r1.15 src/sys/arch/riscv/riscv/riscv_machdep.c
cvs rdiff -u -r1.2 -r1.3 src/sys/arch/riscv/riscv/syscall.c
cvs rdiff -u -r1.15 -r1.16 src/sys/arch/riscv/riscv/trap.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/lib/libc/arch/aarch64/gen

2021-10-07 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Thu Oct  7 06:44:19 UTC 2021

Modified Files:
src/lib/libc/arch/aarch64/gen: _setjmp.S setjmp.S

Log Message:
Fix the lib/libc/setjmp/t_setjmp:{,_}longjmp_zero test cases


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/lib/libc/arch/aarch64/gen/_setjmp.S
cvs rdiff -u -r1.3 -r1.4 src/lib/libc/arch/aarch64/gen/setjmp.S

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/lib/libc/arch/aarch64/gen

2021-10-07 Thread Nick Hudson
Module Name:src
Committed By:   skrll
Date:   Thu Oct  7 06:44:19 UTC 2021

Modified Files:
src/lib/libc/arch/aarch64/gen: _setjmp.S setjmp.S

Log Message:
Fix the lib/libc/setjmp/t_setjmp:{,_}longjmp_zero test cases


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/lib/libc/arch/aarch64/gen/_setjmp.S
cvs rdiff -u -r1.3 -r1.4 src/lib/libc/arch/aarch64/gen/setjmp.S

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libc/arch/aarch64/gen/_setjmp.S
diff -u src/lib/libc/arch/aarch64/gen/_setjmp.S:1.4 src/lib/libc/arch/aarch64/gen/_setjmp.S:1.5
--- src/lib/libc/arch/aarch64/gen/_setjmp.S:1.4	Sun May 10 14:05:59 2020
+++ src/lib/libc/arch/aarch64/gen/_setjmp.S	Thu Oct  7 06:44:18 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: _setjmp.S,v 1.4 2020/05/10 14:05:59 skrll Exp $ */
+/* $NetBSD: _setjmp.S,v 1.5 2021/10/07 06:44:18 skrll Exp $ */
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -99,7 +99,8 @@ ENTRY(_longjmp)
 	mov	x29, x4
 	mov	x30, x5
 
-	mov	x0, x1
+	cmp x1, #0
+	csinc   x0, x1, xzr, ne
 	ret
 
 	/* validation failed, die die die. */

Index: src/lib/libc/arch/aarch64/gen/setjmp.S
diff -u src/lib/libc/arch/aarch64/gen/setjmp.S:1.3 src/lib/libc/arch/aarch64/gen/setjmp.S:1.4
--- src/lib/libc/arch/aarch64/gen/setjmp.S:1.3	Sun May 10 14:05:59 2020
+++ src/lib/libc/arch/aarch64/gen/setjmp.S	Thu Oct  7 06:44:18 2021
@@ -1,4 +1,4 @@
-/*.$NetBSD: setjmp.S,v 1.3 2020/05/10 14:05:59 skrll Exp $.*/
+/*.$NetBSD: setjmp.S,v 1.4 2021/10/07 06:44:18 skrll Exp $.*/
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -114,8 +114,11 @@ ENTRY(__longjmp14)
 	bl	_C_LABEL(__sigprocmask14)
 
 	ldp	x29, x30, [sp, #16]
-	ldr	x0, [sp, #8]
+	ldr	x1, [sp, #8]
 	add	sp, sp, #32
+
+	cmp x1, #0
+	csinc   x0, x1, xzr, ne
 	ret
 
 	/* validation failed, die die die. */