CVS commit: src/usr.bin/indent

2021-10-03 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Oct  3 18:44:51 UTC 2021

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

Log Message:
indent: rename functions

There was no good reason for using the different verbs 'scan' and 'set'
for two functions that essentially do the same.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.40 -r1.41 src/usr.bin/indent/args.c
cvs rdiff -u -r1.97 -r1.98 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.26 -r1.27 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.40 src/usr.bin/indent/args.c:1.41
--- src/usr.bin/indent/args.c:1.40	Sun Oct  3 18:41:36 2021
+++ src/usr.bin/indent/args.c	Sun Oct  3 18:44:51 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: args.c,v 1.40 2021/10/03 18:41:36 rillig Exp $	*/
+/*	$NetBSD: args.c,v 1.41 2021/10/03 18:44:51 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.40 2021/10/03 18:41:36 rillig Exp $");
+__RCSID("$NetBSD: args.c,v 1.41 2021/10/03 18:44:51 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/args.c 336318 2018-07-15 21:04:21Z pstef $");
 #endif
@@ -64,7 +64,6 @@ __FBSDID("$FreeBSD: head/usr.bin/indent/
 
 #define INDENT_VERSION	"2.0"
 
-static void scan_profile(FILE *);
 void add_typedefs_from_file(const char *);
 
 static const char *option_source = "?";
@@ -140,34 +139,8 @@ static const struct pro {
 bool_options("v", verbose),
 };
 
-/*
- * set_profile reads $HOME/.indent.pro and ./.indent.pro and handles arguments
- * given in these files.
- */
-void
-set_profile(const char *profile_name)
-{
-FILE *f;
-char fname[PATH_MAX];
-static char prof[] = ".indent.pro";
-
-if (profile_name == NULL)
-	snprintf(fname, sizeof(fname), "%s/%s", getenv("HOME"), prof);
-else
-	snprintf(fname, sizeof(fname), "%s", profile_name);
-if ((f = fopen(option_source = fname, "r")) != NULL) {
-	scan_profile(f);
-	(void)fclose(f);
-}
-if ((f = fopen(option_source = prof, "r")) != NULL) {
-	scan_profile(f);
-	(void)fclose(f);
-}
-option_source = "Command line";
-}
-
 static void
-scan_profile(FILE *f)
+load_profile(FILE *f)
 {
 int comment_index, i;
 char *p;
@@ -200,6 +173,28 @@ scan_profile(FILE *f)
 }
 }
 
+void
+load_profiles(const char *profile_name)
+{
+FILE *f;
+char fname[PATH_MAX];
+static char prof[] = ".indent.pro";
+
+if (profile_name == NULL)
+	snprintf(fname, sizeof(fname), "%s/%s", getenv("HOME"), prof);
+else
+	snprintf(fname, sizeof(fname), "%s", profile_name);
+if ((f = fopen(option_source = fname, "r")) != NULL) {
+	load_profile(f);
+	(void)fclose(f);
+}
+if ((f = fopen(option_source = prof, "r")) != NULL) {
+	load_profile(f);
+	(void)fclose(f);
+}
+option_source = "Command line";
+}
+
 static const char *
 skip_over(const char *s, bool may_negate, const char *prefix)
 {

Index: src/usr.bin/indent/indent.c
diff -u src/usr.bin/indent/indent.c:1.97 src/usr.bin/indent/indent.c:1.98
--- src/usr.bin/indent/indent.c:1.97	Sun Oct  3 18:41:36 2021
+++ src/usr.bin/indent/indent.c	Sun Oct  3 18:44:51 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.97 2021/10/03 18:41:36 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.98 2021/10/03 18:44:51 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.97 2021/10/03 18:41:36 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.98 2021/10/03 18:44:51 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -449,7 +449,7 @@ main_parse_command_line(int argc, char *
 	else if (argv[i][0] == '-' && argv[i][1] == 'P' && argv[i][2] != '\0')
 	profile_name = argv[i] + 2;	/* non-empty -P (set profile) */
 if (i >= argc)
-	set_profile(profile_name);
+	load_profiles(profile_name);
 
 for (i = 1; i < argc; ++i) {
 	if (argv[i][0] == '-') {

Index: src/usr.bin/indent/indent.h
diff -u src/usr.bin/indent/indent.h:1.26 src/usr.bin/indent/indent.h:1.27
--- src/usr.bin/indent/indent.h:1.26	Mon Sep 27 18:21:47 2021
+++ src/usr.bin/indent/indent.h	Sun Oct  3 18:44:51 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.h,v 1.26 2021/09/27 18:21:47 rillig Exp $	*/
+/*	$NetBSD: indent.h,v 1.27 2021/10/03 18:44:51 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -64,7 +64,7 @@ void		fill_buffer(void);
 void		parse(token_type);
 void		process_comment(void);
 void		set_option(const char *);
-void		set_profile(const char *);
+void		load_profiles(const char *);
 
 void		*xmalloc(size_t);
 void		

CVS commit: src/usr.bin/indent

2021-10-03 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Oct  3 18:44:51 UTC 2021

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

Log Message:
indent: rename functions

There was no good reason for using the different verbs 'scan' and 'set'
for two functions that essentially do the same.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.40 -r1.41 src/usr.bin/indent/args.c
cvs rdiff -u -r1.97 -r1.98 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.26 -r1.27 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-03 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Oct  3 18:41:36 UTC 2021

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

Log Message:
indent: fix content of profile_name

Previously, profile_name included the leading "-P", which was confusing.


To generate a diff of this commit:
cvs rdiff -u -r1.39 -r1.40 src/usr.bin/indent/args.c
cvs rdiff -u -r1.96 -r1.97 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/args.c
diff -u src/usr.bin/indent/args.c:1.39 src/usr.bin/indent/args.c:1.40
--- src/usr.bin/indent/args.c:1.39	Sun Sep 26 21:05:48 2021
+++ src/usr.bin/indent/args.c	Sun Oct  3 18:41:36 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: args.c,v 1.39 2021/09/26 21:05:48 rillig Exp $	*/
+/*	$NetBSD: args.c,v 1.40 2021/10/03 18:41:36 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.39 2021/09/26 21:05:48 rillig Exp $");
+__RCSID("$NetBSD: args.c,v 1.40 2021/10/03 18:41:36 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/args.c 336318 2018-07-15 21:04:21Z pstef $");
 #endif
@@ -154,7 +154,7 @@ set_profile(const char *profile_name)
 if (profile_name == NULL)
 	snprintf(fname, sizeof(fname), "%s/%s", getenv("HOME"), prof);
 else
-	snprintf(fname, sizeof(fname), "%s", profile_name + 2);
+	snprintf(fname, sizeof(fname), "%s", profile_name);
 if ((f = fopen(option_source = fname, "r")) != NULL) {
 	scan_profile(f);
 	(void)fclose(f);

Index: src/usr.bin/indent/indent.c
diff -u src/usr.bin/indent/indent.c:1.96 src/usr.bin/indent/indent.c:1.97
--- src/usr.bin/indent/indent.c:1.96	Thu Sep 30 21:48:12 2021
+++ src/usr.bin/indent/indent.c	Sun Oct  3 18:41:36 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.96 2021/09/30 21:48:12 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.97 2021/10/03 18:41: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.96 2021/09/30 21:48:12 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.97 2021/10/03 18:41:36 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -447,7 +447,7 @@ main_parse_command_line(int argc, char *
 	if (strcmp(argv[i], "-npro") == 0)
 	break;
 	else if (argv[i][0] == '-' && argv[i][1] == 'P' && argv[i][2] != '\0')
-	profile_name = argv[i];	/* non-empty -P (set profile) */
+	profile_name = argv[i] + 2;	/* non-empty -P (set profile) */
 if (i >= argc)
 	set_profile(profile_name);
 



CVS commit: src/usr.bin/indent

2021-10-03 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Oct  3 18:41:36 UTC 2021

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

Log Message:
indent: fix content of profile_name

Previously, profile_name included the leading "-P", which was confusing.


To generate a diff of this commit:
cvs rdiff -u -r1.39 -r1.40 src/usr.bin/indent/args.c
cvs rdiff -u -r1.96 -r1.97 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-09-30 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Sep 30 21:38:43 UTC 2021

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

Log Message:
indent: untangle want_blank_before_lparen

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.94 -r1.95 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.94 src/usr.bin/indent/indent.c:1.95
--- src/usr.bin/indent/indent.c:1.94	Thu Sep 30 21:33:55 2021
+++ src/usr.bin/indent/indent.c	Thu Sep 30 21:38:43 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.94 2021/09/30 21:33:55 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.95 2021/09/30 21:38:43 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.94 2021/09/30 21:33:55 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.95 2021/09/30 21:38:43 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -596,11 +596,15 @@ process_newline(void)
 static bool
 want_blank_before_lparen(void)
 {
-return ps.want_blank &&
-	   ((ps.last_token != ident && ps.last_token != funcname) ||
-	opt.proc_calls_space ||
-	(ps.keyword == kw_sizeof ? opt.blank_after_sizeof :
-	 ps.keyword != kw_0 && ps.keyword != kw_offsetof));
+if (!ps.want_blank)
+	return false;
+if (ps.last_token != ident && ps.last_token != funcname)
+	return true;
+if (opt.proc_calls_space)
+	return true;
+if (ps.keyword == kw_sizeof)
+	return opt.blank_after_sizeof;
+return ps.keyword != kw_0 && ps.keyword != kw_offsetof;
 }
 
 static void



CVS commit: src/usr.bin/indent

2021-09-30 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Sep 30 21:38:43 UTC 2021

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

Log Message:
indent: untangle want_blank_before_lparen

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.94 -r1.95 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-09-30 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Sep 30 21:33:55 UTC 2021

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

Log Message:
indent: extract want_blank_before_lparen

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.93 -r1.94 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.93 src/usr.bin/indent/indent.c:1.94
--- src/usr.bin/indent/indent.c:1.93	Thu Sep 30 20:58:26 2021
+++ src/usr.bin/indent/indent.c	Thu Sep 30 21:33:55 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.93 2021/09/30 20:58:26 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.94 2021/09/30 21:33:55 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.93 2021/09/30 20:58:26 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.94 2021/09/30 21:33:55 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -593,6 +593,16 @@ process_newline(void)
 ++line_no;			/* keep track of input line number */
 }
 
+static bool
+want_blank_before_lparen(void)
+{
+return ps.want_blank &&
+	   ((ps.last_token != ident && ps.last_token != funcname) ||
+	opt.proc_calls_space ||
+	(ps.keyword == kw_sizeof ? opt.blank_after_sizeof :
+	 ps.keyword != kw_0 && ps.keyword != kw_offsetof));
+}
+
 static void
 process_lparen_or_lbracket(int dec_ind, bool tabs_to_var, bool sp_sw)
 {
@@ -608,11 +618,7 @@ process_lparen_or_lbracket(int dec_ind, 
 	/* function pointer declarations */
 	indent_declaration(dec_ind, tabs_to_var);
 	ps.dumped_decl_indent = true;
-} else if (ps.want_blank &&
-	((ps.last_token != ident && ps.last_token != funcname) ||
-	opt.proc_calls_space ||
-	(ps.keyword == kw_sizeof ? opt.blank_after_sizeof :
-	ps.keyword != kw_0 && ps.keyword != kw_offsetof)))
+} else if (want_blank_before_lparen())
 	*code.e++ = ' ';
 ps.want_blank = false;
 *code.e++ = token.s[0];



CVS commit: src/usr.bin/indent

2021-09-30 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Thu Sep 30 21:33:55 UTC 2021

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

Log Message:
indent: extract want_blank_before_lparen

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.93 -r1.94 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-09-27 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Sep 27 20:09:55 UTC 2021

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

Log Message:
indent: let indent format the comments after previous refactoring

Before this refactoring, I had skipped this section of the code from
formatting since the 'default:' branch was enclosed in a block of its
own, and that block would have been indented one more level to the
right. Extracting that code into a separate function got rid of the
extra braces.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.91 -r1.92 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.91 src/usr.bin/indent/indent.c:1.92
--- src/usr.bin/indent/indent.c:1.91	Mon Sep 27 20:00:41 2021
+++ src/usr.bin/indent/indent.c	Mon Sep 27 20:09:55 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.91 2021/09/27 20:00:41 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.92 2021/09/27 20:09:55 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.91 2021/09/27 20:00:41 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.92 2021/09/27 20:09:55 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -171,13 +171,12 @@ search_brace_newline(bool *inout_force_n
 *sc_end++ = '\n';
 
 /*
- * We may have inherited a force_nl == true from the previous
- * token (like a semicolon). But once we know that a newline has
- * been scanned in this loop, force_nl should be false.
+ * We may have inherited a force_nl == true from the previous token (like
+ * a semicolon). But once we know that a newline has been scanned in this
+ * loop, force_nl should be false.
  *
- * However, the force_nl == true must be preserved if newline is
- * never scanned in this loop, so this assignment cannot be done
- * earlier.
+ * However, the force_nl == true must be preserved if newline is never
+ * scanned in this loop, so this assignment cannot be done earlier.
  */
 *inout_force_nl = false;
 }
@@ -188,8 +187,8 @@ search_brace_comment(bool *inout_comment
 if (sc_end == NULL) {
 	/*
 	 * Copy everything from the start of the line, because
-	 * process_comment() will use that to calculate original
-	 * indentation of a boxed comment.
+	 * 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);
@@ -197,14 +196,14 @@ search_brace_comment(bool *inout_comment
 	sc_end = _com[2];
 }
 *inout_comment_buffered = true;
-*sc_end++ = '/';	/* copy in start of comment */
+*sc_end++ = '/';		/* copy in start of comment */
 *sc_end++ = '*';
-for (;;) {		/* loop until the end of the comment */
+for (;;) {			/* loop until the end of the comment */
 	*sc_end = *buf_ptr++;
 	if (buf_ptr >= buf_end)
 	fill_buffer();
 	if (*sc_end++ == '*' && *buf_ptr == '/')
-	break;	/* we are at end of comment */
+	break;		/* we are at end of comment */
 	if (sc_end >= _com[sc_size]) {	/* check for temp buffer
 		 * overflow */
 	diag(1, "Internal buffer overflow - Move big comment from right after if, while, or whatever");
@@ -212,7 +211,7 @@ search_brace_comment(bool *inout_comment
 	exit(1);
 	}
 }
-*sc_end++ = '/';	/* add ending slash */
+*sc_end++ = '/';		/* add ending slash */
 if (++buf_ptr >= buf_end)	/* get past / in buffer */
 	fill_buffer();
 }
@@ -221,17 +220,16 @@ static bool
 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.
+ * 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.
  */
 if (sc_end != NULL && opt.btype_2) {
 	save_com[0] = '{';
 	/*
-	 * Originally the lbrace may have been alone on its own line,
-	 * but it 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.
+	 * Originally the lbrace may have been alone on its own line, but it
+	 * 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)) {
 	if (++buf_ptr >= buf_end)



CVS commit: src/usr.bin/indent

2021-09-27 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Sep 27 20:09:55 UTC 2021

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

Log Message:
indent: let indent format the comments after previous refactoring

Before this refactoring, I had skipped this section of the code from
formatting since the 'default:' branch was enclosed in a block of its
own, and that block would have been indented one more level to the
right. Extracting that code into a separate function got rid of the
extra braces.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.91 -r1.92 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-09-27 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Sep 27 20:00:41 UTC 2021

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

Log Message:
indent: split search_brace into smaller functions

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.90 -r1.91 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-09-27 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Sep 27 20:00:41 UTC 2021

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

Log Message:
indent: split search_brace into smaller functions

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.90 -r1.91 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.90 src/usr.bin/indent/indent.c:1.91
--- src/usr.bin/indent/indent.c:1.90	Mon Sep 27 18:21:47 2021
+++ src/usr.bin/indent/indent.c	Mon Sep 27 20:00:41 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.90 2021/09/27 18:21:47 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.91 2021/09/27 20:00: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.90 2021/09/27 18:21:47 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.91 2021/09/27 20:00:41 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -161,184 +161,222 @@ init_capsicum(void)
 #endif
 
 static void
+search_brace_newline(bool *inout_force_nl)
+{
+if (sc_end == NULL) {
+	save_com = sc_buf;
+	save_com[0] = save_com[1] = ' ';
+	sc_end = _com[2];
+}
+*sc_end++ = '\n';
+
+/*
+ * We may have inherited a force_nl == true from the previous
+ * token (like a semicolon). But once we know that a newline has
+ * been scanned in this loop, force_nl should be false.
+ *
+ * However, the force_nl == true must be preserved if newline is
+ * never scanned in this loop, so this assignment cannot be done
+ * earlier.
+ */
+*inout_force_nl = false;
+}
+
+static void
+search_brace_comment(bool *inout_comment_buffered)
+{
+if (sc_end == NULL) {
+	/*
+	 * Copy everything from the start of the line, because
+	 * 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);
+	save_com[0] = save_com[1] = ' ';
+	sc_end = _com[2];
+}
+*inout_comment_buffered = true;
+*sc_end++ = '/';	/* copy in start of comment */
+*sc_end++ = '*';
+for (;;) {		/* loop until the end of the comment */
+	*sc_end = *buf_ptr++;
+	if (buf_ptr >= buf_end)
+	fill_buffer();
+	if (*sc_end++ == '*' && *buf_ptr == '/')
+	break;	/* we are at end of comment */
+	if (sc_end >= _com[sc_size]) {	/* check for temp buffer
+		 * overflow */
+	diag(1, "Internal buffer overflow - Move big comment from right after if, while, or whatever");
+	fflush(output);
+	exit(1);
+	}
+}
+*sc_end++ = '/';	/* add ending slash */
+if (++buf_ptr >= buf_end)	/* get past / in buffer */
+	fill_buffer();
+}
+
+static bool
+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.
+ */
+if (sc_end != NULL && opt.btype_2) {
+	save_com[0] = '{';
+	/*
+	 * Originally the lbrace may have been alone on its own line,
+	 * but it 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)) {
+	if (++buf_ptr >= buf_end)
+		fill_buffer();
+	if (*buf_ptr == '\n')
+		break;
+	}
+	return true;
+}
+return false;
+}
+
+static bool
+search_brace_other(token_type ttype, bool *inout_force_nl,
+bool comment_buffered, bool last_else)
+{
+bool remove_newlines;
+
+remove_newlines =
+	/* "} else" */
+	(ttype == keyword_do_else && *token.s == 'e' &&
+	 code.e != code.s && code.e[-1] == '}')
+	/* "else if" */
+	|| (ttype == keyword_for_if_while &&
+		*token.s == 'i' && last_else && opt.else_if);
+if (remove_newlines)
+	*inout_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)) {
+	*inout_force_nl = !remove_newlines;
+	while (sc_end > save_com && sc_end[-1] == '\n') {
+	sc_end--;
+	}
+}
+if (*inout_force_nl) {	/* if we should insert a nl here, put it into
+ * the buffer */
+	*inout_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 */
+	diag(0, "Line 

CVS commit: src/usr.bin/indent

2021-09-27 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Sep 27 18:21:47 UTC 2021

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

Log Message:
indent: use binary instead of linear search when adding types

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.89 -r1.90 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.25 -r1.26 src/usr.bin/indent/indent.h
cvs rdiff -u -r1.63 -r1.64 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-09-27 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Sep 27 18:21:47 UTC 2021

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

Log Message:
indent: use binary instead of linear search when adding types

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.89 -r1.90 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.25 -r1.26 src/usr.bin/indent/indent.h
cvs rdiff -u -r1.63 -r1.64 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.89 src/usr.bin/indent/indent.c:1.90
--- src/usr.bin/indent/indent.c:1.89	Mon Sep 27 16:56:35 2021
+++ src/usr.bin/indent/indent.c	Mon Sep 27 18:21:47 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.89 2021/09/27 16:56:35 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.90 2021/09/27 18:21: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.89 2021/09/27 16:56:35 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.90 2021/09/27 18:21:47 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -379,7 +379,6 @@ main_init_globals(void)
 buf_init();
 buf_init();
 buf_init();
-alloc_typenames();
 opt.else_if = true;		/* XXX: redundant? */
 
 in_buffer = xmalloc(10);

Index: src/usr.bin/indent/indent.h
diff -u src/usr.bin/indent/indent.h:1.25 src/usr.bin/indent/indent.h:1.26
--- src/usr.bin/indent/indent.h:1.25	Sat Sep 25 22:14:21 2021
+++ src/usr.bin/indent/indent.h	Mon Sep 27 18:21:47 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.h,v 1.25 2021/09/25 22:14:21 rillig Exp $	*/
+/*	$NetBSD: indent.h,v 1.26 2021/09/27 18:21:47 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -42,7 +42,6 @@ __FBSDID("$FreeBSD: head/usr.bin/indent/
 #endif
 
 void		add_typename(const char *);
-void		alloc_typenames(void);
 int		compute_code_indent(void);
 int		compute_label_indent(void);
 int		indentation_after_range(int, const char *, const char *);

Index: src/usr.bin/indent/lexi.c
diff -u src/usr.bin/indent/lexi.c:1.63 src/usr.bin/indent/lexi.c:1.64
--- src/usr.bin/indent/lexi.c:1.63	Mon Sep 27 17:33:07 2021
+++ src/usr.bin/indent/lexi.c	Mon Sep 27 18:21:47 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: lexi.c,v 1.63 2021/09/27 17:33:07 rillig Exp $	*/
+/*	$NetBSD: lexi.c,v 1.64 2021/09/27 18:21:47 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.63 2021/09/27 17:33:07 rillig Exp $");
+__RCSID("$NetBSD: lexi.c,v 1.64 2021/09/27 18:21:47 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/lexi.c 337862 2018-08-15 18:19:45Z pstef $");
 #endif
@@ -106,9 +106,11 @@ static const struct keyword {
 {"while", kw_for_or_if_or_while}
 };
 
-static const char **typenames;
-static int typename_count;
-static int typename_top = -1;
+struct {
+const char **items;
+unsigned int len;
+unsigned int cap;
+} typenames;
 
 /*
  * The transition table below was rewritten by hand from lx's output, given
@@ -344,10 +346,10 @@ is_typename(void)
 	return true;
 }
 
-if (typename_top < 0)
+if (typenames.len == 0)
 	return false;
-return bsearch(token.s, typenames, (size_t)typename_top + 1,
-	sizeof(typenames[0]), cmp_type_by_name) != NULL;
+return bsearch(token.s, typenames.items, (size_t)typenames.len,
+	sizeof(typenames.items[0]), cmp_type_by_name) != NULL;
 }
 
 /* Reads the next token, placing it in the global variable "token". */
@@ -662,38 +664,38 @@ lexi(struct parser_state *state)
 return lexi_end(ttype);
 }
 
-void
-alloc_typenames(void)
-{
-
-typenames = xmalloc(sizeof(typenames[0]) * (typename_count = 16));
+static int
+insert_pos(const char *key, const char **arr, unsigned int len) {
+int lo = 0;
+int hi = (int)len - 1;
+
+while (lo <= hi) {
+	int mid = (lo + hi) >> 1;
+	int cmp = strcmp(arr[mid], key);
+	if (cmp < 0)
+	lo = mid + 1;
+	else if (cmp > 0)
+	hi = mid - 1;
+	else
+	return mid;
+}
+return -(lo + 1);
 }
 
 void
-add_typename(const char *key)
+add_typename(const char *name)
 {
-int comparison;
-
-if (typename_top + 1 >= typename_count) {
-	typenames = xrealloc((void *)typenames,
-	sizeof(typenames[0]) * (typename_count *= 2));
-}
-if (typename_top == -1)
-	typenames[++typename_top] = xstrdup(key);
-else if ((comparison = strcmp(key, typenames[typename_top])) >= 0) {
-	/* take advantage of sorted input */
-	if (comparison == 0)	/* remove duplicates */
-	return;
-	typenames[++typename_top] = xstrdup(key);
-} else {
-	int p;
-
-	for (p = 0; (comparison = 

CVS commit: src/usr.bin/indent

2021-09-27 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Sep 27 17:33:07 UTC 2021

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

Log Message:
indent: extract is_typename from lexi

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.62 -r1.63 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/lexi.c
diff -u src/usr.bin/indent/lexi.c:1.62 src/usr.bin/indent/lexi.c:1.63
--- src/usr.bin/indent/lexi.c:1.62	Mon Sep 27 16:56:35 2021
+++ src/usr.bin/indent/lexi.c	Mon Sep 27 17:33:07 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: lexi.c,v 1.62 2021/09/27 16:56:35 rillig Exp $	*/
+/*	$NetBSD: lexi.c,v 1.63 2021/09/27 17:33:07 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.62 2021/09/27 16:56:35 rillig Exp $");
+__RCSID("$NetBSD: lexi.c,v 1.63 2021/09/27 17:33:07 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/lexi.c 337862 2018-08-15 18:19:45Z pstef $");
 #endif
@@ -335,6 +335,21 @@ probably_typedef(const struct parser_sta
 	state->last_token == rbrace);
 }
 
+static bool
+is_typename(void)
+{
+if (opt.auto_typedefs) {
+	const char *u;
+	if ((u = strrchr(token.s, '_')) != NULL && strcmp(u, "_t") == 0)
+	return true;
+}
+
+if (typename_top < 0)
+	return false;
+return bsearch(token.s, typenames, (size_t)typename_top + 1,
+	sizeof(typenames[0]), cmp_type_by_name) != NULL;
+}
+
 /* Reads the next token, placing it in the global variable "token". */
 token_type
 lexi(struct parser_state *state)
@@ -391,13 +406,7 @@ lexi(struct parser_state *state)
 	kw = bsearch(token.s, keywords, nitems(keywords),
 	sizeof(keywords[0]), cmp_keyword_by_name);
 	if (kw == NULL) {
-	char *u;
-
-	/* ... so maybe a type_t or a typedef */
-	if ((opt.auto_typedefs && ((u = strrchr(token.s, '_')) != NULL) &&
-		strcmp(u, "_t") == 0) || (typename_top >= 0 &&
-		bsearch(token.s, typenames, (size_t)typename_top + 1,
-			sizeof(typenames[0]), cmp_type_by_name) != NULL)) {
+	if (is_typename()) {
 		state->keyword = kw_type;
 		state->last_u_d = true;
 		goto found_typename;



CVS commit: src/usr.bin/indent

2021-09-27 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Sep 27 17:33:07 UTC 2021

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

Log Message:
indent: extract is_typename from lexi

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.62 -r1.63 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-09-27 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Sep 27 16:56:35 UTC 2021

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

Log Message:
indent: rename rwcode to keyword_kind, various cleanup

No idea what the 'rw' in 'rwcode' meant, it had been imported that way
28 years ago. Since rwcode specifies the kind of a keyword, the prefix
'kw_' makes sense.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.88 -r1.89 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.11 -r1.12 src/usr.bin/indent/indent_codes.h
cvs rdiff -u -r1.40 -r1.41 src/usr.bin/indent/indent_globs.h
cvs rdiff -u -r1.61 -r1.62 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.88 src/usr.bin/indent/indent.c:1.89
--- src/usr.bin/indent/indent.c:1.88	Sun Sep 26 21:23:31 2021
+++ src/usr.bin/indent/indent.c	Mon Sep 27 16:56:35 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.88 2021/09/26 21:23:31 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.89 2021/09/27 16:56:35 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.88 2021/09/26 21:23:31 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.89 2021/09/27 16:56:35 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -577,8 +577,8 @@ process_lparen_or_lbracket(int dec_ind, 
 } else if (ps.want_blank &&
 	((ps.last_token != ident && ps.last_token != funcname) ||
 	opt.proc_calls_space ||
-	(ps.keyword == rw_sizeof ? opt.blank_after_sizeof :
-	ps.keyword != rw_0 && ps.keyword != rw_offsetof)))
+	(ps.keyword == kw_sizeof ? opt.blank_after_sizeof :
+	ps.keyword != kw_0 && ps.keyword != kw_offsetof)))
 	*code.e++ = ' ';
 ps.want_blank = false;
 *code.e++ = token.s[0];
@@ -603,7 +603,7 @@ process_lparen_or_lbracket(int dec_ind, 
  * initialization */
 }
 /* parenthesized type following sizeof or offsetof is not a cast */
-if (ps.keyword == rw_offsetof || ps.keyword == rw_sizeof)
+if (ps.keyword == kw_offsetof || ps.keyword == kw_sizeof)
 	ps.not_cast_mask |= 1 << ps.p_l_follow;
 }
 

Index: src/usr.bin/indent/indent_codes.h
diff -u src/usr.bin/indent/indent_codes.h:1.11 src/usr.bin/indent/indent_codes.h:1.12
--- src/usr.bin/indent/indent_codes.h:1.11	Tue Mar  9 19:23:08 2021
+++ src/usr.bin/indent/indent_codes.h	Mon Sep 27 16:56:35 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent_codes.h,v 1.11 2021/03/09 19:23:08 rillig Exp $	*/
+/*	$NetBSD: indent_codes.h,v 1.12 2021/09/27 16:56:35 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -54,7 +54,7 @@ typedef enum token_type {
 semicolon,
 lbrace,
 rbrace,
-ident,
+ident,			/* identifier, constant or string */
 comma,
 comment,
 switch_expr,		/* 'switch' '('  ')' */

Index: src/usr.bin/indent/indent_globs.h
diff -u src/usr.bin/indent/indent_globs.h:1.40 src/usr.bin/indent/indent_globs.h:1.41
--- src/usr.bin/indent/indent_globs.h:1.40	Sun Sep 26 21:32:58 2021
+++ src/usr.bin/indent/indent_globs.h	Mon Sep 27 16:56:35 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent_globs.h,v 1.40 2021/09/26 21:32:58 rillig Exp $	*/
+/*	$NetBSD: indent_globs.h,v 1.41 2021/09/27 16:56:35 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -155,20 +155,20 @@ extern struct options {
  * are printed */
 } opt;
 
-enum rwcode {
-rw_0,
-rw_offsetof,
-rw_sizeof,
-rw_struct_or_union_or_enum,
-rw_type,
-rw_for_or_if_or_while,
-rw_do_or_else,
-rw_switch,
-rw_case_or_default,
-rw_jump,
-rw_storage_class,
-rw_typedef,
-rw_inline_or_restrict
+enum keyword_kind {
+kw_0,
+kw_offsetof,
+kw_sizeof,
+kw_struct_or_union_or_enum,
+kw_type,
+kw_for_or_if_or_while,
+kw_do_or_else,
+kw_switch,
+kw_case_or_default,
+kw_jump,
+kw_storage_class,
+kw_typedef,
+kw_inline_or_restrict
 };
 
 
@@ -251,7 +251,7 @@ extern struct parser_state {
 bool	want_blank;	/* whether the following token should
  * be prefixed by a blank. (Said prefixing is
  * ignored in some cases.) */
-enum rwcode keyword;	/* the type of a keyword or 0 */
+enum keyword_kind keyword;
 bool	dumped_decl_indent;
 bool	in_parameter_declaration;
 int tos;		/* pointer to top of stack */

Index: src/usr.bin/indent/lexi.c
diff -u src/usr.bin/indent/lexi.c:1.61 src/usr.bin/indent/lexi.c:1.62
--- src/usr.bin/indent/lexi.c:1.61	Sun Sep 26 21:23:31 2021
+++ src/usr.bin/indent/lexi.c	Mon Sep 27 16:56:35 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: lexi.c,v 1.61 2021/09/26 21:23:31 rillig Exp $	*/
+/*	$NetBSD: lexi.c,v 1.62 2021/09/27 

CVS commit: src/usr.bin/indent

2021-09-27 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Mon Sep 27 16:56:35 UTC 2021

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

Log Message:
indent: rename rwcode to keyword_kind, various cleanup

No idea what the 'rw' in 'rwcode' meant, it had been imported that way
28 years ago. Since rwcode specifies the kind of a keyword, the prefix
'kw_' makes sense.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.88 -r1.89 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.11 -r1.12 src/usr.bin/indent/indent_codes.h
cvs rdiff -u -r1.40 -r1.41 src/usr.bin/indent/indent_globs.h
cvs rdiff -u -r1.61 -r1.62 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-09-26 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Sep 26 21:32:59 UTC 2021

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

Log Message:
indent: fix documentation of opt.case_indent

See io.c, compute_label_indent.


To generate a diff of this commit:
cvs rdiff -u -r1.39 -r1.40 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_globs.h
diff -u src/usr.bin/indent/indent_globs.h:1.39 src/usr.bin/indent/indent_globs.h:1.40
--- src/usr.bin/indent/indent_globs.h:1.39	Sun Sep 26 21:23:31 2021
+++ src/usr.bin/indent/indent_globs.h	Sun Sep 26 21:32:58 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent_globs.h,v 1.39 2021/09/26 21:23:31 rillig Exp $	*/
+/*	$NetBSD: indent_globs.h,v 1.40 2021/09/26 21:32:58 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -100,9 +100,9 @@ extern struct options {
 bool	cuddle_else;	/* whether 'else' should cuddle up to '}' */
 int continuation_indent; /* the indentation between the
  * edge of code and continuation lines */
-float   case_indent;	/* The distance (measured in tabsize) to
- * indent case labels from the switch
- * statement */
+float   case_indent;	/* The distance (measured in indentation
+ * levels) to indent case labels from the
+ * switch statement */
 int comment_column;	/* the column in which comments to the right
  * of code should start */
 int decl_indent;	/* indentation of identifier in declaration */



CVS commit: src/usr.bin/indent

2021-09-26 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Sep 26 21:32:59 UTC 2021

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

Log Message:
indent: fix documentation of opt.case_indent

See io.c, compute_label_indent.


To generate a diff of this commit:
cvs rdiff -u -r1.39 -r1.40 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-09-26 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Sep 26 21:31:57 UTC 2021

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

Log Message:
indent: fix definition of -cli in manual page

See io.c, compute_label_indent.


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 src/usr.bin/indent/indent.1

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.1
diff -u src/usr.bin/indent/indent.1:1.29 src/usr.bin/indent/indent.1:1.30
--- src/usr.bin/indent/indent.1:1.29	Sat Mar  6 21:08:08 2021
+++ src/usr.bin/indent/indent.1	Sun Sep 26 21:31:57 2021
@@ -1,4 +1,4 @@
-.\"	$NetBSD: indent.1,v 1.29 2021/03/06 21:08:08 rillig Exp $
+.\"	$NetBSD: indent.1,v 1.30 2021/09/26 21:31:57 rillig Exp $
 .\"
 .\" Copyright (c) 1980, 1990, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -32,7 +32,7 @@
 .\"	@(#)indent.1	8.1 (Berkeley) 7/1/93
 .\" $FreeBSD: head/usr.bin/indent/indent.1 334944 2018-06-11 05:35:57Z pstef $
 .\"
-.Dd March 6, 2021
+.Dd September 26, 2021
 .Dt INDENT 1
 .Os
 .Sh NAME
@@ -254,11 +254,11 @@ defaults to the same value as
 .It Fl cli Ns Ar n
 Causes case labels to be indented
 .Ar n
-tab stops to the right of the containing
+indentation levels to the right of the containing
 .Ic switch
 statement.
 .Fl cli0.5
-causes case labels to be indented half a tab stop.
+causes case labels to be indented half an indentation level.
 The
 default is
 .Fl cli0 .



CVS commit: src/usr.bin/indent

2021-09-26 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Sep 26 21:31:57 UTC 2021

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

Log Message:
indent: fix definition of -cli in manual page

See io.c, compute_label_indent.


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 src/usr.bin/indent/indent.1

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-09-26 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Sep 26 21:23:31 UTC 2021

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

Log Message:
indent: unexport global variables

The variable match_state was write-only and was thus removed.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.87 -r1.88 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.38 -r1.39 src/usr.bin/indent/indent_globs.h
cvs rdiff -u -r1.67 -r1.68 src/usr.bin/indent/io.c
cvs rdiff -u -r1.60 -r1.61 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.87 src/usr.bin/indent/indent.c:1.88
--- src/usr.bin/indent/indent.c:1.87	Sun Sep 26 19:57:23 2021
+++ src/usr.bin/indent/indent.c	Sun Sep 26 21:23:31 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.87 2021/09/26 19:57:23 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.88 2021/09/26 21:23: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.87 2021/09/26 19:57:23 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.88 2021/09/26 21:23:31 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -99,7 +99,7 @@ char *buf_end;
 
 char sc_buf[sc_size];
 char *save_com;
-char *sc_end;
+static char *sc_end;		/* pointer into save_com buffer */
 
 char *bp_save;
 char *be_save;
@@ -113,11 +113,9 @@ float case_ind;
 bool had_eof;
 int line_no;
 bool inhibit_formatting;
-int suppress_blanklines;
 
-int ifdef_level;
-struct parser_state state_stack[5];
-struct parser_state match_state[5];
+static int ifdef_level;
+static struct parser_state state_stack[5];
 
 FILE *input;
 FILE *output;
@@ -125,13 +123,10 @@ FILE *output;
 static void bakcopy(void);
 static void indent_declaration(int, bool);
 
-const char *in_name = "Standard Input";	/* will always point to name of input
-	 * file */
-const char *out_name = "Standard Output";	/* will always point to name
-		 * of output file */
-const char *simple_backup_suffix = ".BAK";	/* Suffix to use for backup
-		 * files */
-char bakfile[MAXPATHLEN] = "";
+static const char *in_name = "Standard Input";
+static const char *out_name = "Standard Output";
+static const char *backup_suffix = ".BAK";
+static char bakfile[MAXPATHLEN] = "";
 
 static void
 check_size_code(size_t desired_size)
@@ -404,7 +399,7 @@ main_init_globals(void)
 
 const char *suffix = getenv("SIMPLE_BACKUP_SUFFIX");
 if (suffix != NULL)
-	simple_backup_suffix = suffix;
+	backup_suffix = suffix;
 }
 
 static void
@@ -1150,18 +1145,15 @@ process_preprocessing(void)
 }
 
 if (strncmp(lab.s, "#if", 3) == 0) {	/* also ifdef, ifndef */
-	if ((size_t)ifdef_level < nitems(state_stack)) {
-	match_state[ifdef_level].tos = -1;
+	if ((size_t)ifdef_level < nitems(state_stack))
 	state_stack[ifdef_level++] = ps;
-	} else
+	else
 	diag(1, "#if stack overflow");
 } else if (strncmp(lab.s, "#el", 3) == 0) {	/* else, elif */
 	if (ifdef_level <= 0)
 	diag(1, lab.s[3] == 'i' ? "Unmatched #elif" : "Unmatched #else");
-	else {
-	match_state[ifdef_level - 1] = ps;
+	else
 	ps = state_stack[ifdef_level - 1];
-	}
 } else if (strncmp(lab.s, "#endif", 6) == 0) {
 	if (ifdef_level <= 0)
 	diag(1, "Unmatched #endif");
@@ -1418,7 +1410,7 @@ bakcopy(void)
 	p--;
 if (*p == '/')
 	p++;
-sprintf(bakfile, "%s%s", p, simple_backup_suffix);
+sprintf(bakfile, "%s%s", p, backup_suffix);
 
 /* copy in_name to backup file */
 bakchn = creat(bakfile, 0600);

Index: src/usr.bin/indent/indent_globs.h
diff -u src/usr.bin/indent/indent_globs.h:1.38 src/usr.bin/indent/indent_globs.h:1.39
--- src/usr.bin/indent/indent_globs.h:1.38	Sun Sep 26 19:57:23 2021
+++ src/usr.bin/indent/indent_globs.h	Sun Sep 26 21:23:31 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent_globs.h,v 1.38 2021/09/26 19:57:23 rillig Exp $	*/
+/*	$NetBSD: indent_globs.h,v 1.39 2021/09/26 21:23:31 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -70,7 +70,6 @@ extern char   *buf_end;		/* ptr to f
 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   *sc_end;		/* pointer into save_com buffer */
 
 extern char   *bp_save;		/* saved value of buf_ptr when taking input
  * from save_com */
@@ -184,8 +183,6 @@ extern float   case_ind;	/* indentat
 extern boolhad_eof;		/* whether input is exhausted */
 extern int line_no;		/* the current line number. */
 extern boolinhibit_formatting;	/* true if INDENT OFF is in effect */
-extern int   

CVS commit: src/usr.bin/indent

2021-09-26 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Sep 26 21:23:31 UTC 2021

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

Log Message:
indent: unexport global variables

The variable match_state was write-only and was thus removed.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.87 -r1.88 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.38 -r1.39 src/usr.bin/indent/indent_globs.h
cvs rdiff -u -r1.67 -r1.68 src/usr.bin/indent/io.c
cvs rdiff -u -r1.60 -r1.61 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-09-26 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Sep 26 21:05:48 UTC 2021

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

Log Message:
indent: unexport keyword table, clean up

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.38 -r1.39 src/usr.bin/indent/args.c
cvs rdiff -u -r1.59 -r1.60 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.38 src/usr.bin/indent/args.c:1.39
--- src/usr.bin/indent/args.c:1.38	Sun Sep 26 20:48:10 2021
+++ src/usr.bin/indent/args.c	Sun Sep 26 21:05:48 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: args.c,v 1.38 2021/09/26 20:48:10 rillig Exp $	*/
+/*	$NetBSD: args.c,v 1.39 2021/09/26 21:05:48 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.38 2021/09/26 20:48:10 rillig Exp $");
+__RCSID("$NetBSD: args.c,v 1.39 2021/09/26 21:05:48 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/args.c 336318 2018-07-15 21:04:21Z pstef $");
 #endif
@@ -92,7 +92,7 @@ static const struct pro {
 bool p_is_bool;
 bool p_bool_value;
 bool p_may_negate;
-void *p_obj;		/* the associated variable (bool, int) */
+void *p_var;		/* the associated variable */
 }   pro[] = {
 bool_options("bacc", blanklines_around_conditional_compilation),
 bool_options("bad", blanklines_after_declarations),
@@ -285,12 +285,12 @@ set_option(const char *arg)
 
 found:
 if (p->p_is_bool)
-	*(bool *)p->p_obj = p->p_may_negate ? arg[0] != 'n' : p->p_bool_value;
+	*(bool *)p->p_var = p->p_may_negate ? arg[0] != 'n' : p->p_bool_value;
 else {
 	if (!isdigit((unsigned char)*param_start))
 	errx(1, "%s: ``%s'' requires a parameter",
 		option_source, p->p_name);
-	*(int *)p->p_obj = atoi(param_start);
+	*(int *)p->p_var = atoi(param_start);
 }
 }
 

Index: src/usr.bin/indent/lexi.c
diff -u src/usr.bin/indent/lexi.c:1.59 src/usr.bin/indent/lexi.c:1.60
--- src/usr.bin/indent/lexi.c:1.59	Sun Sep 26 19:37:11 2021
+++ src/usr.bin/indent/lexi.c	Sun Sep 26 21:05:48 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: lexi.c,v 1.59 2021/09/26 19:37:11 rillig Exp $	*/
+/*	$NetBSD: lexi.c,v 1.60 2021/09/26 21:05:48 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.59 2021/09/26 19:37:11 rillig Exp $");
+__RCSID("$NetBSD: lexi.c,v 1.60 2021/09/26 21:05:48 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/lexi.c 337862 2018-08-15 18:19:45Z pstef $");
 #endif
@@ -59,17 +59,11 @@ __FBSDID("$FreeBSD: head/usr.bin/indent/
 
 #include "indent.h"
 
-struct templ {
+/* must be sorted alphabetically, is used in binary search */
+static const struct special {
 const char *rwd;
 enum rwcode rwcode;
-};
-
-/*
- * This table has to be sorted alphabetically, because it'll be used in binary
- * search.
- */
-const struct templ specials[] =
-{
+} specials[] = {
 {"_Bool", rw_type},
 {"_Complex", rw_type},
 {"_Imaginary", rw_type},
@@ -210,9 +204,9 @@ check_size_token(size_t desired_size)
 }
 
 static int
-compare_templ_array(const void *key, const void *elem)
+compare_special_array(const void *key, const void *elem)
 {
-return strcmp(key, ((const struct templ *)elem)->rwd);
+return strcmp(key, ((const struct special *)elem)->rwd);
 }
 
 static int
@@ -368,10 +362,7 @@ lexi(struct parser_state *state)
 if (isalnum((unsigned char)*buf_ptr) ||
 	*buf_ptr == '_' || *buf_ptr == '$' ||
 	(buf_ptr[0] == '.' && isdigit((unsigned char)buf_ptr[1]))) {
-	/*
-	 * we have a letter or number
-	 */
-	struct templ *p;
+	struct special *p;
 
 	if (isdigit((unsigned char)*buf_ptr) ||
 	(buf_ptr[0] == '.' && isdigit((unsigned char)buf_ptr[1]))) {
@@ -388,12 +379,9 @@ lexi(struct parser_state *state)
 	while (*buf_ptr == ' ' || *buf_ptr == '\t')	/* get rid of blanks */
 	inbuf_next();
 	state->keyword = rw_0;
+
 	if (state->last_token == keyword_struct_union_enum &&
-	state->p_l_follow == 0) {
-	/*
-	 * if last token was 'struct' and we're not in parentheses, then
-	 * this token should be treated as a declaration
-	 */
+		state->p_l_follow == 0) {
 	state->last_u_d = true;
 	return lexi_end(decl);
 	}
@@ -403,7 +391,7 @@ lexi(struct parser_state *state)
 	state->last_u_d = (state->last_token == keyword_struct_union_enum);
 
 	p = bsearch(token.s, specials, sizeof specials / sizeof specials[0],
-	sizeof specials[0], compare_templ_array);
+	sizeof specials[0], compare_special_array);
 	if (p == NULL) {	/* not a special keyword... */
 	char *u;
 



CVS commit: src/usr.bin/indent

2021-09-26 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Sep 26 21:05:48 UTC 2021

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

Log Message:
indent: unexport keyword table, clean up

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.38 -r1.39 src/usr.bin/indent/args.c
cvs rdiff -u -r1.59 -r1.60 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-09-26 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Sep 26 20:48:10 UTC 2021

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

Log Message:
indent: force all option variables to be in struct options

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.37 -r1.38 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.37 src/usr.bin/indent/args.c:1.38
--- src/usr.bin/indent/args.c:1.37	Sun Sep 26 20:43:44 2021
+++ src/usr.bin/indent/args.c	Sun Sep 26 20:48:10 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: args.c,v 1.37 2021/09/26 20:43:44 rillig Exp $	*/
+/*	$NetBSD: args.c,v 1.38 2021/09/26 20:48:10 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.37 2021/09/26 20:43:44 rillig Exp $");
+__RCSID("$NetBSD: args.c,v 1.38 2021/09/26 20:48:10 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/args.c 336318 2018-07-15 21:04:21Z pstef $");
 #endif
@@ -75,11 +75,11 @@ static const char *option_source = "?";
 #define assert_type(expr, type) (expr)
 #endif
 #define bool_option(name, value, var) \
-	{name, true, value, false, assert_type(&(var), bool *)}
+	{name, true, value, false, assert_type(&(opt.var), bool *)}
 #define int_option(name, var) \
-	{name, false, false, false, assert_type(&(var), int *)}
+	{name, false, false, false, assert_type(&(opt.var), int *)}
 #define bool_options(name, var) \
-	{name, true, false, true, assert_type(&(var), bool *)}
+	{name, true, false, true, assert_type(&(opt.var), bool *)}
 
 /*
  * N.B.: an option whose name is a prefix of another option must come earlier;
@@ -94,50 +94,50 @@ static const struct pro {
 bool p_may_negate;
 void *p_obj;		/* the associated variable (bool, int) */
 }   pro[] = {
-bool_options("bacc", opt.blanklines_around_conditional_compilation),
-bool_options("bad", opt.blanklines_after_declarations),
-bool_options("badp", opt.blanklines_after_declarations_at_proctop),
-bool_options("bap", opt.blanklines_after_procs),
-bool_options("bbb", opt.blanklines_before_blockcomments),
-bool_options("bc", opt.break_after_comma),
-bool_option("bl", false, opt.btype_2),
-bool_option("br", true, opt.btype_2),
-bool_options("bs", opt.blank_after_sizeof),
-int_option("c", opt.comment_column),
-int_option("cd", opt.decl_comment_column),
-bool_options("cdb", opt.comment_delimiter_on_blankline),
-bool_options("ce", opt.cuddle_else),
-int_option("ci", opt.continuation_indent),
+bool_options("bacc", blanklines_around_conditional_compilation),
+bool_options("bad", blanklines_after_declarations),
+bool_options("badp", blanklines_after_declarations_at_proctop),
+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_options("bs", blank_after_sizeof),
+int_option("c", comment_column),
+int_option("cd", decl_comment_column),
+bool_options("cdb", comment_delimiter_on_blankline),
+bool_options("ce", cuddle_else),
+int_option("ci", continuation_indent),
 /* "cli" is special */
-bool_options("cs", opt.space_after_cast),
-int_option("d", opt.unindent_displace),
-int_option("di", opt.decl_indent),
-bool_options("dj", opt.ljust_decl),
-bool_options("eei", opt.extra_expression_indent),
-bool_options("ei", opt.else_if),
-bool_options("fbs", opt.function_brace_split),
-bool_options("fc1", opt.format_col1_comments),
-bool_options("fcb", opt.format_block_comments),
-int_option("i", opt.indent_size),
-bool_options("ip", opt.indent_parameters),
-int_option("l", opt.max_line_length),
-int_option("lc", opt.block_comment_max_line_length),
-int_option("ldi", opt.local_decl_indent),
-bool_options("lp", opt.lineup_to_parens),
-bool_options("lpl", opt.lineup_to_parens_always),
+bool_options("cs", space_after_cast),
+int_option("d", unindent_displace),
+int_option("di", decl_indent),
+bool_options("dj", ljust_decl),
+bool_options("eei", extra_expression_indent),
+bool_options("ei", else_if),
+bool_options("fbs", function_brace_split),
+bool_options("fc1", format_col1_comments),
+bool_options("fcb", format_block_comments),
+int_option("i", indent_size),
+bool_options("ip", indent_parameters),
+int_option("l", max_line_length),
+int_option("lc", block_comment_max_line_length),
+int_option("ldi", local_decl_indent),
+bool_options("lp", lineup_to_parens),
+bool_options("lpl", lineup_to_parens_always),
 /* "npro" is special */
 /* 

CVS commit: src/usr.bin/indent

2021-09-26 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Sep 26 20:48:10 UTC 2021

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

Log Message:
indent: force all option variables to be in struct options

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.37 -r1.38 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-09-26 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Sep 26 20:43:44 UTC 2021

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

Log Message:
indent: reduce memory usage of the options table

Almost all boolean options are negatable, so model this directly instead
of saving each option twice. This saves memory, is faster and more
directly models reality.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.36 -r1.37 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.36 src/usr.bin/indent/args.c:1.37
--- src/usr.bin/indent/args.c:1.36	Sun Sep 26 20:21:47 2021
+++ src/usr.bin/indent/args.c	Sun Sep 26 20:43:44 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: args.c,v 1.36 2021/09/26 20:21:47 rillig Exp $	*/
+/*	$NetBSD: args.c,v 1.37 2021/09/26 20:43:44 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.36 2021/09/26 20:21:47 rillig Exp $");
+__RCSID("$NetBSD: args.c,v 1.37 2021/09/26 20:43:44 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/args.c 336318 2018-07-15 21:04:21Z pstef $");
 #endif
@@ -75,12 +75,11 @@ static const char *option_source = "?";
 #define assert_type(expr, type) (expr)
 #endif
 #define bool_option(name, value, var) \
-	{name, true, value, assert_type(&(var), bool *)}
+	{name, true, value, false, assert_type(&(var), bool *)}
 #define int_option(name, var) \
-	{name, false, false, assert_type(&(var), int *)}
+	{name, false, false, false, assert_type(&(var), int *)}
 #define bool_options(name, var) \
-	bool_option(name, true, var), \
-	bool_option("n" name, false, var)
+	{name, true, false, true, assert_type(&(var), bool *)}
 
 /*
  * N.B.: an option whose name is a prefix of another option must come earlier;
@@ -89,9 +88,10 @@ static const char *option_source = "?";
  * See set_special_option for special options.
  */
 static const struct pro {
-const char p_name[6];	/* name, e.g. "bl", "cli" */
+const char p_name[5];	/* name, e.g. "bl", "cli" */
 bool p_is_bool;
 bool p_bool_value;
+bool p_may_negate;
 void *p_obj;		/* the associated variable (bool, int) */
 }   pro[] = {
 bool_options("bacc", opt.blanklines_around_conditional_compilation),
@@ -201,8 +201,10 @@ scan_profile(FILE *f)
 }
 
 static const char *
-skip_over(const char *s, const char *prefix)
+skip_over(const char *s, bool may_negate, const char *prefix)
 {
+if (may_negate && s[0] == 'n')
+	s++;
 while (*prefix != '\0') {
 	if (*prefix++ != *s++)
 	return NULL;
@@ -274,15 +276,16 @@ set_option(const char *arg)
 if (set_special_option(arg))
 	return;
 
-for (p = pro + nitems(pro); p-- != pro; )
-	if (p->p_name[0] == arg[0])
-	if ((param_start = skip_over(arg, p->p_name)) != NULL)
-		goto found;
+for (p = pro + nitems(pro); p-- != pro;) {
+	param_start = skip_over(arg, p->p_may_negate, p->p_name);
+	if (param_start != NULL)
+	goto found;
+}
 errx(1, "%s: unknown parameter \"%s\"", option_source, arg - 1);
 
 found:
 if (p->p_is_bool)
-	*(bool *)p->p_obj = p->p_bool_value;
+	*(bool *)p->p_obj = p->p_may_negate ? arg[0] != 'n' : p->p_bool_value;
 else {
 	if (!isdigit((unsigned char)*param_start))
 	errx(1, "%s: ``%s'' requires a parameter",



CVS commit: src/usr.bin/indent

2021-09-26 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Sep 26 20:43:44 UTC 2021

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

Log Message:
indent: reduce memory usage of the options table

Almost all boolean options are negatable, so model this directly instead
of saving each option twice. This saves memory, is faster and more
directly models reality.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.36 -r1.37 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-09-26 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Sep 26 20:21:47 UTC 2021

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

Log Message:
indent: list options in the same order as in the manual page

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.35 -r1.36 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.35 src/usr.bin/indent/args.c:1.36
--- src/usr.bin/indent/args.c:1.35	Sun Sep 26 20:12:37 2021
+++ src/usr.bin/indent/args.c	Sun Sep 26 20:21:47 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: args.c,v 1.35 2021/09/26 20:12:37 rillig Exp $	*/
+/*	$NetBSD: args.c,v 1.36 2021/09/26 20:21:47 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.35 2021/09/26 20:12:37 rillig Exp $");
+__RCSID("$NetBSD: args.c,v 1.36 2021/09/26 20:21:47 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/args.c 336318 2018-07-15 21:04:21Z pstef $");
 #endif
@@ -83,11 +83,10 @@ static const char *option_source = "?";
 	bool_option("n" name, false, var)
 
 /*
- * N.B.: because of the way the table here is scanned, options whose names are
- * a prefix of other options must occur later; that is, with -lp vs -l, -lp
- * must be first and -l must be last.
+ * N.B.: an option whose name is a prefix of another option must come earlier;
+ * for example, "l" must come before "lp".
  *
- * See also set_special_option.
+ * See set_special_option for special options.
  */
 static const struct pro {
 const char p_name[6];	/* name, e.g. "bl", "cli" */
@@ -96,41 +95,47 @@ static const struct pro {
 void *p_obj;		/* the associated variable (bool, int) */
 }   pro[] = {
 bool_options("bacc", opt.blanklines_around_conditional_compilation),
-bool_options("badp", opt.blanklines_after_declarations_at_proctop),
 bool_options("bad", opt.blanklines_after_declarations),
+bool_options("badp", opt.blanklines_after_declarations_at_proctop),
 bool_options("bap", opt.blanklines_after_procs),
 bool_options("bbb", opt.blanklines_before_blockcomments),
 bool_options("bc", opt.break_after_comma),
 bool_option("bl", false, opt.btype_2),
 bool_option("br", true, opt.btype_2),
 bool_options("bs", opt.blank_after_sizeof),
-bool_options("cdb", opt.comment_delimiter_on_blankline),
+int_option("c", opt.comment_column),
 int_option("cd", opt.decl_comment_column),
+bool_options("cdb", opt.comment_delimiter_on_blankline),
 bool_options("ce", opt.cuddle_else),
 int_option("ci", opt.continuation_indent),
+/* "cli" is special */
 bool_options("cs", opt.space_after_cast),
-int_option("c", opt.comment_column),
+int_option("d", opt.unindent_displace),
 int_option("di", opt.decl_indent),
 bool_options("dj", opt.ljust_decl),
-int_option("d", opt.unindent_displace),
 bool_options("eei", opt.extra_expression_indent),
 bool_options("ei", opt.else_if),
 bool_options("fbs", opt.function_brace_split),
 bool_options("fc1", opt.format_col1_comments),
 bool_options("fcb", opt.format_block_comments),
-bool_options("ip", opt.indent_parameters),
 int_option("i", opt.indent_size),
+bool_options("ip", opt.indent_parameters),
+int_option("l", opt.max_line_length),
 int_option("lc", opt.block_comment_max_line_length),
 int_option("ldi", opt.local_decl_indent),
-bool_options("lpl", opt.lineup_to_parens_always),
 bool_options("lp", opt.lineup_to_parens),
-int_option("l", opt.max_line_length),
+bool_options("lpl", opt.lineup_to_parens_always),
+/* "npro" is special */
+/* "P" is special */
 bool_options("pcs", opt.proc_calls_space),
 bool_options("psl", opt.procnames_start_line),
 bool_options("sc", opt.star_comment_cont),
 bool_options("sob", opt.swallow_optional_blanklines),
+/* "st" is special */
 bool_option("ta", true, opt.auto_typedefs),
+/* "T" is special */
 int_option("ts", opt.tabsize),
+/* "U" is special */
 bool_options("ut", opt.use_tabs),
 bool_options("v", opt.verbose),
 };
@@ -269,7 +274,7 @@ set_option(const char *arg)
 if (set_special_option(arg))
 	return;
 
-for (p = pro; p != pro + nitems(pro); p++)
+for (p = pro + nitems(pro); p-- != pro; )
 	if (p->p_name[0] == arg[0])
 	if ((param_start = skip_over(arg, p->p_name)) != NULL)
 		goto found;



CVS commit: src/usr.bin/indent

2021-09-26 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Sep 26 20:21:47 UTC 2021

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

Log Message:
indent: list options in the same order as in the manual page

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.35 -r1.36 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-09-26 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Sep 26 20:12:38 UTC 2021

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

Log Message:
indent: reduce code for listing the options

After this change, the few options that do not follow the standard
scheme become more visible. They are '-bl', '-br' and '-ta'.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 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.34 src/usr.bin/indent/args.c:1.35
--- src/usr.bin/indent/args.c:1.34	Sun Sep 26 19:57:23 2021
+++ src/usr.bin/indent/args.c	Sun Sep 26 20:12:37 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: args.c,v 1.34 2021/09/26 19:57:23 rillig Exp $	*/
+/*	$NetBSD: args.c,v 1.35 2021/09/26 20:12:37 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.34 2021/09/26 19:57:23 rillig Exp $");
+__RCSID("$NetBSD: args.c,v 1.35 2021/09/26 20:12:37 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/args.c 336318 2018-07-15 21:04:21Z pstef $");
 #endif
@@ -78,6 +78,9 @@ static const char *option_source = "?";
 	{name, true, value, assert_type(&(var), bool *)}
 #define int_option(name, var) \
 	{name, false, false, assert_type(&(var), int *)}
+#define bool_options(name, var) \
+	bool_option(name, true, var), \
+	bool_option("n" name, false, var)
 
 /*
  * N.B.: because of the way the table here is scanned, options whose names are
@@ -92,69 +95,44 @@ static const struct pro {
 bool p_bool_value;
 void *p_obj;		/* the associated variable (bool, int) */
 }   pro[] = {
-bool_option("bacc", true, opt.blanklines_around_conditional_compilation),
-bool_option("badp", true, opt.blanklines_after_declarations_at_proctop),
-bool_option("bad", true, opt.blanklines_after_declarations),
-bool_option("bap", true, opt.blanklines_after_procs),
-bool_option("bbb", true, opt.blanklines_before_blockcomments),
-bool_option("bc", true, opt.break_after_comma),
+bool_options("bacc", opt.blanklines_around_conditional_compilation),
+bool_options("badp", opt.blanklines_after_declarations_at_proctop),
+bool_options("bad", opt.blanklines_after_declarations),
+bool_options("bap", opt.blanklines_after_procs),
+bool_options("bbb", opt.blanklines_before_blockcomments),
+bool_options("bc", opt.break_after_comma),
 bool_option("bl", false, opt.btype_2),
 bool_option("br", true, opt.btype_2),
-bool_option("bs", true, opt.blank_after_sizeof),
-bool_option("cdb", true, opt.comment_delimiter_on_blankline),
+bool_options("bs", opt.blank_after_sizeof),
+bool_options("cdb", opt.comment_delimiter_on_blankline),
 int_option("cd", opt.decl_comment_column),
-bool_option("ce", true, opt.cuddle_else),
+bool_options("ce", opt.cuddle_else),
 int_option("ci", opt.continuation_indent),
-bool_option("cs", true, opt.space_after_cast),
+bool_options("cs", opt.space_after_cast),
 int_option("c", opt.comment_column),
 int_option("di", opt.decl_indent),
-bool_option("dj", true, opt.ljust_decl),
+bool_options("dj", opt.ljust_decl),
 int_option("d", opt.unindent_displace),
-bool_option("eei", true, opt.extra_expression_indent),
-bool_option("ei", true, opt.else_if),
-bool_option("fbs", true, opt.function_brace_split),
-bool_option("fc1", true, opt.format_col1_comments),
-bool_option("fcb", true, opt.format_block_comments),
-bool_option("ip", true, opt.indent_parameters),
+bool_options("eei", opt.extra_expression_indent),
+bool_options("ei", opt.else_if),
+bool_options("fbs", opt.function_brace_split),
+bool_options("fc1", opt.format_col1_comments),
+bool_options("fcb", opt.format_block_comments),
+bool_options("ip", opt.indent_parameters),
 int_option("i", opt.indent_size),
 int_option("lc", opt.block_comment_max_line_length),
 int_option("ldi", opt.local_decl_indent),
-bool_option("lpl", true, opt.lineup_to_parens_always),
-bool_option("lp", true, opt.lineup_to_parens),
+bool_options("lpl", opt.lineup_to_parens_always),
+bool_options("lp", opt.lineup_to_parens),
 int_option("l", opt.max_line_length),
-bool_option("nbacc", false, opt.blanklines_around_conditional_compilation),
-bool_option("nbadp", false, opt.blanklines_after_declarations_at_proctop),
-bool_option("nbad", false, opt.blanklines_after_declarations),
-bool_option("nbap", false, opt.blanklines_after_procs),
-bool_option("nbbb", false, opt.blanklines_before_blockcomments),
-bool_option("nbc", false, opt.break_after_comma),
-bool_option("nbs", false, opt.blank_after_sizeof),
-bool_option("ncdb", false, 

CVS commit: src/usr.bin/indent

2021-09-26 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Sep 26 20:12:38 UTC 2021

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

Log Message:
indent: reduce code for listing the options

After this change, the few options that do not follow the standard
scheme become more visible. They are '-bl', '-br' and '-ta'.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 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-09-26 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Sep 26 19:57:23 UTC 2021

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

Log Message:
indent: negate and rename option.leave_comma

The old name did not mirror the description in the manual page, and it
was the only option that is negated. Inverting it allows the options
table to be compressed.


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 src/usr.bin/indent/args.c
cvs rdiff -u -r1.86 -r1.87 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.37 -r1.38 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/args.c
diff -u src/usr.bin/indent/args.c:1.33 src/usr.bin/indent/args.c:1.34
--- src/usr.bin/indent/args.c:1.33	Sun Sep 26 19:37:11 2021
+++ src/usr.bin/indent/args.c	Sun Sep 26 19:57:23 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: args.c,v 1.33 2021/09/26 19:37:11 rillig Exp $	*/
+/*	$NetBSD: args.c,v 1.34 2021/09/26 19:57:23 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.33 2021/09/26 19:37:11 rillig Exp $");
+__RCSID("$NetBSD: args.c,v 1.34 2021/09/26 19:57:23 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/args.c 336318 2018-07-15 21:04:21Z pstef $");
 #endif
@@ -97,7 +97,7 @@ static const struct pro {
 bool_option("bad", true, opt.blanklines_after_declarations),
 bool_option("bap", true, opt.blanklines_after_procs),
 bool_option("bbb", true, opt.blanklines_before_blockcomments),
-bool_option("bc", false, opt.leave_comma),
+bool_option("bc", true, opt.break_after_comma),
 bool_option("bl", false, opt.btype_2),
 bool_option("br", true, opt.btype_2),
 bool_option("bs", true, opt.blank_after_sizeof),
@@ -127,7 +127,7 @@ static const struct pro {
 bool_option("nbad", false, opt.blanklines_after_declarations),
 bool_option("nbap", false, opt.blanklines_after_procs),
 bool_option("nbbb", false, opt.blanklines_before_blockcomments),
-bool_option("nbc", true, opt.leave_comma),
+bool_option("nbc", false, opt.break_after_comma),
 bool_option("nbs", false, opt.blank_after_sizeof),
 bool_option("ncdb", false, opt.comment_delimiter_on_blankline),
 bool_option("nce", false, opt.cuddle_else),

Index: src/usr.bin/indent/indent.c
diff -u src/usr.bin/indent/indent.c:1.86 src/usr.bin/indent/indent.c:1.87
--- src/usr.bin/indent/indent.c:1.86	Sun Sep 26 19:37:11 2021
+++ src/usr.bin/indent/indent.c	Sun Sep 26 19:57:23 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.86 2021/09/26 19:37:11 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.87 2021/09/26 19:57:23 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.86 2021/09/26 19:37:11 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.87 2021/09/26 19:57:23 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,6 @@ __FBSDID("$FreeBSD: head/usr.bin/indent/
 #include "indent.h"
 
 struct options opt = {
-.leave_comma = true,
 .btype_2 = true,
 .comment_delimiter_on_blankline = true,
 .cuddle_else = true,
@@ -556,8 +555,8 @@ process_form_feed(void)
 static void
 process_newline(void)
 {
-if (ps.last_token != comma || ps.p_l_follow > 0
-	|| !opt.leave_comma || ps.block_init || !break_comma || com.s != com.e) {
+if (ps.last_token != comma || ps.p_l_follow > 0 || opt.break_after_comma
+	|| ps.block_init || !break_comma || com.s != com.e) {
 	dump_line();
 	ps.want_blank = false;
 }
@@ -1047,7 +1046,7 @@ process_comma(int dec_ind, bool tabs_to_
 if (ps.p_l_follow == 0) {
 	if (ps.block_init_level <= 0)
 	ps.block_init = false;
-	if (break_comma && (!opt.leave_comma ||
+	if (break_comma && (opt.break_after_comma ||
 			indentation_after_range(
 compute_code_indent(), code.s, code.e)
 			>= opt.max_line_length - opt.tabsize))

Index: src/usr.bin/indent/indent_globs.h
diff -u src/usr.bin/indent/indent_globs.h:1.37 src/usr.bin/indent/indent_globs.h:1.38
--- src/usr.bin/indent/indent_globs.h:1.37	Sat Sep 25 22:57:04 2021
+++ src/usr.bin/indent/indent_globs.h	Sun Sep 26 19:57:23 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent_globs.h,v 1.37 2021/09/25 22:57:04 rillig Exp $	*/
+/*	$NetBSD: indent_globs.h,v 1.38 2021/09/26 19:57:23 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -89,7 +89,7 @@ extern struct options {
 bool	blanklines_after_declarations;
 bool	blanklines_after_procs;
 bool	blanklines_before_blockcomments;
-bool	leave_comma;	/* if true, never break declarations after
+bool	break_after_comma; /* 

CVS commit: src/usr.bin/indent

2021-09-26 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Sep 26 19:57:23 UTC 2021

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

Log Message:
indent: negate and rename option.leave_comma

The old name did not mirror the description in the manual page, and it
was the only option that is negated. Inverting it allows the options
table to be compressed.


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 src/usr.bin/indent/args.c
cvs rdiff -u -r1.86 -r1.87 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.37 -r1.38 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-09-26 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Sep 26 19:37:11 UTC 2021

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

Log Message:
indent: let indent format its own code -- in supervised mode

After running indent on the code, I manually selected each change that
now looks better than before. The remaining changes are left for later.
All in all, indent did a pretty good job, except for syntactic additions
from after 1990, but that was to be expected. Examples for such
additions are GCC's __attribute__ and C99 designated initializers.

Indent has only few knobs to tune the indentation. The knob for the
continuation indentation applies to function declarations as well as to
expressions. The knob for indentation of local variable declarations
applies to struct members as well, even if these are members of a
top-level struct.

Several code comments crossed the right margin in column 78. Several
other code comments were correctly broken though. The cause for this
difference was not obvious.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 src/usr.bin/indent/args.c
cvs rdiff -u -r1.85 -r1.86 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.66 -r1.67 src/usr.bin/indent/io.c
cvs rdiff -u -r1.58 -r1.59 src/usr.bin/indent/lexi.c
cvs rdiff -u -r1.26 -r1.27 src/usr.bin/indent/parse.c
cvs rdiff -u -r1.46 -r1.47 src/usr.bin/indent/pr_comment.c

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

Modified files:

Index: src/usr.bin/indent/args.c
diff -u src/usr.bin/indent/args.c:1.32 src/usr.bin/indent/args.c:1.33
--- src/usr.bin/indent/args.c:1.32	Sun Sep 26 00:57:28 2021
+++ src/usr.bin/indent/args.c	Sun Sep 26 19:37:11 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: args.c,v 1.32 2021/09/26 00:57:28 rillig Exp $	*/
+/*	$NetBSD: args.c,v 1.33 2021/09/26 19:37:11 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.32 2021/09/26 00:57:28 rillig Exp $");
+__RCSID("$NetBSD: args.c,v 1.33 2021/09/26 19:37:11 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/args.c 336318 2018-07-15 21:04:21Z pstef $");
 #endif
@@ -87,11 +87,11 @@ static const char *option_source = "?";
  * See also set_special_option.
  */
 static const struct pro {
-const char  p_name[6];	/* name, e.g. "bl", "cli" */
-bool	p_is_bool;
-bool	p_bool_value;
-void*p_obj;		/* the associated variable (bool, int) */
-}   pro[] = {
+const char p_name[6];	/* name, e.g. "bl", "cli" */
+bool p_is_bool;
+bool p_bool_value;
+void *p_obj;		/* the associated variable (bool, int) */
+}   pro[] = {
 bool_option("bacc", true, opt.blanklines_around_conditional_compilation),
 bool_option("badp", true, opt.blanklines_after_declarations_at_proctop),
 bool_option("bad", true, opt.blanklines_after_declarations),
@@ -174,11 +174,11 @@ set_profile(const char *profile_name)
 	snprintf(fname, sizeof(fname), "%s", profile_name + 2);
 if ((f = fopen(option_source = fname, "r")) != NULL) {
 	scan_profile(f);
-	(void) fclose(f);
+	(void)fclose(f);
 }
 if ((f = fopen(option_source = prof, "r")) != NULL) {
 	scan_profile(f);
-	(void) fclose(f);
+	(void)fclose(f);
 }
 option_source = "Command line";
 }
@@ -186,9 +186,9 @@ set_profile(const char *profile_name)
 static void
 scan_profile(FILE *f)
 {
-int		comment_index, i;
-char	*p;
-charbuf[BUFSIZ];
+int comment_index, i;
+char *p;
+char buf[BUFSIZ];
 
 for (;;) {
 	p = buf;
@@ -235,7 +235,7 @@ set_special_option(const char *arg)
 if (strncmp(arg, "-version", 8) == 0) {
 	printf("FreeBSD indent %s\n", INDENT_VERSION);
 	exit(0);
-	/*NOTREACHED*/
+	/* NOTREACHED */
 }
 
 if (arg[0] == 'P' || strncmp(arg, "npro", 4) == 0)
@@ -285,7 +285,7 @@ void
 set_option(const char *arg)
 {
 const struct pro *p;
-const char	*param_start;
+const char *param_start;
 
 arg++;			/* ignore leading "-" */
 if (set_special_option(arg))

Index: src/usr.bin/indent/indent.c
diff -u src/usr.bin/indent/indent.c:1.85 src/usr.bin/indent/indent.c:1.86
--- src/usr.bin/indent/indent.c:1.85	Sun Sep 26 18:52:16 2021
+++ src/usr.bin/indent/indent.c	Sun Sep 26 19:37:11 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.85 2021/09/26 18:52:16 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.86 2021/09/26 19:37:11 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.85 2021/09/26 18:52:16 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.86 2021/09/26 19:37:11 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 

CVS commit: src/usr.bin/indent

2021-09-26 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Sep 26 19:37:11 UTC 2021

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

Log Message:
indent: let indent format its own code -- in supervised mode

After running indent on the code, I manually selected each change that
now looks better than before. The remaining changes are left for later.
All in all, indent did a pretty good job, except for syntactic additions
from after 1990, but that was to be expected. Examples for such
additions are GCC's __attribute__ and C99 designated initializers.

Indent has only few knobs to tune the indentation. The knob for the
continuation indentation applies to function declarations as well as to
expressions. The knob for indentation of local variable declarations
applies to struct members as well, even if these are members of a
top-level struct.

Several code comments crossed the right margin in column 78. Several
other code comments were correctly broken though. The cause for this
difference was not obvious.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 src/usr.bin/indent/args.c
cvs rdiff -u -r1.85 -r1.86 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.66 -r1.67 src/usr.bin/indent/io.c
cvs rdiff -u -r1.58 -r1.59 src/usr.bin/indent/lexi.c
cvs rdiff -u -r1.26 -r1.27 src/usr.bin/indent/parse.c
cvs rdiff -u -r1.46 -r1.47 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-09-26 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Sep 26 19:02:35 UTC 2021

Added Files:
src/usr.bin/indent: .indent.pro

Log Message:
indent: add .indent.pro that almost matches the source code

One might expect that the code of indent is properly indented according
to its own capabilities, but that's not the case, there are many
deviations.

This indentation profile comes close to the existing code. Maybe someday
indent's own source code can be formatted using this profile, but before
attempting that, its remaining bugs have to be fixed.

Development of indent has essentially stopped somewhere around 1990, as
demonstrated by the wrong formatting of '...' that has only been fixed a
few minutes ago. The '...' is an invention of C90. Indent's parser still
considers '...' as consisting of the 3 tokens period-period-period, but
that's OK since the effect is the same.

Another feature that had been missing for a long time were C99 comments
that span from '//' to the next newline. Before March 2021, these were
parsed as a binary operator, which produced lots of funny side effects.

Since indent's code makes use of several C99 features, as soon as it can
properly indent its own code, the worst of these bugs will have been
fixed.


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/usr.bin/indent/.indent.pro

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

Added files:

Index: src/usr.bin/indent/.indent.pro
diff -u /dev/null src/usr.bin/indent/.indent.pro:1.1
--- /dev/null	Sun Sep 26 19:02:35 2021
+++ src/usr.bin/indent/.indent.pro	Sun Sep 26 19:02:35 2021
@@ -0,0 +1,10 @@
+/* $NetBSD: .indent.pro,v 1.1 2021/09/26 19:02:35 rillig Exp $ */
+
+-di0		/* Do not indent variable names in global declarations. */
+-nfc1		/* Do not format CVS Id comments. */
+-i4		/* Indent by 4 spaces, for traditional reasons. */
+-ldi0		/* Do not indent variable names in local declarations. */
+-nlp		/* Do not indent function arguments. */
+-ta		/* Identifiers ending in '_t' are considered type names. */
+-TFILE		/* Additional types, for proper formatting of '*'. */
+-Ttoken_type



CVS commit: src/usr.bin/indent

2021-09-26 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Sep 26 19:02:35 UTC 2021

Added Files:
src/usr.bin/indent: .indent.pro

Log Message:
indent: add .indent.pro that almost matches the source code

One might expect that the code of indent is properly indented according
to its own capabilities, but that's not the case, there are many
deviations.

This indentation profile comes close to the existing code. Maybe someday
indent's own source code can be formatted using this profile, but before
attempting that, its remaining bugs have to be fixed.

Development of indent has essentially stopped somewhere around 1990, as
demonstrated by the wrong formatting of '...' that has only been fixed a
few minutes ago. The '...' is an invention of C90. Indent's parser still
considers '...' as consisting of the 3 tokens period-period-period, but
that's OK since the effect is the same.

Another feature that had been missing for a long time were C99 comments
that span from '//' to the next newline. Before March 2021, these were
parsed as a binary operator, which produced lots of funny side effects.

Since indent's code makes use of several C99 features, as soon as it can
properly indent its own code, the worst of these bugs will have been
fixed.


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/usr.bin/indent/.indent.pro

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-09-25 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Sep 26 00:57:28 UTC 2021

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

Log Message:
indent: handle special options separately

Handling the special options separately removes the need for several
macro definitions. It saves a bit of memory since without the option
'--version', the option names are shorter.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 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.31 src/usr.bin/indent/args.c:1.32
--- src/usr.bin/indent/args.c:1.31	Sat Sep 25 23:38:45 2021
+++ src/usr.bin/indent/args.c	Sun Sep 26 00:57:28 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: args.c,v 1.31 2021/09/25 23:38:45 rillig Exp $	*/
+/*	$NetBSD: args.c,v 1.32 2021/09/26 00:57:28 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.31 2021/09/25 23:38:45 rillig Exp $");
+__RCSID("$NetBSD: args.c,v 1.32 2021/09/26 00:57:28 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/args.c 336318 2018-07-15 21:04:21Z pstef $");
 #endif
@@ -56,7 +56,6 @@ __FBSDID("$FreeBSD: head/usr.bin/indent/
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -65,53 +64,34 @@ __FBSDID("$FreeBSD: head/usr.bin/indent/
 
 #define INDENT_VERSION	"2.0"
 
-/* profile types */
-#define	PRO_SPECIAL	1	/* special case */
-#define	PRO_BOOL	2	/* boolean */
-#define	PRO_INT		3	/* integer */
-
-/* profile specials for specials */
-#define	IGN		1	/* ignore it */
-#define	CLI		2	/* case label indent (float) */
-#define	STDIN		3	/* use stdin */
-#define	KEY		4	/* type (keyword) */
-#define	KEY_FILE	5	/* only used for args */
-#define VERSION		6	/* only used for args */
-
 static void scan_profile(FILE *);
-
-const char *option_source = "?";
-
 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
 #define assert_type(expr, type) (expr)
 #endif
 #define bool_option(name, value, var) \
-	{name, PRO_BOOL, /*CONSTCOND*/(value) ? 1 : 0, \
-	assert_type(&(var), bool *)}
+	{name, true, value, assert_type(&(var), bool *)}
 #define int_option(name, var) \
-	{name, PRO_INT, 0, assert_type(&(var), int *)}
-#define special_option(name, value) \
-	{name, PRO_SPECIAL, assert_type(value, int), NULL}
+	{name, false, false, assert_type(&(var), int *)}
 
 /*
  * N.B.: because of the way the table here is scanned, options whose names are
  * a prefix of other options must occur later; that is, with -lp vs -l, -lp
  * must be first and -l must be last.
+ *
+ * See also set_special_option.
  */
 static const struct pro {
-const char  p_name[9];	/* name, e.g. "bl", "cli" */
-uint8_t p_type;		/* type (int, bool, special) */
-int p_special;	/* depends on type */
+const char  p_name[6];	/* name, e.g. "bl", "cli" */
+bool	p_is_bool;
+bool	p_bool_value;
 void*p_obj;		/* the associated variable (bool, int) */
 }   pro[] = {
-special_option("T", KEY),
-special_option("U", KEY_FILE),
-special_option("-version", VERSION),
-special_option("P", IGN),
 bool_option("bacc", true, opt.blanklines_around_conditional_compilation),
 bool_option("badp", true, opt.blanklines_after_declarations_at_proctop),
 bool_option("bad", true, opt.blanklines_after_declarations),
@@ -125,7 +105,6 @@ static const struct pro {
 int_option("cd", opt.decl_comment_column),
 bool_option("ce", true, opt.cuddle_else),
 int_option("ci", opt.continuation_indent),
-special_option("cli", CLI),
 bool_option("cs", true, opt.space_after_cast),
 int_option("c", opt.comment_column),
 int_option("di", opt.decl_indent),
@@ -163,7 +142,6 @@ static const struct pro {
 bool_option("nlpl", false, opt.lineup_to_parens_always),
 bool_option("nlp", false, opt.lineup_to_parens),
 bool_option("npcs", false, opt.proc_calls_space),
-special_option("npro", IGN),
 bool_option("npsl", false, opt.procnames_start_line),
 bool_option("nsc", false, opt.star_comment_cont),
 bool_option("nsob", false, opt.swallow_optional_blanklines),
@@ -173,13 +151,10 @@ static const struct pro {
 bool_option("psl", true, opt.procnames_start_line),
 bool_option("sc", true, opt.star_comment_cont),
 bool_option("sob", true, opt.swallow_optional_blanklines),
-special_option("st", STDIN),
 bool_option("ta", true, opt.auto_typedefs),
 int_option("ts", opt.tabsize),
 bool_option("ut", true, opt.use_tabs),
 bool_option("v", true, opt.verbose),
-/* whew! */
-{"", 0, 0, 0}
 };
 
 

CVS commit: src/usr.bin/indent

2021-09-25 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sun Sep 26 00:57:28 UTC 2021

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

Log Message:
indent: handle special options separately

Handling the special options separately removes the need for several
macro definitions. It saves a bit of memory since without the option
'--version', the option names are shorter.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.32 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-09-25 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Sep 25 23:38:45 UTC 2021

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

Log Message:
indent: reduce abstraction layer for defining boolean options

When initializing a boolean option, the most natural values are true and
false. Replace the previous values ON and OFF with them.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.30 -r1.31 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.30 src/usr.bin/indent/args.c:1.31
--- src/usr.bin/indent/args.c:1.30	Sat Sep 25 22:16:58 2021
+++ src/usr.bin/indent/args.c	Sat Sep 25 23:38:45 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: args.c,v 1.30 2021/09/25 22:16:58 rillig Exp $	*/
+/*	$NetBSD: args.c,v 1.31 2021/09/25 23:38:45 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.30 2021/09/25 22:16:58 rillig Exp $");
+__RCSID("$NetBSD: args.c,v 1.31 2021/09/25 23:38:45 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/args.c 336318 2018-07-15 21:04:21Z pstef $");
 #endif
@@ -70,21 +70,16 @@ __FBSDID("$FreeBSD: head/usr.bin/indent/
 #define	PRO_BOOL	2	/* boolean */
 #define	PRO_INT		3	/* integer */
 
-/* profile specials for booleans */
-#define	ON		1	/* turn it on */
-#define	OFF		0	/* turn it off */
-
 /* profile specials for specials */
 #define	IGN		1	/* ignore it */
 #define	CLI		2	/* case label indent (float) */
 #define	STDIN		3	/* use stdin */
 #define	KEY		4	/* type (keyword) */
-
-static void scan_profile(FILE *);
-
 #define	KEY_FILE	5	/* only used for args */
 #define VERSION		6	/* only used for args */
 
+static void scan_profile(FILE *);
+
 const char *option_source = "?";
 
 void add_typedefs_from_file(const char *);
@@ -95,9 +90,10 @@ void add_typedefs_from_file(const char *
 #define assert_type(expr, type) (expr)
 #endif
 #define bool_option(name, value, var) \
-	{name, PRO_BOOL, value, assert_type(&(var), bool *)}
-#define int_option(name, value, var) \
-	{name, PRO_INT, value, assert_type(&(var), int *)}
+	{name, PRO_BOOL, /*CONSTCOND*/(value) ? 1 : 0, \
+	assert_type(&(var), bool *)}
+#define int_option(name, var) \
+	{name, PRO_INT, 0, assert_type(&(var), int *)}
 #define special_option(name, value) \
 	{name, PRO_SPECIAL, assert_type(value, int), NULL}
 
@@ -116,72 +112,72 @@ static const struct pro {
 special_option("U", KEY_FILE),
 special_option("-version", VERSION),
 special_option("P", IGN),
-bool_option("bacc", ON, opt.blanklines_around_conditional_compilation),
-bool_option("badp", ON, opt.blanklines_after_declarations_at_proctop),
-bool_option("bad", ON, opt.blanklines_after_declarations),
-bool_option("bap", ON, opt.blanklines_after_procs),
-bool_option("bbb", ON, opt.blanklines_before_blockcomments),
-bool_option("bc", OFF, opt.leave_comma),
-bool_option("bl", OFF, opt.btype_2),
-bool_option("br", ON, opt.btype_2),
-bool_option("bs", ON, opt.blank_after_sizeof),
-bool_option("cdb", ON, opt.comment_delimiter_on_blankline),
-int_option("cd", 0, opt.decl_comment_column),
-bool_option("ce", ON, opt.cuddle_else),
-int_option("ci", 0, opt.continuation_indent),
+bool_option("bacc", true, opt.blanklines_around_conditional_compilation),
+bool_option("badp", true, opt.blanklines_after_declarations_at_proctop),
+bool_option("bad", true, opt.blanklines_after_declarations),
+bool_option("bap", true, opt.blanklines_after_procs),
+bool_option("bbb", true, opt.blanklines_before_blockcomments),
+bool_option("bc", false, opt.leave_comma),
+bool_option("bl", false, opt.btype_2),
+bool_option("br", true, opt.btype_2),
+bool_option("bs", true, opt.blank_after_sizeof),
+bool_option("cdb", true, opt.comment_delimiter_on_blankline),
+int_option("cd", opt.decl_comment_column),
+bool_option("ce", true, opt.cuddle_else),
+int_option("ci", opt.continuation_indent),
 special_option("cli", CLI),
-bool_option("cs", ON, opt.space_after_cast),
-int_option("c", 0, opt.comment_column),
-int_option("di", 0, opt.decl_indent),
-bool_option("dj", ON, opt.ljust_decl),
-int_option("d", 0, opt.unindent_displace),
-bool_option("eei", ON, opt.extra_expression_indent),
-bool_option("ei", ON, opt.else_if),
-bool_option("fbs", ON, opt.function_brace_split),
-bool_option("fc1", ON, opt.format_col1_comments),
-bool_option("fcb", ON, opt.format_block_comments),
-bool_option("ip", ON, opt.indent_parameters),
-int_option("i", 0, opt.indent_size),
-int_option("lc", 0, opt.block_comment_max_line_length),
-int_option("ldi", 0, opt.local_decl_indent),
-bool_option("lpl", ON, 

CVS commit: src/usr.bin/indent

2021-09-25 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Sep 25 23:38:45 UTC 2021

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

Log Message:
indent: reduce abstraction layer for defining boolean options

When initializing a boolean option, the most natural values are true and
false. Replace the previous values ON and OFF with them.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.30 -r1.31 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-09-25 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Sep 25 22:57:05 UTC 2021

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

Log Message:
indent: misc cleanup

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.83 -r1.84 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.36 -r1.37 src/usr.bin/indent/indent_globs.h
cvs rdiff -u -r1.65 -r1.66 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-09-25 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Sep 25 22:57:05 UTC 2021

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

Log Message:
indent: misc cleanup

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.83 -r1.84 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.36 -r1.37 src/usr.bin/indent/indent_globs.h
cvs rdiff -u -r1.65 -r1.66 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.83 src/usr.bin/indent/indent.c:1.84
--- src/usr.bin/indent/indent.c:1.83	Sat Sep 25 22:54:32 2021
+++ src/usr.bin/indent/indent.c	Sat Sep 25 22:57:04 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.83 2021/09/25 22:54:32 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.84 2021/09/25 22:57:04 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.83 2021/09/25 22:54:32 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.84 2021/09/25 22:57:04 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -529,7 +529,7 @@ process_comment_in_code(token_type ttype
 }
 
 ps.in_stmt = true;		/* turn on flag which causes an extra level of
- * indentation. this is turned off by a ; or
+ * indentation. this is turned off by a ';' or
  * '}' */
 if (com.s != com.e) {	/* the turkey has embedded a comment
  * in a line. fix it */
@@ -1210,7 +1210,7 @@ main_loop(void)
 int squest;			/* when this is positive, we have seen a '?'
  * without the matching ':' in a ?:
  * construct */
-bool scase;			/* set to true when we see a case, so we will
+bool scase;			/* set to true when we see a 'case', so we
  * know what to do with the following colon */
 
 sp_sw = force_nl = false;

Index: src/usr.bin/indent/indent_globs.h
diff -u src/usr.bin/indent/indent_globs.h:1.36 src/usr.bin/indent/indent_globs.h:1.37
--- src/usr.bin/indent/indent_globs.h:1.36	Sat Sep 25 22:54:32 2021
+++ src/usr.bin/indent/indent_globs.h	Sat Sep 25 22:57:04 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent_globs.h,v 1.36 2021/09/25 22:54:32 rillig Exp $	*/
+/*	$NetBSD: indent_globs.h,v 1.37 2021/09/25 22:57:04 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -137,7 +137,7 @@ extern struct options {
  * will be lined up to the open paren */
 bool	proc_calls_space; /* whether procedure calls look like:
  * foo (bar) rather than foo(bar) */
-bool	procnames_start_line; /* whether, the names of procedures
+bool	procnames_start_line; /* whether the names of procedures
  * being defined get placed in column 1 (i.e.
  * a newline is placed between the type of
  * the procedure and its name) */
@@ -208,11 +208,11 @@ extern struct parser_state {
 int not_cast_mask;	/* indicates which close parens definitely
  * close off something else than casts */
 bool	block_init;	/* whether inside a block initialization */
-int block_init_level;	/* The level of brace nesting in an
-	 * initialization */
-bool	last_nl;	/* this is true if the last thing scanned was
+int block_init_level; /* The level of brace nesting in an
+ * initialization */
+bool	last_nl;	/* whether the last thing scanned was
  * a newline */
-bool	in_or_st;	/* Will be true iff there has been a
+bool	in_or_st;	/* true iff there has been a
  * declarator (e.g. int or char) and no left
  * paren since the last semicolon. When true,
  * a '{' is starting a structure definition or
@@ -229,7 +229,7 @@ extern struct parser_state {
 bool	in_decl;	/* whether we are in a declaration stmt.
  * The processing of braces is then slightly
  * different */
-bool	in_stmt;	/* whether in a stmt */
+bool	in_stmt;
 int ind_level;	/* the current indentation level */
 bool	ind_stmt;	/* whether the next line should have an extra
  * indentation level because we are in the

Index: src/usr.bin/indent/io.c
diff -u src/usr.bin/indent/io.c:1.65 src/usr.bin/indent/io.c:1.66
--- src/usr.bin/indent/io.c:1.65	Sat Sep 25 22:54:32 2021
+++ src/usr.bin/indent/io.c	Sat Sep 25 22:57:04 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: io.c,v 1.65 2021/09/25 22:54:32 rillig Exp $	*/
+/*	$NetBSD: io.c,v 1.66 2021/09/25 22:57:04 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,21 +43,19 @@ static char sccsid[] = "@(#)io.c	8.1 (Be
 
 #include 
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: io.c,v 1.65 2021/09/25 22:54:32 rillig Exp $");
+__RCSID("$NetBSD: io.c,v 1.66 2021/09/25 22:57:04 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/io.c 334927 2018-06-10 16:44:18Z 

CVS commit: src/usr.bin/indent

2021-09-25 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Sep 25 22:54:32 UTC 2021

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

Log Message:
indent: convert found_err to bool

That variable had slipped through the migration since it consequently
used int for the declaration, the definition and all assignments.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.82 -r1.83 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.35 -r1.36 src/usr.bin/indent/indent_globs.h
cvs rdiff -u -r1.64 -r1.65 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.82 src/usr.bin/indent/indent.c:1.83
--- src/usr.bin/indent/indent.c:1.82	Sat Sep 25 22:24:35 2021
+++ src/usr.bin/indent/indent.c	Sat Sep 25 22:54:32 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.82 2021/09/25 22:24:35 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.83 2021/09/25 22:54: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.82 2021/09/25 22:24:35 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.83 2021/09/25 22:54:32 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -105,7 +105,7 @@ char   *sc_end;
 char   *bp_save;
 char   *be_save;
 
-int found_err;
+boolfound_err;
 int n_real_blanklines;
 boolprefix_blankline_requested;
 boolpostfix_blankline_requested;
@@ -376,7 +376,7 @@ buf_expand(struct buffer *buf, size_t de
 static void
 main_init_globals(void)
 {
-found_err = 0;
+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
@@ -510,7 +510,7 @@ process_end_of_file(void)
 }
 
 fflush(output);
-exit(found_err);
+exit(found_err ? EXIT_FAILURE : EXIT_SUCCESS);
 }
 
 static void

Index: src/usr.bin/indent/indent_globs.h
diff -u src/usr.bin/indent/indent_globs.h:1.35 src/usr.bin/indent/indent_globs.h:1.36
--- src/usr.bin/indent/indent_globs.h:1.35	Sat Sep 25 20:56:53 2021
+++ src/usr.bin/indent/indent_globs.h	Sat Sep 25 22:54:32 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent_globs.h,v 1.35 2021/09/25 20:56:53 rillig Exp $	*/
+/*	$NetBSD: indent_globs.h,v 1.36 2021/09/25 22:54:32 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -173,7 +173,7 @@ enum rwcode {
 };
 
 
-extern int found_err;
+extern boolfound_err;
 extern int n_real_blanklines;
 extern boolprefix_blankline_requested;
 extern boolpostfix_blankline_requested;

Index: src/usr.bin/indent/io.c
diff -u src/usr.bin/indent/io.c:1.64 src/usr.bin/indent/io.c:1.65
--- src/usr.bin/indent/io.c:1.64	Sat Sep 25 20:56:53 2021
+++ src/usr.bin/indent/io.c	Sat Sep 25 22:54:32 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: io.c,v 1.64 2021/09/25 20:56:53 rillig Exp $	*/
+/*	$NetBSD: io.c,v 1.65 2021/09/25 22:54:32 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.64 2021/09/25 20:56:53 rillig Exp $");
+__RCSID("$NetBSD: io.c,v 1.65 2021/09/25 22:54:32 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/io.c 334927 2018-06-10 16:44:18Z pstef $");
 #endif
@@ -466,7 +466,7 @@ diag(int level, const char *msg, ...)
 const char *s, *e;
 
 if (level != 0)
-	found_err = 1;
+	found_err = true;
 
 if (output == stdout) {
 	s = "/**INDENT** ";



CVS commit: src/usr.bin/indent

2021-09-25 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Sep 25 22:54:32 UTC 2021

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

Log Message:
indent: convert found_err to bool

That variable had slipped through the migration since it consequently
used int for the declaration, the definition and all assignments.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.82 -r1.83 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.35 -r1.36 src/usr.bin/indent/indent_globs.h
cvs rdiff -u -r1.64 -r1.65 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-09-25 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Sep 25 22:24:35 UTC 2021

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

Log Message:
indent: use strlen instead of own implementation

The two loops looks similar but differ in a crucial detail that makes up
for a '+ 1'.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.81 -r1.82 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-09-25 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Sep 25 22:24:35 UTC 2021

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

Log Message:
indent: use strlen instead of own implementation

The two loops looks similar but differ in a crucial detail that makes up
for a '+ 1'.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.81 -r1.82 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.81 src/usr.bin/indent/indent.c:1.82
--- src/usr.bin/indent/indent.c:1.81	Sat Sep 25 22:14:21 2021
+++ src/usr.bin/indent/indent.c	Sat Sep 25 22:24:35 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.81 2021/09/25 22:14:21 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.82 2021/09/25 22:24:35 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.81 2021/09/25 22:14:21 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.82 2021/09/25 22:24:35 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -53,14 +53,14 @@ __FBSDID("$FreeBSD: head/usr.bin/indent/
 #include 
 #include 
 #endif
+#include 
 #include 
 #include 
 #include 
-#include 
 #include 
 #include 
 #include 
-#include 
+#include 
 
 #include "indent.h"
 
@@ -658,15 +658,7 @@ process_unary_op(int dec_ind, bool tabs_
 if (!ps.dumped_decl_indent && ps.in_decl && !ps.block_init &&
 	ps.procname[0] == '\0' && ps.paren_level == 0) {
 	/* pointer declarations */
-
-	/*
-	 * if this is a unary op in a declaration, we should indent
-	 * this token
-	 */
-	int i;
-	for (i = 0; token.s[i] != '\0'; ++i)
-	/* find length of token */;
-	indent_declaration(dec_ind - i, tabs_to_var);
+	indent_declaration(dec_ind - (int)strlen(token.s), tabs_to_var);
 	ps.dumped_decl_indent = true;
 } else if (ps.want_blank)
 	*code.e++ = ' ';
@@ -968,18 +960,13 @@ process_decl(int *out_dec_ind, bool *out
 if ( /* !ps.in_or_st && */ ps.decl_nest <= 0)
 	ps.just_saw_decl = 2;
 prefix_blankline_requested = false;
-int i;
-for (i = 0; token.s[i++] != '\0';);	/* get length of token */
 
-if (ps.ind_level == 0 || ps.decl_nest > 0) {
-	/* global variable or struct member in local variable */
-	*out_dec_ind = opt.decl_indent > 0 ? opt.decl_indent : i;
-	*out_tabs_to_var = opt.use_tabs ? opt.decl_indent > 0 : false;
-} else {
-	/* local variable */
-	*out_dec_ind = opt.local_decl_indent > 0 ? opt.local_decl_indent : i;
-	*out_tabs_to_var = opt.use_tabs ? opt.local_decl_indent > 0 : false;
-}
+int len = (int)strlen(token.s) + 1;
+int ind = ps.ind_level == 0 || ps.decl_nest > 0
+	? opt.decl_indent		/* global variable or local member */
+	: opt.local_decl_indent;	/* local variable */
+*out_dec_ind = ind > 0 ? ind : len;
+*out_tabs_to_var = opt.use_tabs ? ind > 0 : false;
 }
 
 static void



CVS commit: src/usr.bin/indent

2021-09-25 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Sep 25 22:16:58 UTC 2021

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

Log Message:
indent: clean up argument handling

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 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.29 src/usr.bin/indent/args.c:1.30
--- src/usr.bin/indent/args.c:1.29	Sat Sep 25 21:42:43 2021
+++ src/usr.bin/indent/args.c	Sat Sep 25 22:16:58 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: args.c,v 1.29 2021/09/25 21:42:43 rillig Exp $	*/
+/*	$NetBSD: args.c,v 1.30 2021/09/25 22:16:58 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.29 2021/09/25 21:42:43 rillig Exp $");
+__RCSID("$NetBSD: args.c,v 1.30 2021/09/25 22:16:58 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/args.c 336318 2018-07-15 21:04:21Z pstef $");
 #endif
@@ -87,7 +87,7 @@ static void scan_profile(FILE *);
 
 const char *option_source = "?";
 
-void add_typedefs_from_file(const char *str);
+void add_typedefs_from_file(const char *);
 
 #if __STDC_VERSION__ >= 201112L
 #define assert_type(expr, type) _Generic((expr), type : (expr))
@@ -247,13 +247,13 @@ scan_profile(FILE *f)
 }
 
 static const char *
-eqin(const char *s1, const char *s2)
+skip_over(const char *s, const char *prefix)
 {
-while (*s1 != '\0') {
-	if (*s1++ != *s2++)
+while (*prefix != '\0') {
+	if (*prefix++ != *s++)
 	return NULL;
 }
-return s2;
+return s;
 }
 
 void
@@ -264,9 +264,11 @@ set_option(const char *arg)
 
 arg++;			/* ignore leading "-" */
 for (p = pro; p->p_name[0] != '\0'; p++)
-	if (*p->p_name == *arg && (param_start = eqin(p->p_name, arg)) != NULL)
-	goto found;
+	if (p->p_name[0] == arg[0])
+	if ((param_start = skip_over(arg, p->p_name)) != NULL)
+		goto found;
 errx(1, "%s: unknown parameter \"%s\"", option_source, arg - 1);
+
 found:
 switch (p->p_type) {
 
@@ -277,7 +279,7 @@ found:
 	break;
 
 	case CLI:
-	if (*param_start == 0)
+	if (param_start[0] == '\0')
 		goto need_param;
 	opt.case_indent = atof(param_start);
 	break;
@@ -290,13 +292,13 @@ found:
 	break;
 
 	case KEY:
-	if (*param_start == 0)
+	if (param_start[0] == '\0')
 		goto need_param;
 	add_typename(param_start);
 	break;
 
 	case KEY_FILE:
-	if (*param_start == 0)
+	if (param_start[0] == '\0')
 		goto need_param;
 	add_typedefs_from_file(param_start);
 	break;
@@ -329,13 +331,13 @@ found:
 }
 
 void
-add_typedefs_from_file(const char *str)
+add_typedefs_from_file(const char *fname)
 {
 FILE *file;
 char line[BUFSIZ];
 
-if ((file = fopen(str, "r")) == NULL) {
-	fprintf(stderr, "indent: cannot open file %s\n", str);
+if ((file = fopen(fname, "r")) == NULL) {
+	fprintf(stderr, "indent: cannot open file %s\n", fname);
 	exit(1);
 }
 while ((fgets(line, BUFSIZ, file)) != NULL) {



CVS commit: src/usr.bin/indent

2021-09-25 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Sep 25 22:16:58 UTC 2021

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

Log Message:
indent: clean up argument handling

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 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-09-25 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Sep 25 22:14:21 UTC 2021

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

Log Message:
indent: merge duplicate code for token buffers

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.80 -r1.81 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.24 -r1.25 src/usr.bin/indent/indent.h
cvs rdiff -u -r1.57 -r1.58 src/usr.bin/indent/lexi.c
cvs rdiff -u -r1.45 -r1.46 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.80 src/usr.bin/indent/indent.c:1.81
--- src/usr.bin/indent/indent.c:1.80	Sat Sep 25 21:42:43 2021
+++ src/usr.bin/indent/indent.c	Sat Sep 25 22:14:21 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.80 2021/09/25 21:42:43 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.81 2021/09/25 22:14: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.80 2021/09/25 21:42:43 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.81 2021/09/25 22:14:21 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -137,29 +137,15 @@ charbakfile[MAXPATHLEN] = "";
 static void
 check_size_code(size_t desired_size)
 {
-if (code.e + desired_size < code.l)
-return;
-
-size_t nsize = code.l - code.s + 400 + desired_size;
-size_t code_len = code.e - code.s;
-code.buf = xrealloc(code.buf, nsize);
-code.e = code.buf + code_len + 1;
-code.l = code.buf + nsize - 5;
-code.s = code.buf + 1;
+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)
-return;
-
-size_t nsize = lab.l - lab.s + 400 + desired_size;
-size_t label_len = lab.e - lab.s;
-lab.buf = xrealloc(lab.buf, nsize);
-lab.e = lab.buf + label_len + 1;
-lab.l = lab.buf + nsize - 5;
-lab.s = lab.buf + 1;
+if (lab.e + desired_size >= lab.l)
+	buf_expand(, desired_size);
 }
 
 #if HAVE_CAPSICUM
@@ -376,6 +362,17 @@ buf_init(struct buffer *buf)
 buf->l = buf->buf + bufsize - 5;	/* safety margin, though unreliable */
 }
 
+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;
+buf->buf = xrealloc(buf->buf, nsize);
+buf->e = buf->buf + code_len + 1;
+buf->l = buf->buf + nsize - 5;
+buf->s = buf->buf + 1;
+}
+
 static void
 main_init_globals(void)
 {

Index: src/usr.bin/indent/indent.h
diff -u src/usr.bin/indent/indent.h:1.24 src/usr.bin/indent/indent.h:1.25
--- src/usr.bin/indent/indent.h:1.24	Sat Sep 25 21:42:43 2021
+++ src/usr.bin/indent/indent.h	Sat Sep 25 22:14:21 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.h,v 1.24 2021/09/25 21:42:43 rillig Exp $	*/
+/*	$NetBSD: indent.h,v 1.25 2021/09/25 22:14:21 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -70,3 +70,5 @@ void		set_profile(const char *);
 void		*xmalloc(size_t);
 void		*xrealloc(void *, size_t);
 char		*xstrdup(const char *);
+
+void		buf_expand(struct buffer *, size_t);

Index: src/usr.bin/indent/lexi.c
diff -u src/usr.bin/indent/lexi.c:1.57 src/usr.bin/indent/lexi.c:1.58
--- src/usr.bin/indent/lexi.c:1.57	Sat Sep 25 20:05:55 2021
+++ src/usr.bin/indent/lexi.c	Sat Sep 25 22:14:21 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: lexi.c,v 1.57 2021/09/25 20:05:55 rillig Exp $	*/
+/*	$NetBSD: lexi.c,v 1.58 2021/09/25 22:14: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.57 2021/09/25 20:05:55 rillig Exp $");
+__RCSID("$NetBSD: lexi.c,v 1.58 2021/09/25 22:14:21 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/lexi.c 337862 2018-08-15 18:19:45Z pstef $");
 #endif
@@ -205,15 +205,8 @@ inbuf_next(void)
 static void
 check_size_token(size_t desired_size)
 {
-if (token.e + (desired_size) < token.l)
-return;
-
-size_t nsize = token.l - token.s + 400 + desired_size;
-size_t token_len = token.e - token.s;
-token.buf = xrealloc(token.buf, nsize);
-token.e = token.buf + token_len + 1;
-token.l = token.buf + nsize - 5;
-token.s = token.buf + 1;
+if (token.e + desired_size >= token.l)
+	buf_expand(, desired_size);
 }
 
 static int

Index: src/usr.bin/indent/pr_comment.c
diff -u src/usr.bin/indent/pr_comment.c:1.45 src/usr.bin/indent/pr_comment.c:1.46
--- src/usr.bin/indent/pr_comment.c:1.45	Sat Sep 25 20:23:42 2021
+++ src/usr.bin/indent/pr_comment.c	Sat Sep 25 22:14:21 2021

CVS commit: src/usr.bin/indent

2021-09-25 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Sep 25 22:14:21 UTC 2021

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

Log Message:
indent: merge duplicate code for token buffers

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.80 -r1.81 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.24 -r1.25 src/usr.bin/indent/indent.h
cvs rdiff -u -r1.57 -r1.58 src/usr.bin/indent/lexi.c
cvs rdiff -u -r1.45 -r1.46 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-09-25 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Sep 25 21:42:43 UTC 2021

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

Log Message:
indent: clean up argument handling

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/usr.bin/indent/args.c
cvs rdiff -u -r1.79 -r1.80 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.23 -r1.24 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.28 src/usr.bin/indent/args.c:1.29
--- src/usr.bin/indent/args.c:1.28	Sat Sep 25 21:20:59 2021
+++ src/usr.bin/indent/args.c	Sat Sep 25 21:42:43 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: args.c,v 1.28 2021/09/25 21:20:59 rillig Exp $	*/
+/*	$NetBSD: args.c,v 1.29 2021/09/25 21:42:43 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.28 2021/09/25 21:20:59 rillig Exp $");
+__RCSID("$NetBSD: args.c,v 1.29 2021/09/25 21:42:43 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/args.c 336318 2018-07-15 21:04:21Z pstef $");
 #endif
@@ -56,6 +56,7 @@ __FBSDID("$FreeBSD: head/usr.bin/indent/
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -102,14 +103,14 @@ void add_typedefs_from_file(const char *
 
 /*
  * N.B.: because of the way the table here is scanned, options whose names are
- * substrings of other options must occur later; that is, with -lp vs -l, -lp
- * must be first.
+ * a prefix of other options must occur later; that is, with -lp vs -l, -lp
+ * must be first and -l must be last.
  */
-const struct pro {
+static const struct pro {
 const char  p_name[9];	/* name, e.g. "bl", "cli" */
-int p_type;		/* type (int, bool, special) */
+uint8_t p_type;		/* type (int, bool, special) */
 int p_special;	/* depends on type */
-void*p_obj;		/* the associated variable */
+void*p_obj;		/* the associated variable (bool, int) */
 }   pro[] = {
 special_option("T", KEY),
 special_option("U", KEY_FILE),
@@ -256,7 +257,7 @@ eqin(const char *s1, const char *s2)
 }
 
 void
-set_option(char *arg)
+set_option(const char *arg)
 {
 const struct pro *p;
 const char	*param_start;
@@ -311,10 +312,7 @@ found:
 	break;
 
 case PRO_BOOL:
-	if (p->p_special == OFF)
-	*(bool *)p->p_obj = false;
-	else
-	*(bool *)p->p_obj = true;
+	*(bool *)p->p_obj = p->p_special == ON;
 	break;
 
 case PRO_INT:

Index: src/usr.bin/indent/indent.c
diff -u src/usr.bin/indent/indent.c:1.79 src/usr.bin/indent/indent.c:1.80
--- src/usr.bin/indent/indent.c:1.79	Sat Sep 25 20:56:53 2021
+++ src/usr.bin/indent/indent.c	Sat Sep 25 21:42:43 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.79 2021/09/25 20:56:53 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.80 2021/09/25 21:42:43 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.79 2021/09/25 20:56:53 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.80 2021/09/25 21:42:43 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -427,32 +427,27 @@ main_parse_command_line(int argc, char *
 	set_profile(profile_name);
 
 for (i = 1; i < argc; ++i) {
+	if (argv[i][0] == '-') {
+	set_option(argv[i]);
+
+	} else if (input == NULL) {
+	in_name = argv[i];
+	input = fopen(in_name, "r");
+	if (input == NULL)
+		err(1, "%s", in_name);
+
+	} else if (output == NULL) {
+	out_name = argv[i];
+	if (strcmp(in_name, out_name) == 0)
+		errx(1, "input and output files must be different");
+	output = fopen(out_name, "w");
+	if (output == NULL)
+		err(1, "%s", out_name);
 
-	/*
-	 * look thru args (if any) for changes to defaults
-	 */
-	if (argv[i][0] != '-') {/* no flag on parameter */
-	if (input == NULL) {	/* we must have the input file */
-		in_name = argv[i];	/* remember name of input file */
-		input = fopen(in_name, "r");
-		if (input == NULL)	/* check for open error */
-			err(1, "%s", in_name);
-		continue;
-	} else if (output == NULL) {	/* we have the output file */
-		out_name = argv[i];	/* remember name of output file */
-		if (strcmp(in_name, out_name) == 0) {	/* attempt to overwrite
-			 * the file */
-		errx(1, "input and output files must be different");
-		}
-		output = fopen(out_name, "w");
-		if (output == NULL)	/* check for create error */
-			err(1, "%s", out_name);
-		continue;
-	}
-	errx(1, "unknown parameter: %s", argv[i]);
 	} else
-	set_option(argv[i]);
-}/* end of for */
+	errx(1, "unknown 

CVS commit: src/usr.bin/indent

2021-09-25 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Sep 25 21:42:43 UTC 2021

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

Log Message:
indent: clean up argument handling

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/usr.bin/indent/args.c
cvs rdiff -u -r1.79 -r1.80 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.23 -r1.24 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-09-25 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Sep 25 21:21:00 UTC 2021

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

Log Message:
indent: reduce binary size

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 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.27 src/usr.bin/indent/args.c:1.28
--- src/usr.bin/indent/args.c:1.27	Sat Sep 25 18:49:03 2021
+++ src/usr.bin/indent/args.c	Sat Sep 25 21:20:59 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: args.c,v 1.27 2021/09/25 18:49:03 rillig Exp $	*/
+/*	$NetBSD: args.c,v 1.28 2021/09/25 21:20:59 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.27 2021/09/25 18:49:03 rillig Exp $");
+__RCSID("$NetBSD: args.c,v 1.28 2021/09/25 21:20:59 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/args.c 336318 2018-07-15 21:04:21Z pstef $");
 #endif
@@ -106,7 +106,7 @@ void add_typedefs_from_file(const char *
  * must be first.
  */
 const struct pro {
-const char *p_name;		/* name, e.g. -bl, -cli */
+const char  p_name[9];	/* name, e.g. "bl", "cli" */
 int p_type;		/* type (int, bool, special) */
 int p_special;	/* depends on type */
 void*p_obj;		/* the associated variable */
@@ -182,7 +182,7 @@ const struct pro {
 bool_option("ut", ON, opt.use_tabs),
 bool_option("v", ON, opt.verbose),
 /* whew! */
-{0, 0, 0, 0}
+{"", 0, 0, 0}
 };
 
 /*
@@ -262,7 +262,7 @@ set_option(char *arg)
 const char	*param_start;
 
 arg++;			/* ignore leading "-" */
-for (p = pro; p->p_name != NULL; p++)
+for (p = pro; p->p_name[0] != '\0'; p++)
 	if (*p->p_name == *arg && (param_start = eqin(p->p_name, arg)) != NULL)
 	goto found;
 errx(1, "%s: unknown parameter \"%s\"", option_source, arg - 1);



CVS commit: src/usr.bin/indent

2021-09-25 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Sep 25 21:21:00 UTC 2021

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

Log Message:
indent: reduce binary size

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 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-09-25 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Sep 25 20:56:53 UTC 2021

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

Log Message:
indent: un-abbreviate a few parser_state members, clean up comments

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.78 -r1.79 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.34 -r1.35 src/usr.bin/indent/indent_globs.h
cvs rdiff -u -r1.63 -r1.64 src/usr.bin/indent/io.c
cvs rdiff -u -r1.25 -r1.26 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/indent.c
diff -u src/usr.bin/indent/indent.c:1.78 src/usr.bin/indent/indent.c:1.79
--- src/usr.bin/indent/indent.c:1.78	Sat Sep 25 20:23:42 2021
+++ src/usr.bin/indent/indent.c	Sat Sep 25 20:56:53 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.78 2021/09/25 20:23:42 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.79 2021/09/25 20:56:53 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.78 2021/09/25 20:23:42 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.79 2021/09/25 20:56:53 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -498,7 +498,7 @@ main_prepare_parsing(void)
 	p++;
 }
 if (col > opt.indent_size)
-	ps.ind_level = ps.i_l_follow = col / opt.indent_size;
+	ps.ind_level = ps.ind_level_follow = col / opt.indent_size;
 }
 
 static void __attribute__((__noreturn__))
@@ -769,7 +769,7 @@ process_semicolon(bool *inout_scase, int
 		  token_type hd_type,
 		  bool *inout_force_nl)
 {
-if (ps.dec_nest == 0)
+if (ps.decl_nest == 0)
 	ps.in_or_st = false;	/* we are not in an initialization or
  * structure declaration */
 *inout_scase = false; /* these will only need resetting in an error */
@@ -789,7 +789,7 @@ process_semicolon(bool *inout_scase, int
 	ps.dumped_decl_indent = true;
 }
 
-ps.in_decl = (ps.dec_nest > 0);	/* if we were in a first level
+ps.in_decl = (ps.decl_nest > 0);	/* if we were in a first level
 		 * structure declaration, we
 		 * arent any more */
 
@@ -837,7 +837,7 @@ process_lbrace(bool *inout_force_nl, boo
 	dump_line();
 	ps.want_blank = false;
 	} else if (ps.in_parameter_declaration && !ps.in_or_st) {
-	ps.i_l_follow = 0;
+	ps.ind_level_follow = 0;
 	if (opt.function_brace_split) { /* dump the line prior
  * to the brace ... */
 		dump_line();
@@ -856,7 +856,7 @@ process_lbrace(bool *inout_force_nl, boo
 	if (*inout_sp_sw) {	/* check for unclosed if, for, etc. */
 	*inout_sp_sw = false;
 	parse(hd_type);
-	ps.ind_level = ps.i_l_follow;
+	ps.ind_level = ps.ind_level_follow;
 	}
 }
 if (code.s == code.e)
@@ -864,11 +864,11 @@ process_lbrace(bool *inout_force_nl, boo
  * with '{' */
 if (ps.in_decl && ps.in_or_st) {	/* this is either a structure
  * declaration or an init */
-	di_stack[ps.dec_nest] = *inout_dec_ind;
-	if (++ps.dec_nest == di_stack_cap) {
+	di_stack[ps.decl_nest] = *inout_dec_ind;
+	if (++ps.decl_nest == di_stack_cap) {
 	diag(0, "Reached internal limit of %d struct levels",
 		 di_stack_cap);
-	ps.dec_nest--;
+	ps.decl_nest--;
 	}
 	/* ?		dec_ind = 0; */
 } else {
@@ -913,9 +913,9 @@ process_rbrace(bool *inout_sp_sw, int *i
 *code.e++ = '}';
 ps.want_blank = true;
 ps.in_stmt = ps.ind_stmt = false;
-if (ps.dec_nest > 0) { /* we are in multi-level structure declaration */
-	*inout_dec_ind = di_stack[--ps.dec_nest];
-	if (ps.dec_nest == 0 && !ps.in_parameter_declaration)
+if (ps.decl_nest > 0) { /* we are in multi-level structure declaration */
+	*inout_dec_ind = di_stack[--ps.decl_nest];
+	if (ps.decl_nest == 0 && !ps.in_parameter_declaration)
 	ps.just_saw_decl = 2;
 	ps.in_decl = true;
 }
@@ -924,7 +924,7 @@ process_rbrace(bool *inout_sp_sw, int *i
 ps.search_brace = opt.cuddle_else
 		  && ps.p_stack[ps.tos] == if_expr_stmt
 		  && ps.il[ps.tos] >= ps.ind_level;
-if (ps.tos <= 1 && opt.blanklines_after_procs && ps.dec_nest <= 0)
+if (ps.tos <= 1 && opt.blanklines_after_procs && ps.decl_nest <= 0)
 	postfix_blankline_requested = true;
 }
 
@@ -965,20 +965,21 @@ process_decl(int *out_dec_ind, bool *out
 	ps.want_blank = false;
 	}
 }
-if (ps.in_parameter_declaration && opt.indent_parameters && ps.dec_nest == 0) {
-	ps.ind_level = ps.i_l_follow = 1;
+if (ps.in_parameter_declaration && opt.indent_parameters &&
+	ps.decl_nest == 0) {
+	ps.ind_level = ps.ind_level_follow = 1;
 	ps.ind_stmt = false;
 }
 ps.in_or_st = true;		/* this might be a structure or initialization
  * declaration */
 ps.in_decl = ps.decl_on_line = ps.last_token != type_def;
-if ( /* !ps.in_or_st 

CVS commit: src/usr.bin/indent

2021-09-25 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Sep 25 20:56:53 UTC 2021

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

Log Message:
indent: un-abbreviate a few parser_state members, clean up comments

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.78 -r1.79 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.34 -r1.35 src/usr.bin/indent/indent_globs.h
cvs rdiff -u -r1.63 -r1.64 src/usr.bin/indent/io.c
cvs rdiff -u -r1.25 -r1.26 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-09-25 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Sep 25 20:23:42 UTC 2021

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

Log Message:
indent: remove dead code for printing comments after empty lines

This code has been commented out for at least 29 years.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.77 -r1.78 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.33 -r1.34 src/usr.bin/indent/indent_globs.h
cvs rdiff -u -r1.62 -r1.63 src/usr.bin/indent/io.c
cvs rdiff -u -r1.44 -r1.45 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.77 src/usr.bin/indent/indent.c:1.78
--- src/usr.bin/indent/indent.c:1.77	Sat Sep 25 19:49:13 2021
+++ src/usr.bin/indent/indent.c	Sat Sep 25 20:23:42 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.77 2021/09/25 19:49:13 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.78 2021/09/25 20:23:42 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.77 2021/09/25 19:49:13 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.78 2021/09/25 20:23:42 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -398,7 +398,6 @@ main_init_globals(void)
 line_no = 1;
 had_eof = ps.in_decl = ps.decl_on_line = (break_comma = false);
 ps.in_or_st = false;
-ps.bl_line = true;
 ps.want_blank = ps.in_stmt = ps.ind_stmt = false;
 
 ps.pcase = false;

Index: src/usr.bin/indent/indent_globs.h
diff -u src/usr.bin/indent/indent_globs.h:1.33 src/usr.bin/indent/indent_globs.h:1.34
--- src/usr.bin/indent/indent_globs.h:1.33	Sat Sep 25 18:49:03 2021
+++ src/usr.bin/indent/indent_globs.h	Sat Sep 25 20:23:42 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent_globs.h,v 1.33 2021/09/25 18:49:03 rillig Exp $	*/
+/*	$NetBSD: indent_globs.h,v 1.34 2021/09/25 20:23:42 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -217,7 +217,6 @@ extern struct parser_state {
  * paren since the last semicolon. When true,
  * a '{' is starting a structure definition or
  * an initialization list */
-bool	bl_line;	/* set to 1 by dump_line if the line is blank */
 bool	col_1;		/* set to true if the last token started in
  * column 1 */
 int com_col;	/* this is the column in which the current

Index: src/usr.bin/indent/io.c
diff -u src/usr.bin/indent/io.c:1.62 src/usr.bin/indent/io.c:1.63
--- src/usr.bin/indent/io.c:1.62	Sat Sep 25 17:36:51 2021
+++ src/usr.bin/indent/io.c	Sat Sep 25 20:23:42 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: io.c,v 1.62 2021/09/25 17:36:51 rillig Exp $	*/
+/*	$NetBSD: io.c,v 1.63 2021/09/25 20:23:42 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.62 2021/09/25 17:36:51 rillig Exp $");
+__RCSID("$NetBSD: io.c,v 1.63 2021/09/25 20:23:42 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/io.c 334927 2018-06-10 16:44:18Z pstef $");
 #endif
@@ -122,13 +122,10 @@ dump_line(void)
 if (code.s == code.e && lab.s == lab.e && com.s == com.e) {
 	if (suppress_blanklines > 0)
 	suppress_blanklines--;
-	else {
-	ps.bl_line = true;
+	else
 	n_real_blanklines++;
-	}
 } else if (!inhibit_formatting) {
 	suppress_blanklines = 0;
-	ps.bl_line = false;
 	if (prefix_blankline_requested && not_first_line) {
 	if (opt.swallow_optional_blanklines) {
 		if (n_real_blanklines == 1)

Index: src/usr.bin/indent/pr_comment.c
diff -u src/usr.bin/indent/pr_comment.c:1.44 src/usr.bin/indent/pr_comment.c:1.45
--- src/usr.bin/indent/pr_comment.c:1.44	Sat Sep 25 17:36:51 2021
+++ src/usr.bin/indent/pr_comment.c	Sat Sep 25 20:23:42 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: pr_comment.c,v 1.44 2021/09/25 17:36:51 rillig Exp $	*/
+/*	$NetBSD: pr_comment.c,v 1.45 2021/09/25 20:23:42 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@ static char sccsid[] = "@(#)pr_comment.c
 
 #include 
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: pr_comment.c,v 1.44 2021/09/25 17:36:51 rillig Exp $");
+__RCSID("$NetBSD: pr_comment.c,v 1.45 2021/09/25 20:23:42 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/pr_comment.c 334927 2018-06-10 16:44:18Z pstef $");
 #endif
@@ -124,12 +124,7 @@ process_comment(void)
  * is nonzero (the default). */
 	break_delim = false;
 	}
-	if ( /* ps.bl_line && */ lab.s == lab.e && code.s == code.e) {
-	/* klg: check only if this line is blank */
-	/*
-	 * If this (*and previous lines are*) blank, dont put comment way
-	 * out 

CVS commit: src/usr.bin/indent

2021-09-25 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Sep 25 20:23:42 UTC 2021

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

Log Message:
indent: remove dead code for printing comments after empty lines

This code has been commented out for at least 29 years.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.77 -r1.78 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.33 -r1.34 src/usr.bin/indent/indent_globs.h
cvs rdiff -u -r1.62 -r1.63 src/usr.bin/indent/io.c
cvs rdiff -u -r1.44 -r1.45 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-09-25 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Sep 25 20:05:55 UTC 2021

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

Log Message:
indent: extract probably_typedef into separate function

This condition is complicated enough that it warrants being split into
several clauses, maybe even with an explanation.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.56 -r1.57 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/lexi.c
diff -u src/usr.bin/indent/lexi.c:1.56 src/usr.bin/indent/lexi.c:1.57
--- src/usr.bin/indent/lexi.c:1.56	Sat Sep 25 19:49:13 2021
+++ src/usr.bin/indent/lexi.c	Sat Sep 25 20:05:55 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: lexi.c,v 1.56 2021/09/25 19:49:13 rillig Exp $	*/
+/*	$NetBSD: lexi.c,v 1.57 2021/09/25 20:05:55 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.56 2021/09/25 19:49:13 rillig Exp $");
+__RCSID("$NetBSD: lexi.c,v 1.57 2021/09/25 20:05:55 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/lexi.c 337862 2018-08-15 18:19:45Z pstef $");
 #endif
@@ -336,6 +336,20 @@ lex_char_or_string(void)
 }
 }
 
+/*
+ * This hack attempts to guess whether the current token is in fact a
+ * declaration keyword -- one that has been defined by typedef.
+ */
+static bool
+probably_typedef(const struct parser_state *state)
+{
+return state->p_l_follow == 0 && !state->block_init && !state->in_stmt &&
+	   ((*buf_ptr == '*' && buf_ptr[1] != '=') ||
+	isalpha((unsigned char)*buf_ptr)) &&
+	   (state->last_token == semicolon || state->last_token == lbrace ||
+	state->last_token == rbrace);
+}
+
 /* Reads the next token, placing it in the global variable "token". */
 token_type
 lexi(struct parser_state *state)
@@ -460,18 +474,7 @@ lexi(struct parser_state *state)
 		state->in_parameter_declaration = true;
 	return lexi_end(funcname);
 not_proc:;
-	}
-	/*
-	 * The following hack attempts to guess whether or not the current
-	 * token is in fact a declaration keyword -- one that has been
-	 * typedefd
-	 */
-	else if (state->p_l_follow == 0 && !state->block_init &&
-	!state->in_stmt &&
-	((*buf_ptr == '*' && buf_ptr[1] != '=') ||
-		isalpha((unsigned char)*buf_ptr)) &&
-	(state->last_token == semicolon || state->last_token == lbrace ||
-		state->last_token == rbrace)) {
+	} else if (probably_typedef(state)) {
 	state->keyword = rw_type;
 	state->last_u_d = true;
 	return lexi_end(decl);



CVS commit: src/usr.bin/indent

2021-09-25 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Sep 25 20:05:55 UTC 2021

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

Log Message:
indent: extract probably_typedef into separate function

This condition is complicated enough that it warrants being split into
several clauses, maybe even with an explanation.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.56 -r1.57 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-09-25 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Sep 25 19:49:13 UTC 2021

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

Log Message:
indent: reduce code and data size for lexing of numbers

Instead of having a table of strings (121 pointers + 121 data
relocations), reduce that table to the actual character data and use a
secondary table for looking up the correct row in the main table.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.76 -r1.77 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.22 -r1.23 src/usr.bin/indent/indent.h
cvs rdiff -u -r1.55 -r1.56 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.76 src/usr.bin/indent/indent.c:1.77
--- src/usr.bin/indent/indent.c:1.76	Sat Sep 25 18:49:03 2021
+++ src/usr.bin/indent/indent.c	Sat Sep 25 19:49:13 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.76 2021/09/25 18:49:03 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.77 2021/09/25 19:49: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.76 2021/09/25 18:49:03 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.77 2021/09/25 19:49:13 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -390,7 +390,6 @@ main_init_globals(void)
 buf_init();
 buf_init();
 alloc_typenames();
-init_constant_tt();
 opt.else_if = true;		/* XXX: redundant? */
 
 in_buffer = xmalloc(10);

Index: src/usr.bin/indent/indent.h
diff -u src/usr.bin/indent/indent.h:1.22 src/usr.bin/indent/indent.h:1.23
--- src/usr.bin/indent/indent.h:1.22	Sat Sep 25 17:36:51 2021
+++ src/usr.bin/indent/indent.h	Sat Sep 25 19:49:13 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.h,v 1.22 2021/09/25 17:36:51 rillig Exp $	*/
+/*	$NetBSD: indent.h,v 1.23 2021/09/25 19:49:13 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -47,7 +47,6 @@ int		compute_code_indent(void);
 int		compute_label_indent(void);
 int		indentation_after_range(int, const char *, const char *);
 int		indentation_after(int, const char *);
-void		init_constant_tt(void);
 #ifdef debug
 void		debug_vis_range(const char *, const char *, const char *,
 		const char *);

Index: src/usr.bin/indent/lexi.c
diff -u src/usr.bin/indent/lexi.c:1.55 src/usr.bin/indent/lexi.c:1.56
--- src/usr.bin/indent/lexi.c:1.55	Sat Sep 25 17:36:51 2021
+++ src/usr.bin/indent/lexi.c	Sat Sep 25 19:49:13 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: lexi.c,v 1.55 2021/09/25 17:36:51 rillig Exp $	*/
+/*	$NetBSD: lexi.c,v 1.56 2021/09/25 19:49: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.55 2021/09/25 17:36:51 rillig Exp $");
+__RCSID("$NetBSD: lexi.c,v 1.56 2021/09/25 19:49:13 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/lexi.c 337862 2018-08-15 18:19:45Z pstef $");
 #endif
@@ -52,6 +52,7 @@ __FBSDID("$FreeBSD: head/usr.bin/indent/
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -133,7 +134,7 @@ int typename_top = -1;
  * HP H* "." H+ P  FS? -> $float;"0" O*  IS? -> $int;
  * HP H+ "."P  FS  -> $float;BP B+   IS? -> $int;
  */
-static char const *table[] = {
+static const char num_lex_state[][26] = {
 /*examples:
  00
  s  0xx
@@ -142,40 +143,42 @@ static char const *table[] = {
  r   11ee0001101lbuuxx.a.pp
  t.01.e+008bLuxll0Ll.aa.p+0
 states:  ABCDEFGHIJKLMNOPQRSTUVWXYZ */
-['0'] = "CEIDEHHHIJQ  U  Q  VUVVZZZ",
-['1'] = "DEIDEHHHIJQ  U  Q  VUVVZZZ",
-['7'] = "DEIDEHHHIJ   U VUVVZZZ",
-['9'] = "DEJDEHHHJJ   U VUVVZZZ",
-['a'] = " U VUVV   ",
-['b'] = "  K  U VUVV   ",
-['e'] = "  FFF   FF   U VUVV   ",
-['f'] = "f  f U VUVV  f",
-['u'] = "  MMM  i  iiM   M ",
-['x'] = "  N   ",
-['p'] = "FFX   ",
-['L'] = "  LLf  fL  PR   Li  Lf",
-['l'] = "  OOf  fO   S P O i Of",
-['+'] = " G Y  ",
-['.'] = "B EEEE   T  W ",
+[0] =   "uuiifuufiuuiiuiuiu",
+[1] =   "CEIDEHHHIJQ  U  Q  VUVVZZZ",
+[2] =   "DEIDEHHHIJQ  U  Q  VUVVZZZ",
+[3] =   "DEIDEHHHIJ   U VUVVZZZ",
+[4] =   "DEJDEHHHJJ   U VUVVZZZ",
+[5] =   " U VUVV   ",
+[6] =   "  K  U VUVV   ",
+[7] =   "  FFF   FF   U VUVV   ",
+[8] =   

CVS commit: src/usr.bin/indent

2021-09-25 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Sep 25 19:49:13 UTC 2021

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

Log Message:
indent: reduce code and data size for lexing of numbers

Instead of having a table of strings (121 pointers + 121 data
relocations), reduce that table to the actual character data and use a
secondary table for looking up the correct row in the main table.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.76 -r1.77 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.22 -r1.23 src/usr.bin/indent/indent.h
cvs rdiff -u -r1.55 -r1.56 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-09-25 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Sep 25 18:49:03 UTC 2021

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

Log Message:
indent: rename option variable to be more expressive

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.27 src/usr.bin/indent/args.c
cvs rdiff -u -r1.75 -r1.76 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.32 -r1.33 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-09-25 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Sep 25 18:49:03 UTC 2021

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

Log Message:
indent: rename option variable to be more expressive

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.27 src/usr.bin/indent/args.c
cvs rdiff -u -r1.75 -r1.76 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.32 -r1.33 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/args.c
diff -u src/usr.bin/indent/args.c:1.26 src/usr.bin/indent/args.c:1.27
--- src/usr.bin/indent/args.c:1.26	Sat Sep 25 17:20:02 2021
+++ src/usr.bin/indent/args.c	Sat Sep 25 18:49:03 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: args.c,v 1.26 2021/09/25 17:20:02 rillig Exp $	*/
+/*	$NetBSD: args.c,v 1.27 2021/09/25 18:49:03 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.26 2021/09/25 17:20:02 rillig Exp $");
+__RCSID("$NetBSD: args.c,v 1.27 2021/09/25 18:49:03 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/args.c 336318 2018-07-15 21:04:21Z pstef $");
 #endif
@@ -123,7 +123,7 @@ const struct pro {
 bool_option("bc", OFF, opt.leave_comma),
 bool_option("bl", OFF, opt.btype_2),
 bool_option("br", ON, opt.btype_2),
-bool_option("bs", ON, opt.Bill_Shannon),
+bool_option("bs", ON, opt.blank_after_sizeof),
 bool_option("cdb", ON, opt.comment_delimiter_on_blankline),
 int_option("cd", 0, opt.decl_comment_column),
 bool_option("ce", ON, opt.cuddle_else),
@@ -152,7 +152,7 @@ const struct pro {
 bool_option("nbap", OFF, opt.blanklines_after_procs),
 bool_option("nbbb", OFF, opt.blanklines_before_blockcomments),
 bool_option("nbc", ON, opt.leave_comma),
-bool_option("nbs", OFF, opt.Bill_Shannon),
+bool_option("nbs", OFF, opt.blank_after_sizeof),
 bool_option("ncdb", OFF, opt.comment_delimiter_on_blankline),
 bool_option("nce", OFF, opt.cuddle_else),
 bool_option("ncs", OFF, opt.space_after_cast),

Index: src/usr.bin/indent/indent.c
diff -u src/usr.bin/indent/indent.c:1.75 src/usr.bin/indent/indent.c:1.76
--- src/usr.bin/indent/indent.c:1.75	Sat Sep 25 17:36:51 2021
+++ src/usr.bin/indent/indent.c	Sat Sep 25 18:49:03 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.75 2021/09/25 17:36:51 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.76 2021/09/25 18:49:03 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.75 2021/09/25 17:36:51 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.76 2021/09/25 18:49:03 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -594,7 +594,7 @@ process_lparen_or_lbracket(int dec_ind, 
 } else if (ps.want_blank &&
 	((ps.last_token != ident && ps.last_token != funcname) ||
 	opt.proc_calls_space ||
-	(ps.keyword == rw_sizeof ? opt.Bill_Shannon :
+	(ps.keyword == rw_sizeof ? opt.blank_after_sizeof :
 	ps.keyword != rw_0 && ps.keyword != rw_offsetof)))
 	*code.e++ = ' ';
 ps.want_blank = false;

Index: src/usr.bin/indent/indent_globs.h
diff -u src/usr.bin/indent/indent_globs.h:1.32 src/usr.bin/indent/indent_globs.h:1.33
--- src/usr.bin/indent/indent_globs.h:1.32	Sat Sep 25 17:36:51 2021
+++ src/usr.bin/indent/indent_globs.h	Sat Sep 25 18:49:03 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent_globs.h,v 1.32 2021/09/25 17:36:51 rillig Exp $	*/
+/*	$NetBSD: indent_globs.h,v 1.33 2021/09/25 18:49:03 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -93,7 +93,7 @@ extern struct options {
  * commas */
 bool	btype_2;	/* whether brace should be on same line
  * as if, while, etc */
-bool	Bill_Shannon;	/* whether a blank should always be
+bool	blank_after_sizeof; /* whether a blank should always be
  * inserted after sizeof */
 bool	comment_delimiter_on_blankline;
 int decl_comment_column; /* the column in which comments after



CVS commit: src/usr.bin/indent

2021-09-25 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Sep 25 17:36:51 UTC 2021

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

Log Message:
indent: convert remaining ibool to bool

No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.74 -r1.75 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.21 -r1.22 src/usr.bin/indent/indent.h
cvs rdiff -u -r1.31 -r1.32 src/usr.bin/indent/indent_globs.h
cvs rdiff -u -r1.61 -r1.62 src/usr.bin/indent/io.c
cvs rdiff -u -r1.54 -r1.55 src/usr.bin/indent/lexi.c
cvs rdiff -u -r1.24 -r1.25 src/usr.bin/indent/parse.c
cvs rdiff -u -r1.43 -r1.44 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.74 src/usr.bin/indent/indent.c:1.75
--- src/usr.bin/indent/indent.c:1.74	Sat Sep 25 17:29:13 2021
+++ src/usr.bin/indent/indent.c	Sat Sep 25 17:36:51 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.74 2021/09/25 17:29:13 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.75 2021/09/25 17:36:51 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.74 2021/09/25 17:29:13 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.75 2021/09/25 17:36:51 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -107,13 +107,13 @@ char   *be_save;
 
 int found_err;
 int n_real_blanklines;
-ibool   prefix_blankline_requested;
-ibool   postfix_blankline_requested;
-ibool   break_comma;
+boolprefix_blankline_requested;
+boolpostfix_blankline_requested;
+boolbreak_comma;
 float   case_ind;
-ibool   had_eof;
+boolhad_eof;
 int line_no;
-ibool   inhibit_formatting;
+boolinhibit_formatting;
 int suppress_blanklines;
 
 int ifdef_level;
@@ -124,7 +124,7 @@ FILE   *input;
 FILE   *output;
 
 static void bakcopy(void);
-static void indent_declaration(int, ibool);
+static void indent_declaration(int, bool);
 
 const char *in_name = "Standard Input";	/* will always point to name of input
 	 * file */
@@ -181,8 +181,8 @@ init_capsicum(void)
 #endif
 
 static void
-search_brace(token_type *inout_ttype, ibool *inout_force_nl,
-	 ibool *inout_comment_buffered, ibool *inout_last_else)
+search_brace(token_type *inout_ttype, bool *inout_force_nl,
+	 bool *inout_comment_buffered, bool *inout_last_else)
 {
 while (ps.search_brace) {
 	switch (*inout_ttype) {
@@ -263,7 +263,7 @@ search_brace(token_type *inout_ttype, ib
 	/* FALLTHROUGH */
 	default:		/* it is the start of a normal statement */
 	{
-	ibool remove_newlines;
+	bool remove_newlines;
 
 	remove_newlines =
 		/* "} else" */
@@ -524,7 +524,7 @@ process_end_of_file(void)
 }
 
 static void
-process_comment_in_code(token_type ttype, ibool *inout_force_nl)
+process_comment_in_code(token_type ttype, bool *inout_force_nl)
 {
 if (*inout_force_nl &&
 	ttype != semicolon &&
@@ -576,7 +576,7 @@ process_newline(void)
 }
 
 static void
-process_lparen_or_lbracket(int dec_ind, ibool tabs_to_var, ibool sp_sw)
+process_lparen_or_lbracket(int dec_ind, bool tabs_to_var, bool sp_sw)
 {
 /* count parens to make Healy happy */
 if (++ps.p_l_follow == nitems(ps.paren_indents)) {
@@ -626,8 +626,8 @@ process_lparen_or_lbracket(int dec_ind, 
 }
 
 static void
-process_rparen_or_rbracket(ibool *inout_sp_sw, ibool *inout_force_nl,
-			 token_type hd_type)
+process_rparen_or_rbracket(bool *inout_sp_sw, bool *inout_force_nl,
+			   token_type hd_type)
 {
 if ((ps.cast_mask & (1 << ps.p_l_follow) & ~ps.not_cast_mask) != 0) {
 	ps.last_u_d = true;
@@ -663,7 +663,7 @@ process_rparen_or_rbracket(ibool *inout_
 }
 
 static void
-process_unary_op(int dec_ind, ibool tabs_to_var)
+process_unary_op(int dec_ind, bool tabs_to_var)
 {
 if (!ps.dumped_decl_indent && ps.in_decl && !ps.block_init &&
 	ps.procname[0] == '\0' && ps.paren_level == 0) {
@@ -726,7 +726,7 @@ process_question(int *inout_squest)
 }
 
 static void
-process_colon(int *inout_squest, ibool *inout_force_nl, ibool *inout_scase)
+process_colon(int *inout_squest, bool *inout_force_nl, bool *inout_scase)
 {
 if (*inout_squest > 0) {	/* it is part of the ?:  construct */
 	--*inout_squest;
@@ -766,10 +766,10 @@ process_colon(int *inout_squest, ibool *
 }
 
 static void
-process_semicolon(ibool *inout_scase, int *inout_squest, int dec_ind,
-		  ibool tabs_to_var, ibool *inout_sp_sw,
+process_semicolon(bool *inout_scase, int *inout_squest, int dec_ind,
+		  bool tabs_to_var, bool *inout_sp_sw,
 		  token_type hd_type,
-		  ibool *inout_force_nl)
+		  bool 

CVS commit: src/usr.bin/indent

2021-09-25 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Sep 25 17:36:51 UTC 2021

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

Log Message:
indent: convert remaining ibool to bool

No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.74 -r1.75 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.21 -r1.22 src/usr.bin/indent/indent.h
cvs rdiff -u -r1.31 -r1.32 src/usr.bin/indent/indent_globs.h
cvs rdiff -u -r1.61 -r1.62 src/usr.bin/indent/io.c
cvs rdiff -u -r1.54 -r1.55 src/usr.bin/indent/lexi.c
cvs rdiff -u -r1.24 -r1.25 src/usr.bin/indent/parse.c
cvs rdiff -u -r1.43 -r1.44 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-09-25 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Sep 25 17:29:13 UTC 2021

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

Log Message:
indent: convert parser_state from ibool to bool

indent.c:400:5: error: suggest parentheses around assignment used as
truth value
io.c:271:32: error: ‘~’ on a boolean expression

No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.73 -r1.74 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.30 -r1.31 src/usr.bin/indent/indent_globs.h
cvs rdiff -u -r1.60 -r1.61 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.73 src/usr.bin/indent/indent.c:1.74
--- src/usr.bin/indent/indent.c:1.73	Sat Sep 25 17:11:23 2021
+++ src/usr.bin/indent/indent.c	Sat Sep 25 17:29:13 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.73 2021/09/25 17:11:23 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.74 2021/09/25 17:29: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.73 2021/09/25 17:11:23 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.74 2021/09/25 17:29:13 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -397,7 +397,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.bl_line = true;
 ps.want_blank = ps.in_stmt = ps.ind_stmt = false;

Index: src/usr.bin/indent/indent_globs.h
diff -u src/usr.bin/indent/indent_globs.h:1.30 src/usr.bin/indent/indent_globs.h:1.31
--- src/usr.bin/indent/indent_globs.h:1.30	Sat Sep 25 17:20:02 2021
+++ src/usr.bin/indent/indent_globs.h	Sat Sep 25 17:29:13 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent_globs.h,v 1.30 2021/09/25 17:20:02 rillig Exp $	*/
+/*	$NetBSD: indent_globs.h,v 1.31 2021/09/25 17:29:13 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -194,7 +194,7 @@ extern struct parser_state {
 token_type	p_stack[STACKSIZE];	/* this is the parsers stack */
 int il[STACKSIZE];	/* this stack stores indentation levels */
 float   cstk[STACKSIZE];/* used to store case stmt indentation levels */
-ibool	box_com;	/* whether we are in a "boxed" comment. In
+bool	box_com;	/* whether we are in a "boxed" comment. In
  * that case, the first non-blank char should
  * be lined up with the '/' in '/' + '*' */
 int comment_delta;	/* used to set up indentation for all lines
@@ -207,35 +207,35 @@ extern struct parser_state {
  * close off casts */
 int not_cast_mask;	/* indicates which close parens definitely
  * close off something else than casts */
-ibool	block_init;	/* whether inside a block initialization */
+bool	block_init;	/* whether inside a block initialization */
 int block_init_level;	/* The level of brace nesting in an
 	 * initialization */
-ibool	last_nl;	/* this is true if the last thing scanned was
+bool	last_nl;	/* this is true if the last thing scanned was
  * a newline */
-ibool	in_or_st;	/* Will be true iff there has been a
+bool	in_or_st;	/* Will be true iff there has been a
  * declarator (e.g. int or char) and no left
  * paren since the last semicolon. When true,
  * a '{' is starting a structure definition or
  * an initialization list */
-ibool	bl_line;	/* set to 1 by dump_line if the line is blank */
-ibool	col_1;		/* set to true if the last token started in
+bool	bl_line;	/* set to 1 by dump_line if the line is blank */
+bool	col_1;		/* set to true if the last token started in
  * column 1 */
 int com_col;	/* this is the column in which the current
  * comment should start */
 int dec_nest;	/* current nesting level for structure or init */
-ibool	decl_on_line;	/* set to true if this line of code has part
+bool	decl_on_line;	/* set to true if this line of code has part
  * of a declaration on it */
 int i_l_follow;	/* the level to which ind_level should be set
  * after the current line is printed */
-ibool	in_decl;	/* set to true when we are in a declaration
+bool	in_decl;	/* set to true when we are in a declaration
  * stmt.  The processing of braces is then
  * slightly different */
-ibool	in_stmt;	/* set to 1 while in a stmt */
+bool	in_stmt;	/* set to 1 while in a stmt */
 int ind_level;	/* the current indentation level */
-ibool	ind_stmt;	/* set to 1 if next line should have 

CVS commit: src/usr.bin/indent

2021-09-25 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Sep 25 17:29:13 UTC 2021

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

Log Message:
indent: convert parser_state from ibool to bool

indent.c:400:5: error: suggest parentheses around assignment used as
truth value
io.c:271:32: error: ‘~’ on a boolean expression

No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.73 -r1.74 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.30 -r1.31 src/usr.bin/indent/indent_globs.h
cvs rdiff -u -r1.60 -r1.61 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-09-25 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Sep 25 17:20:02 UTC 2021

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

Log Message:
indent: convert options from ibool to bool

No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/usr.bin/indent/args.c
cvs rdiff -u -r1.29 -r1.30 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/args.c
diff -u src/usr.bin/indent/args.c:1.25 src/usr.bin/indent/args.c:1.26
--- src/usr.bin/indent/args.c:1.25	Sat Sep 25 17:11:23 2021
+++ src/usr.bin/indent/args.c	Sat Sep 25 17:20:02 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: args.c,v 1.25 2021/09/25 17:11:23 rillig Exp $	*/
+/*	$NetBSD: args.c,v 1.26 2021/09/25 17:20:02 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.25 2021/09/25 17:11:23 rillig Exp $");
+__RCSID("$NetBSD: args.c,v 1.26 2021/09/25 17:20:02 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/args.c 336318 2018-07-15 21:04:21Z pstef $");
 #endif
@@ -94,7 +94,7 @@ void add_typedefs_from_file(const char *
 #define assert_type(expr, type) (expr)
 #endif
 #define bool_option(name, value, var) \
-	{name, PRO_BOOL, value, assert_type(&(var), ibool *)}
+	{name, PRO_BOOL, value, assert_type(&(var), bool *)}
 #define int_option(name, value, var) \
 	{name, PRO_INT, value, assert_type(&(var), int *)}
 #define special_option(name, value) \
@@ -312,9 +312,9 @@ found:
 
 case PRO_BOOL:
 	if (p->p_special == OFF)
-	*(ibool *)p->p_obj = false;
+	*(bool *)p->p_obj = false;
 	else
-	*(ibool *)p->p_obj = true;
+	*(bool *)p->p_obj = true;
 	break;
 
 case PRO_INT:

Index: src/usr.bin/indent/indent_globs.h
diff -u src/usr.bin/indent/indent_globs.h:1.29 src/usr.bin/indent/indent_globs.h:1.30
--- src/usr.bin/indent/indent_globs.h:1.29	Sat Sep 25 17:11:23 2021
+++ src/usr.bin/indent/indent_globs.h	Sat Sep 25 17:20:02 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent_globs.h,v 1.29 2021/09/25 17:11:23 rillig Exp $	*/
+/*	$NetBSD: indent_globs.h,v 1.30 2021/09/25 17:20:02 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -78,27 +78,27 @@ extern char   *be_save;		/* similarl
 
 
 extern struct options {
-ibool	blanklines_around_conditional_compilation;
-ibool	blanklines_after_declarations_at_proctop; /* this is vaguely
+bool	blanklines_around_conditional_compilation;
+bool	blanklines_after_declarations_at_proctop; /* this is vaguely
  * similar to blanklines_after_declarations
  * except that it only applies to the first
  * set of declarations in a procedure (just
  * after the first '{') and it causes a blank
  * line to be generated even if there are no
  * declarations */
-ibool	blanklines_after_declarations;
-ibool	blanklines_after_procs;
-ibool	blanklines_before_blockcomments;
-ibool	leave_comma;	/* if true, never break declarations after
+bool	blanklines_after_declarations;
+bool	blanklines_after_procs;
+bool	blanklines_before_blockcomments;
+bool	leave_comma;	/* if true, never break declarations after
  * commas */
-ibool	btype_2;	/* whether brace should be on same line
+bool	btype_2;	/* whether brace should be on same line
  * as if, while, etc */
-ibool	Bill_Shannon;	/* whether a blank should always be
+bool	Bill_Shannon;	/* whether a blank should always be
  * inserted after sizeof */
-ibool	comment_delimiter_on_blankline;
+bool	comment_delimiter_on_blankline;
 int decl_comment_column; /* the column in which comments after
  * declarations should be put */
-ibool	cuddle_else;	/* whether 'else' should cuddle up to '}' */
+bool	cuddle_else;	/* whether 'else' should cuddle up to '}' */
 int continuation_indent; /* set to the indentation between the
  * edge of code and continuation lines */
 float   case_indent;	/* The distance (measured in tabsize) to
@@ -107,52 +107,52 @@ extern struct options {
 int comment_column;	/* the column in which comments to the right
  * of code should start */
 int decl_indent;	/* indentation of identifier in declaration */
-ibool	ljust_decl;	/* true if declarations should be left
+bool	ljust_decl;	/* true if declarations should be left
  * justified */
 int unindent_displace; /* comments not to the right of code
  * will be placed this many
  * indentation levels to the left of
  * code */
-ibool	extra_expression_indent; /* whether continuation lines from
+bool	extra_expression_indent; /* whether continuation lines from
  * the expression part of "if(e)",
  * "while(e)", "for(e;e;e)" should be
  

CVS commit: src/usr.bin/indent

2021-09-25 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Sep 25 17:20:02 UTC 2021

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

Log Message:
indent: convert options from ibool to bool

No functional change intended.


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/usr.bin/indent/args.c
cvs rdiff -u -r1.29 -r1.30 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-09-25 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Sep 25 17:11:24 UTC 2021

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

Log Message:
indent: prepare for lint's strict bool mode

Before C99, C had no boolean type. Instead, indent used int for that,
just like many other programs. Even with C99, bool and int can be used
interchangeably in many situations, such as querying '!i' or '!ptr' or
'cond == 0'.

Since January 2021, lint provides the strict bool mode, which makes bool
a non-arithmetic type that is incompatible with any other type. Having
clearly separate types helps in understanding the code.

To migrate indent to strict bool mode, the first step is to apply all
changes that keep the resulting binary the same. Since sizeof(bool) is
1 and sizeof(int) is 4, the type ibool serves as an intermediate type.
For now it is defined to int, later it will become bool.

The current code compiles cleanly in C99 and C11 mode, as well as in
lint's strict bool mode. There are a few tricky places:

In args.c in 'struct pro', there are two types of options: boolean and
integer. Boolean options point to a bool variable, integer options
point to an int variable. To keep the current structure of the code,
the pointer has been changed to 'void *'. To ensure type safety, the
definition of the options is done via preprocessor magic, which in C11
mode ensures the correct pointer types. (Add CFLAGS+=-std=gnu11 at the
very bottom of the Makefile.)

In indent.c in process_preprocessing, a boolean variable is
post-incremented. That variable is only assigned to another variable,
and that variable is only used in a boolean context. To provoke a
different behavior between the '++' and the '= true', the source code
to be indented would need 1 << 32 preprocessing directives, which is
unlikely to happen in practice.

In io.c in dump_line, the variables ps.in_stmt and ps.in_decl only ever
get the values 0 and 1. For these values, the expressions 'a & ~b' and
'a && !b' are equivalent, in all versions of C. The compiler may
generate different code for them, though.

In io.c in parse_indent_comment, the assignment to inhibit_formatting
takes place in integer context. If the compiler is smart enough to
detect the possible values of on_off, it may generate the same code
before and after the change, but that is rather unlikely.

The second step of the migration will be to replace ibool with bool,
step by step, just in case there are any hidden gotchas in the code,
such as sizeof or pointer casts.

No change to the resulting binary.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/usr.bin/indent/Makefile
cvs rdiff -u -r1.24 -r1.25 src/usr.bin/indent/args.c
cvs rdiff -u -r1.72 -r1.73 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.20 -r1.21 src/usr.bin/indent/indent.h
cvs rdiff -u -r1.28 -r1.29 src/usr.bin/indent/indent_globs.h
cvs rdiff -u -r1.59 -r1.60 src/usr.bin/indent/io.c
cvs rdiff -u -r1.53 -r1.54 src/usr.bin/indent/lexi.c
cvs rdiff -u -r1.23 -r1.24 src/usr.bin/indent/parse.c
cvs rdiff -u -r1.42 -r1.43 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/Makefile
diff -u src/usr.bin/indent/Makefile:1.12 src/usr.bin/indent/Makefile:1.13
--- src/usr.bin/indent/Makefile:1.12	Fri Mar 26 22:27:43 2021
+++ src/usr.bin/indent/Makefile	Sat Sep 25 17:11:23 2021
@@ -1,10 +1,10 @@
-#	$NetBSD: Makefile,v 1.12 2021/03/26 22:27:43 rillig Exp $
+#	$NetBSD: Makefile,v 1.13 2021/09/25 17:11:23 rillig Exp $
 #	from: @(#)Makefile	8.1 (Berkeley) 6/6/93
 
 PROG=	indent
 SRCS=	indent.c io.c lexi.c parse.c pr_comment.c args.c
 
 CPPFLAGS+=	${DEBUG:D-Ddebug}
-LINTFLAGS+=	-e -w
+LINTFLAGS+=	-e -w -T
 
 .include 

Index: src/usr.bin/indent/args.c
diff -u src/usr.bin/indent/args.c:1.24 src/usr.bin/indent/args.c:1.25
--- src/usr.bin/indent/args.c:1.24	Sat Sep 25 14:16:06 2021
+++ src/usr.bin/indent/args.c	Sat Sep 25 17:11:23 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: args.c,v 1.24 2021/09/25 14:16:06 rillig Exp $	*/
+/*	$NetBSD: args.c,v 1.25 2021/09/25 17:11:23 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.24 2021/09/25 14:16:06 rillig Exp $");
+__RCSID("$NetBSD: args.c,v 1.25 2021/09/25 17:11:23 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/args.c 336318 2018-07-15 21:04:21Z pstef $");
 #endif
@@ -88,88 +88,99 @@ const char *option_source = "?";
 
 void add_typedefs_from_file(const char *str);
 
+#if __STDC_VERSION__ >= 201112L
+#define assert_type(expr, type) _Generic((expr), type : (expr))
+#else
+#define assert_type(expr, type) (expr)
+#endif
+#define bool_option(name, value, var) \
+	{name, PRO_BOOL, value, assert_type(&(var), ibool 

CVS commit: src/usr.bin/indent

2021-09-25 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Sep 25 17:11:24 UTC 2021

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

Log Message:
indent: prepare for lint's strict bool mode

Before C99, C had no boolean type. Instead, indent used int for that,
just like many other programs. Even with C99, bool and int can be used
interchangeably in many situations, such as querying '!i' or '!ptr' or
'cond == 0'.

Since January 2021, lint provides the strict bool mode, which makes bool
a non-arithmetic type that is incompatible with any other type. Having
clearly separate types helps in understanding the code.

To migrate indent to strict bool mode, the first step is to apply all
changes that keep the resulting binary the same. Since sizeof(bool) is
1 and sizeof(int) is 4, the type ibool serves as an intermediate type.
For now it is defined to int, later it will become bool.

The current code compiles cleanly in C99 and C11 mode, as well as in
lint's strict bool mode. There are a few tricky places:

In args.c in 'struct pro', there are two types of options: boolean and
integer. Boolean options point to a bool variable, integer options
point to an int variable. To keep the current structure of the code,
the pointer has been changed to 'void *'. To ensure type safety, the
definition of the options is done via preprocessor magic, which in C11
mode ensures the correct pointer types. (Add CFLAGS+=-std=gnu11 at the
very bottom of the Makefile.)

In indent.c in process_preprocessing, a boolean variable is
post-incremented. That variable is only assigned to another variable,
and that variable is only used in a boolean context. To provoke a
different behavior between the '++' and the '= true', the source code
to be indented would need 1 << 32 preprocessing directives, which is
unlikely to happen in practice.

In io.c in dump_line, the variables ps.in_stmt and ps.in_decl only ever
get the values 0 and 1. For these values, the expressions 'a & ~b' and
'a && !b' are equivalent, in all versions of C. The compiler may
generate different code for them, though.

In io.c in parse_indent_comment, the assignment to inhibit_formatting
takes place in integer context. If the compiler is smart enough to
detect the possible values of on_off, it may generate the same code
before and after the change, but that is rather unlikely.

The second step of the migration will be to replace ibool with bool,
step by step, just in case there are any hidden gotchas in the code,
such as sizeof or pointer casts.

No change to the resulting binary.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/usr.bin/indent/Makefile
cvs rdiff -u -r1.24 -r1.25 src/usr.bin/indent/args.c
cvs rdiff -u -r1.72 -r1.73 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.20 -r1.21 src/usr.bin/indent/indent.h
cvs rdiff -u -r1.28 -r1.29 src/usr.bin/indent/indent_globs.h
cvs rdiff -u -r1.59 -r1.60 src/usr.bin/indent/io.c
cvs rdiff -u -r1.53 -r1.54 src/usr.bin/indent/lexi.c
cvs rdiff -u -r1.23 -r1.24 src/usr.bin/indent/parse.c
cvs rdiff -u -r1.42 -r1.43 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-09-25 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Sep 25 14:38:31 UTC 2021

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

Log Message:
indent: use standard definition for bool, true, false


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/usr.bin/indent/indent.h
cvs rdiff -u -r1.27 -r1.28 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.h
diff -u src/usr.bin/indent/indent.h:1.19 src/usr.bin/indent/indent.h:1.20
--- src/usr.bin/indent/indent.h:1.19	Sat Sep 25 14:16:06 2021
+++ src/usr.bin/indent/indent.h	Sat Sep 25 14:38:31 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.h,v 1.19 2021/09/25 14:16:06 rillig Exp $	*/
+/*	$NetBSD: indent.h,v 1.20 2021/09/25 14:38:31 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -32,6 +32,8 @@
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.h 336333 2018-07-16 05:46:50Z pstef $");
 #endif
 
+#include 
+
 #include "indent_codes.h"
 #include "indent_globs.h"
 

Index: src/usr.bin/indent/indent_globs.h
diff -u src/usr.bin/indent/indent_globs.h:1.27 src/usr.bin/indent/indent_globs.h:1.28
--- src/usr.bin/indent/indent_globs.h:1.27	Sat Sep 25 10:41:03 2021
+++ src/usr.bin/indent/indent_globs.h	Sat Sep 25 14:38:31 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent_globs.h,v 1.27 2021/09/25 10:41:03 rillig Exp $	*/
+/*	$NetBSD: indent_globs.h,v 1.28 2021/09/25 14:38:31 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -46,9 +46,6 @@
  * of code */
 
 
-#define false 0
-#define true  1
-
 struct buffer {
 char *buf;			/* buffer */
 char *s;			/* start */



CVS commit: src/usr.bin/indent

2021-09-25 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Sep 25 14:38:31 UTC 2021

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

Log Message:
indent: use standard definition for bool, true, false


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/usr.bin/indent/indent.h
cvs rdiff -u -r1.27 -r1.28 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-09-25 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Sep 25 14:26:05 UTC 2021

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

Log Message:
indent: merge duplicate code for initializing buffers

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.71 -r1.72 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.71 src/usr.bin/indent/indent.c:1.72
--- src/usr.bin/indent/indent.c:1.71	Sat Sep 25 14:16:06 2021
+++ src/usr.bin/indent/indent.c	Sat Sep 25 14:26:05 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.71 2021/09/25 14:16:06 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.72 2021/09/25 14:26:05 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.71 2021/09/25 14:16:06 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.72 2021/09/25 14:26:05 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -366,6 +366,17 @@ search_brace(token_type *inout_ttype, in
 }
 
 static void
+buf_init(struct buffer *buf)
+{
+buf->buf = xmalloc(bufsize);
+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 */
+}
+
+static void
 main_init_globals(void)
 {
 found_err = 0;
@@ -374,24 +385,13 @@ main_init_globals(void)
 ps.last_nl = true;		/* this is true if the last thing scanned was
  * a newline */
 ps.last_token = semicolon;
-com.buf = xmalloc(bufsize);
-lab.buf = xmalloc(bufsize);
-code.buf = xmalloc(bufsize);
-token.buf = xmalloc(bufsize);
+buf_init();
+buf_init();
+buf_init();
+buf_init();
 alloc_typenames();
 init_constant_tt();
-com.l = com.buf + bufsize - 5;
-lab.l = lab.buf + bufsize - 5;
-code.l = code.buf + bufsize - 5;
-token.l = token.buf + bufsize - 5;
-com.buf[0] = code.buf[0] = lab.buf[0] = ' ';	/* set up code, label, and
-		 * comment buffers */
-com.buf[1] = code.buf[1] = lab.buf[1] = token.buf[1] = '\0';
 opt.else_if = 1;		/* Default else-if special processing to on */
-lab.s = lab.e = lab.buf + 1;
-code.s = code.e = code.buf + 1;
-com.s = com.e = com.buf + 1;
-token.s = token.e = token.buf + 1;
 
 in_buffer = xmalloc(10);
 in_buffer_limit = in_buffer + 8;



CVS commit: src/usr.bin/indent

2021-09-25 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Sep 25 14:26:05 UTC 2021

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

Log Message:
indent: merge duplicate code for initializing buffers

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.71 -r1.72 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-09-25 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Sep 25 14:16:06 UTC 2021

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

Log Message:
indent: clean up initialization of options

The default values in 'struct pro' were redundant but all consistent,
even with the commented defaults in main_parse_command_line.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/usr.bin/indent/args.c
cvs rdiff -u -r1.70 -r1.71 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.18 -r1.19 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-09-25 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Sep 25 14:16:06 UTC 2021

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

Log Message:
indent: clean up initialization of options

The default values in 'struct pro' were redundant but all consistent,
even with the commented defaults in main_parse_command_line.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/usr.bin/indent/args.c
cvs rdiff -u -r1.70 -r1.71 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.18 -r1.19 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.23 src/usr.bin/indent/args.c:1.24
--- src/usr.bin/indent/args.c:1.23	Sat Sep 25 13:38:32 2021
+++ src/usr.bin/indent/args.c	Sat Sep 25 14:16:06 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: args.c,v 1.23 2021/09/25 13:38:32 rillig Exp $	*/
+/*	$NetBSD: args.c,v 1.24 2021/09/25 14:16:06 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.23 2021/09/25 13:38:32 rillig Exp $");
+__RCSID("$NetBSD: args.c,v 1.24 2021/09/25 14:16:06 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/args.c 336318 2018-07-15 21:04:21Z pstef $");
 #endif
@@ -97,82 +97,81 @@ void add_typedefs_from_file(const char *
 const struct pro {
 const char *p_name;		/* name, e.g. -bl, -cli */
 int p_type;		/* type (int, bool, special) */
-int p_default;	/* the default value (if int) */
 int p_special;	/* depends on type */
 int*p_obj;		/* the associated variable */
 }   pro[] = {
-{"T", PRO_SPECIAL, 0, KEY, 0},
-{"U", PRO_SPECIAL, 0, KEY_FILE, 0},
-{"-version", PRO_SPECIAL, 0, VERSION, 0},
-{"P", PRO_SPECIAL, 0, IGN, 0},
-{"bacc", PRO_BOOL, false, ON, _around_conditional_compilation},
-{"badp", PRO_BOOL, false, ON, _after_declarations_at_proctop},
-{"bad", PRO_BOOL, false, ON, _after_declarations},
-{"bap", PRO_BOOL, false, ON, _after_procs},
-{"bbb", PRO_BOOL, false, ON, _before_blockcomments},
-{"bc", PRO_BOOL, true, OFF, _comma},
-{"bl", PRO_BOOL, true, OFF, _2},
-{"br", PRO_BOOL, true, ON, _2},
-{"bs", PRO_BOOL, false, ON, _Shannon},
-{"cdb", PRO_BOOL, true, ON, _delimiter_on_blankline},
-{"cd", PRO_INT, 0, 0, _comment_column},
-{"ce", PRO_BOOL, true, ON, _else},
-{"ci", PRO_INT, 0, 0, _indent},
-{"cli", PRO_SPECIAL, 0, CLI, 0},
-{"cs", PRO_BOOL, false, ON, _after_cast},
-{"c", PRO_INT, 33, 0, _column},
-{"di", PRO_INT, 16, 0, _indent},
-{"dj", PRO_BOOL, false, ON, _decl},
-{"d", PRO_INT, 0, 0, _displace},
-{"eei", PRO_BOOL, false, ON, _expression_indent},
-{"ei", PRO_BOOL, true, ON, _if},
-{"fbs", PRO_BOOL, true, ON, _brace_split},
-{"fc1", PRO_BOOL, true, ON, _col1_comments},
-{"fcb", PRO_BOOL, true, ON, _block_comments},
-{"ip", PRO_BOOL, true, ON, _parameters},
-{"i", PRO_INT, 8, 0, _size},
-{"lc", PRO_INT, 0, 0, _comment_max_line_length},
-{"ldi", PRO_INT, -1, 0, _decl_indent},
-{"lpl", PRO_BOOL, false, ON, _to_parens_always},
-{"lp", PRO_BOOL, true, ON, _to_parens},
-{"l", PRO_INT, 78, 0, _line_length},
-{"nbacc", PRO_BOOL, false, OFF, _around_conditional_compilation},
-{"nbadp", PRO_BOOL, false, OFF, _after_declarations_at_proctop},
-{"nbad", PRO_BOOL, false, OFF, _after_declarations},
-{"nbap", PRO_BOOL, false, OFF, _after_procs},
-{"nbbb", PRO_BOOL, false, OFF, _before_blockcomments},
-{"nbc", PRO_BOOL, true, ON, _comma},
-{"nbs", PRO_BOOL, false, OFF, _Shannon},
-{"ncdb", PRO_BOOL, true, OFF, _delimiter_on_blankline},
-{"nce", PRO_BOOL, true, OFF, _else},
-{"ncs", PRO_BOOL, false, OFF, _after_cast},
-{"ndj", PRO_BOOL, false, OFF, _decl},
-{"neei", PRO_BOOL, false, OFF, _expression_indent},
-{"nei", PRO_BOOL, true, OFF, _if},
-{"nfbs", PRO_BOOL, true, OFF, _brace_split},
-{"nfc1", PRO_BOOL, true, OFF, _col1_comments},
-{"nfcb", PRO_BOOL, true, OFF, _block_comments},
-{"nip", PRO_BOOL, true, OFF, _parameters},
-{"nlpl", PRO_BOOL, false, OFF, _to_parens_always},
-{"nlp", PRO_BOOL, true, OFF, _to_parens},
-{"npcs", PRO_BOOL, false, OFF, _calls_space},
-{"npro", PRO_SPECIAL, 0, IGN, 0},
-{"npsl", PRO_BOOL, true, OFF, _start_line},
-{"nsc", PRO_BOOL, true, OFF, _comment_cont},
-{"nsob", PRO_BOOL, false, OFF, _optional_blanklines},
-{"nut", PRO_BOOL, true, OFF, _tabs},
-{"nv", PRO_BOOL, false, OFF, },
-{"pcs", PRO_BOOL, false, ON, _calls_space},
-{"psl", PRO_BOOL, true, ON, _start_line},
-{"sc", PRO_BOOL, true, ON, _comment_cont},
-{"sob", PRO_BOOL, false, ON, _optional_blanklines},
-{"st", PRO_SPECIAL, 

CVS commit: src/usr.bin/indent

2021-09-25 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Sep 25 13:38:33 UTC 2021

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

Log Message:
indent: remove ifdef for lint

NetBSD lint does not need them anymore, FreeBSD does not have lint.


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/usr.bin/indent/args.c \
src/usr.bin/indent/parse.c
cvs rdiff -u -r1.69 -r1.70 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.17 -r1.18 src/usr.bin/indent/indent.h
cvs rdiff -u -r1.58 -r1.59 src/usr.bin/indent/io.c
cvs rdiff -u -r1.52 -r1.53 src/usr.bin/indent/lexi.c
cvs rdiff -u -r1.41 -r1.42 src/usr.bin/indent/pr_comment.c

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

Modified files:

Index: src/usr.bin/indent/args.c
diff -u src/usr.bin/indent/args.c:1.22 src/usr.bin/indent/args.c:1.23
--- src/usr.bin/indent/args.c:1.22	Sun Mar 14 00:22:16 2021
+++ src/usr.bin/indent/args.c	Sat Sep 25 13:38:32 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: args.c,v 1.22 2021/03/14 00:22:16 rillig Exp $	*/
+/*	$NetBSD: args.c,v 1.23 2021/09/25 13:38:32 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -38,19 +38,15 @@
  */
 
 #if 0
-#ifndef lint
 static char sccsid[] = "@(#)args.c	8.1 (Berkeley) 6/6/93";
-#endif /* not lint */
 #endif
 
 #include 
-#ifndef lint
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: args.c,v 1.22 2021/03/14 00:22:16 rillig Exp $");
+__RCSID("$NetBSD: args.c,v 1.23 2021/09/25 13:38:32 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/args.c 336318 2018-07-15 21:04:21Z pstef $");
 #endif
-#endif
 
 /*
  * Argument scanning and profile reading code.  Default parameters are set
Index: src/usr.bin/indent/parse.c
diff -u src/usr.bin/indent/parse.c:1.22 src/usr.bin/indent/parse.c:1.23
--- src/usr.bin/indent/parse.c:1.22	Sat Sep 25 08:04:13 2021
+++ src/usr.bin/indent/parse.c	Sat Sep 25 13:38:32 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: parse.c,v 1.22 2021/09/25 08:04:13 rillig Exp $	*/
+/*	$NetBSD: parse.c,v 1.23 2021/09/25 13:38:32 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -38,19 +38,15 @@
  */
 
 #if 0
-#ifndef lint
 static char sccsid[] = "@(#)parse.c	8.1 (Berkeley) 6/6/93";
-#endif /* not lint */
 #endif
 
 #include 
-#ifndef lint
 #if defined(__NetBSD__)
 __RCSID("$FreeBSD$");
 #else
 __FBSDID("$FreeBSD: head/usr.bin/indent/parse.c 337651 2018-08-11 19:20:06Z pstef $");
 #endif
-#endif
 
 #include 
 #include 

Index: src/usr.bin/indent/indent.c
diff -u src/usr.bin/indent/indent.c:1.69 src/usr.bin/indent/indent.c:1.70
--- src/usr.bin/indent/indent.c:1.69	Sat Sep 25 10:41:03 2021
+++ src/usr.bin/indent/indent.c	Sat Sep 25 13:38:32 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.69 2021/09/25 10:41:03 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.70 2021/09/25 13:38:32 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -38,19 +38,15 @@
  */
 
 #if 0
-#ifndef lint
 static char sccsid[] = "@(#)indent.c	5.17 (Berkeley) 6/7/93";
-#endif /* not lint */
 #endif
 
 #include 
-#ifndef lint
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: indent.c,v 1.69 2021/09/25 10:41:03 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.70 2021/09/25 13:38:32 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
-#endif
 
 #include 
 #if HAVE_CAPSICUM

Index: src/usr.bin/indent/indent.h
diff -u src/usr.bin/indent/indent.h:1.17 src/usr.bin/indent/indent.h:1.18
--- src/usr.bin/indent/indent.h:1.17	Sat Sep 25 08:23:31 2021
+++ src/usr.bin/indent/indent.h	Sat Sep 25 13:38:32 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.h,v 1.17 2021/09/25 08:23:31 rillig Exp $	*/
+/*	$NetBSD: indent.h,v 1.18 2021/09/25 13:38:32 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -29,10 +29,8 @@
  */
 
 #if 0
-#if defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.h 336333 2018-07-16 05:46:50Z pstef $");
 #endif
-#endif
 
 #include "indent_codes.h"
 #include "indent_globs.h"

Index: src/usr.bin/indent/io.c
diff -u src/usr.bin/indent/io.c:1.58 src/usr.bin/indent/io.c:1.59
--- src/usr.bin/indent/io.c:1.58	Sat Sep 25 10:41:03 2021
+++ src/usr.bin/indent/io.c	Sat Sep 25 13:38:32 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: io.c,v 1.58 2021/09/25 10:41:03 rillig Exp $	*/
+/*	$NetBSD: io.c,v 1.59 2021/09/25 13:38:32 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -38,19 +38,15 @@
  */
 
 #if 0
-#ifndef lint
 static char sccsid[] = "@(#)io.c	8.1 (Berkeley) 6/6/93";
-#endif /* not lint */
 #endif
 
 #include 
-#ifndef lint
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: io.c,v 1.58 2021/09/25 10:41:03 rillig Exp $");
+__RCSID("$NetBSD: io.c,v 1.59 2021/09/25 13:38:32 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/io.c 334927 2018-06-10 16:44:18Z pstef $");
 #endif
-#endif
 
 #include 

CVS commit: src/usr.bin/indent

2021-09-25 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Sep 25 13:38:33 UTC 2021

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

Log Message:
indent: remove ifdef for lint

NetBSD lint does not need them anymore, FreeBSD does not have lint.


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/usr.bin/indent/args.c \
src/usr.bin/indent/parse.c
cvs rdiff -u -r1.69 -r1.70 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.17 -r1.18 src/usr.bin/indent/indent.h
cvs rdiff -u -r1.58 -r1.59 src/usr.bin/indent/io.c
cvs rdiff -u -r1.52 -r1.53 src/usr.bin/indent/lexi.c
cvs rdiff -u -r1.41 -r1.42 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-09-25 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Sep 25 10:41:03 UTC 2021

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

Log Message:
indent: move statistical values into a separate struct

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.68 -r1.69 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.26 -r1.27 src/usr.bin/indent/indent_globs.h
cvs rdiff -u -r1.57 -r1.58 src/usr.bin/indent/io.c
cvs rdiff -u -r1.40 -r1.41 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.68 src/usr.bin/indent/indent.c:1.69
--- src/usr.bin/indent/indent.c:1.68	Sat Sep 25 08:23:31 2021
+++ src/usr.bin/indent/indent.c	Sat Sep 25 10:41:03 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.68 2021/09/25 08:23:31 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.69 2021/09/25 10:41:03 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -46,7 +46,7 @@ static char sccsid[] = "@(#)indent.c	5.1
 #include 
 #ifndef lint
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: indent.c,v 1.68 2021/09/25 08:23:31 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.69 2021/09/25 10:41:03 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -94,7 +94,6 @@ int prefix_blankline_requested;
 int postfix_blankline_requested;
 int break_comma;
 float   case_ind;
-int code_lines;
 int had_eof;
 int line_no;
 int inhibit_formatting;
@@ -528,9 +527,9 @@ process_end_of_file(void)
 
 if (opt.verbose) {
 	printf("There were %d output lines and %d comments\n",
-	   ps.out_lines, ps.out_coms);
+	   ps.stats.lines, ps.stats.comments);
 	printf("(Lines with comments)/(Lines with code): %6.3f\n",
-	   (1.0 * ps.com_lines) / code_lines);
+	   (1.0 * ps.stats.comment_lines) / ps.stats.code_lines);
 }
 
 fflush(output);

Index: src/usr.bin/indent/indent_globs.h
diff -u src/usr.bin/indent/indent_globs.h:1.26 src/usr.bin/indent/indent_globs.h:1.27
--- src/usr.bin/indent/indent_globs.h:1.26	Sat Sep 25 08:04:13 2021
+++ src/usr.bin/indent/indent_globs.h	Sat Sep 25 10:41:03 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent_globs.h,v 1.26 2021/09/25 08:04:13 rillig Exp $	*/
+/*	$NetBSD: indent_globs.h,v 1.27 2021/09/25 10:41:03 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -184,7 +184,6 @@ extern int break_comma;	/* when 
  * comma */
 extern float   case_ind;		/* indentation level to be used for a "case
  * n:" */
-extern int code_lines;		/* count of lines with code */
 extern int had_eof;		/* set to true when input is exhausted */
 extern int line_no;		/* the current line number. */
 extern int inhibit_formatting;	/* true if INDENT OFF is in effect */
@@ -226,8 +225,6 @@ extern struct parser_state {
  * column 1 */
 int com_col;	/* this is the column in which the current
  * comment should start */
-int com_lines;	/* the number of lines with comments, set by
- * dump_line */
 int dec_nest;	/* current nesting level for structure or init */
 int decl_on_line;	/* set to true if this line of code has part
  * of a declaration on it */
@@ -243,10 +240,6 @@ extern struct parser_state {
  * middle of a stmt */
 int last_u_d;	/* set to true after scanning a token which
  * forces a following operator to be unary */
-int out_coms;	/* the number of comments processed, set by
- * process_comment */
-int out_lines;	/* the number of lines written, set by
- * dump_line */
 int p_l_follow;	/* used to remember how to indent following
  * statement */
 int paren_level;	/* parenthesization level. used to indent
@@ -271,6 +264,13 @@ extern struct parser_state {
 int tos;		/* pointer to top of stack */
 charprocname[100];	/* The name of the current procedure */
 int just_saw_decl;
+
+struct {
+	int	comments;
+	int	lines;
+	int	code_lines;
+	int	comment_lines;
+}		stats;
 }   ps;
 
 extern int ifdef_level;

Index: src/usr.bin/indent/io.c
diff -u src/usr.bin/indent/io.c:1.57 src/usr.bin/indent/io.c:1.58
--- src/usr.bin/indent/io.c:1.57	Sat Sep 25 08:23:31 2021
+++ src/usr.bin/indent/io.c	Sat Sep 25 10:41:03 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: io.c,v 1.57 2021/09/25 08:23:31 rillig Exp $	*/
+/*	$NetBSD: io.c,v 1.58 2021/09/25 10:41:03 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -46,7 +46,7 @@ static char sccsid[] = "@(#)io.c	8.1 (Be
 #include 
 #ifndef lint
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: io.c,v 1.57 2021/09/25 08:23:31 rillig Exp $");
+__RCSID("$NetBSD: io.c,v 1.58 

CVS commit: src/usr.bin/indent

2021-09-25 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Sep 25 10:41:03 UTC 2021

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

Log Message:
indent: move statistical values into a separate struct

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.68 -r1.69 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.26 -r1.27 src/usr.bin/indent/indent_globs.h
cvs rdiff -u -r1.57 -r1.58 src/usr.bin/indent/io.c
cvs rdiff -u -r1.40 -r1.41 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-09-25 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Sep 25 10:24:10 UTC 2021

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

Log Message:
indent: make lex_char_or_string simpler

The previous code was so tricky that every second line needed a comment
that explains what's going on.  Replace the complicated code with the
usual straight-forward string-copying patterns.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.51 -r1.52 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/lexi.c
diff -u src/usr.bin/indent/lexi.c:1.51 src/usr.bin/indent/lexi.c:1.52
--- src/usr.bin/indent/lexi.c:1.51	Sat Sep 25 08:23:31 2021
+++ src/usr.bin/indent/lexi.c	Sat Sep 25 10:24:10 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: lexi.c,v 1.51 2021/09/25 08:23:31 rillig Exp $	*/
+/*	$NetBSD: lexi.c,v 1.52 2021/09/25 10:24:10 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -46,7 +46,7 @@ static char sccsid[] = "@(#)lexi.c	8.1 (
 #include 
 #ifndef lint
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: lexi.c,v 1.51 2021/09/25 08:23:31 rillig Exp $");
+__RCSID("$NetBSD: lexi.c,v 1.52 2021/09/25 10:24:10 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/lexi.c 337862 2018-08-15 18:19:45Z pstef $");
 #endif
@@ -319,27 +319,21 @@ lex_word(void)
 static void
 lex_char_or_string(void)
 {
-char delim;
-
-delim = *token.s;
-do {			/* copy the string */
-	for (;;) {		/* move one character or [/] */
-	if (*buf_ptr == '\n') {
-		diag(1, "Unterminated literal");
-		return;
-	}
-	check_size_token(2);
-	*token.e = inbuf_next();
-	if (*token.e == '\\') {	/* if escape, copy extra char */
-		if (*buf_ptr == '\n')	/* check for escaped newline */
-		++line_no;
-		*++token.e = inbuf_next();
-		++token.e;	/* we must increment this again because we
- * copied two chars */
-	} else
-		break;		/* we copied one character */
-	}			/* end of while (1) */
-} while (*token.e++ != delim);
+for (char delim = *token.s;;) {
+	if (*buf_ptr == '\n') {
+	diag(1, "Unterminated literal");
+	return;
+	}
+	check_size_token(2);
+	*token.e++ = inbuf_next();
+	if (token.e[-1] == delim)
+	return;
+	if (token.e[-1] == '\\') {
+	if (*buf_ptr == '\n')
+		++line_no;
+	*token.e++ = inbuf_next();
+	}
+}
 }
 
 /* Reads the next token, placing it in the global variable "token". */



CVS commit: src/usr.bin/indent

2021-09-25 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Sep 25 10:24:10 UTC 2021

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

Log Message:
indent: make lex_char_or_string simpler

The previous code was so tricky that every second line needed a comment
that explains what's going on.  Replace the complicated code with the
usual straight-forward string-copying patterns.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.51 -r1.52 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-09-25 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Sep 25 08:23:32 UTC 2021

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

Log Message:
indent: add nonnull memory allocation functions

The only functional change is a single error message.


To generate a diff of this commit:
cvs rdiff -u -r1.67 -r1.68 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.16 -r1.17 src/usr.bin/indent/indent.h
cvs rdiff -u -r1.56 -r1.57 src/usr.bin/indent/io.c
cvs rdiff -u -r1.50 -r1.51 src/usr.bin/indent/lexi.c
cvs rdiff -u -r1.39 -r1.40 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.67 src/usr.bin/indent/indent.c:1.68
--- src/usr.bin/indent/indent.c:1.67	Sat Sep 25 08:04:13 2021
+++ src/usr.bin/indent/indent.c	Sat Sep 25 08:23:31 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.67 2021/09/25 08:04:13 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.68 2021/09/25 08:23:31 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -46,7 +46,7 @@ static char sccsid[] = "@(#)indent.c	5.1
 #include 
 #ifndef lint
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: indent.c,v 1.67 2021/09/25 08:04:13 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.68 2021/09/25 08:23:31 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -126,9 +126,7 @@ check_size_code(size_t desired_size)
 
 size_t nsize = code.l - code.s + 400 + desired_size;
 size_t code_len = code.e - code.s;
-code.buf = realloc(code.buf, nsize);
-if (code.buf == NULL)
-	err(1, NULL);
+code.buf = xrealloc(code.buf, nsize);
 code.e = code.buf + code_len + 1;
 code.l = code.buf + nsize - 5;
 code.s = code.buf + 1;
@@ -142,9 +140,7 @@ check_size_label(size_t desired_size)
 
 size_t nsize = lab.l - lab.s + 400 + desired_size;
 size_t label_len = lab.e - lab.s;
-lab.buf = realloc(lab.buf, nsize);
-if (lab.buf == NULL)
-	err(1, NULL);
+lab.buf = xrealloc(lab.buf, nsize);
 lab.e = lab.buf + label_len + 1;
 lab.l = lab.buf + nsize - 5;
 lab.s = lab.buf + 1;
@@ -362,18 +358,10 @@ main_init_globals(void)
 ps.last_nl = true;		/* this is true if the last thing scanned was
  * a newline */
 ps.last_token = semicolon;
-com.buf = malloc(bufsize);
-if (com.buf == NULL)
-	err(1, NULL);
-lab.buf = malloc(bufsize);
-if (lab.buf == NULL)
-	err(1, NULL);
-code.buf = malloc(bufsize);
-if (code.buf == NULL)
-	err(1, NULL);
-token.buf = malloc(bufsize);
-if (token.buf == NULL)
-	err(1, NULL);
+com.buf = xmalloc(bufsize);
+lab.buf = xmalloc(bufsize);
+code.buf = xmalloc(bufsize);
+token.buf = xmalloc(bufsize);
 alloc_typenames();
 init_constant_tt();
 com.l = com.buf + bufsize - 5;
@@ -389,9 +377,7 @@ main_init_globals(void)
 com.s = com.e = com.buf + 1;
 token.s = token.e = token.buf + 1;
 
-in_buffer = malloc(10);
-if (in_buffer == NULL)
-	err(1, NULL);
+in_buffer = xmalloc(10);
 in_buffer_limit = in_buffer + 8;
 buf_ptr = buf_end = in_buffer;
 line_no = 1;
@@ -1571,3 +1557,29 @@ debug_vis_range(const char *prefix, cons
 debug_printf("%s", suffix);
 }
 #endif
+
+static void *
+nonnull(void *p)
+{
+if (p == NULL)
+	err(EXIT_FAILURE, NULL);
+return p;
+}
+
+void *
+xmalloc(size_t size)
+{
+return nonnull(malloc(size));
+}
+
+void *
+xrealloc(void *p, size_t new_size)
+{
+return nonnull(realloc(p, new_size));
+}
+
+char *
+xstrdup(const char *s)
+{
+return nonnull(strdup(s));
+}

Index: src/usr.bin/indent/indent.h
diff -u src/usr.bin/indent/indent.h:1.16 src/usr.bin/indent/indent.h:1.17
--- src/usr.bin/indent/indent.h:1.16	Sun Mar 14 00:33:25 2021
+++ src/usr.bin/indent/indent.h	Sat Sep 25 08:23:31 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.h,v 1.16 2021/03/14 00:33:25 rillig Exp $	*/
+/*	$NetBSD: indent.h,v 1.17 2021/09/25 08:23:31 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -68,3 +68,7 @@ void		process_comment(void);
 void		set_defaults(void);
 void		set_option(char *);
 void		set_profile(const char *);
+
+void		*xmalloc(size_t);
+void		*xrealloc(void *, size_t);
+char		*xstrdup(const char *);

Index: src/usr.bin/indent/io.c
diff -u src/usr.bin/indent/io.c:1.56 src/usr.bin/indent/io.c:1.57
--- src/usr.bin/indent/io.c:1.56	Sat Sep 25 08:04:13 2021
+++ src/usr.bin/indent/io.c	Sat Sep 25 08:23:31 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: io.c,v 1.56 2021/09/25 08:04:13 rillig Exp $	*/
+/*	$NetBSD: io.c,v 1.57 2021/09/25 08:23:31 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -46,7 +46,7 @@ static char sccsid[] = "@(#)io.c	8.1 (Be
 #include 
 #ifndef lint
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: io.c,v 1.56 2021/09/25 08:04:13 rillig Exp $");

CVS commit: src/usr.bin/indent

2021-09-25 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Sep 25 08:23:32 UTC 2021

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

Log Message:
indent: add nonnull memory allocation functions

The only functional change is a single error message.


To generate a diff of this commit:
cvs rdiff -u -r1.67 -r1.68 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.16 -r1.17 src/usr.bin/indent/indent.h
cvs rdiff -u -r1.56 -r1.57 src/usr.bin/indent/io.c
cvs rdiff -u -r1.50 -r1.51 src/usr.bin/indent/lexi.c
cvs rdiff -u -r1.39 -r1.40 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-09-25 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Sep 25 08:04:13 UTC 2021

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

Log Message:
indent: group global variables for token buffer

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.66 -r1.67 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.25 -r1.26 src/usr.bin/indent/indent_globs.h
cvs rdiff -u -r1.55 -r1.56 src/usr.bin/indent/io.c
cvs rdiff -u -r1.49 -r1.50 src/usr.bin/indent/lexi.c
cvs rdiff -u -r1.21 -r1.22 src/usr.bin/indent/parse.c
cvs rdiff -u -r1.38 -r1.39 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.66 src/usr.bin/indent/indent.c:1.67
--- src/usr.bin/indent/indent.c:1.66	Sat Sep 25 07:59:52 2021
+++ src/usr.bin/indent/indent.c	Sat Sep 25 08:04:13 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.66 2021/09/25 07:59:52 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.67 2021/09/25 08:04:13 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -46,7 +46,7 @@ static char sccsid[] = "@(#)indent.c	5.1
 #include 
 #ifndef lint
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: indent.c,v 1.66 2021/09/25 07:59:52 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.67 2021/09/25 08:04:13 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -74,11 +74,7 @@ struct parser_state ps;
 struct buffer lab;
 struct buffer code;
 struct buffer com;
-
-char   *tokenbuf;
-char	   *s_token;
-char   *e_token;
-char	   *l_token;
+struct buffer token;
 
 char   *in_buffer;
 char	   *in_buffer_limit;
@@ -259,11 +255,11 @@ search_brace(token_type *inout_ttype, in
 
 	remove_newlines =
 		/* "} else" */
-		(*inout_ttype == keyword_do_else && *s_token == 'e' &&
+		(*inout_ttype == keyword_do_else && *token.s == 'e' &&
 		 code.e != code.s && code.e[-1] == '}')
 		/* "else if" */
 		|| (*inout_ttype == keyword_for_if_while &&
-			*s_token == 'i' && *inout_last_else && opt.else_if);
+			*token.s == 'i' && *inout_last_else && opt.else_if);
 	if (remove_newlines)
 		*inout_force_nl = false;
 	if (sc_end == NULL) {	/* ignore buffering if
@@ -292,7 +288,7 @@ search_brace(token_type *inout_ttype, in
  * not already broken */
 		diag(0, "Line broken");
 	}
-	for (const char *t_ptr = s_token; *t_ptr; ++t_ptr)
+	for (const char *t_ptr = token.s; *t_ptr; ++t_ptr)
 		*sc_end++ = *t_ptr;
 
 	sw_buffer:
@@ -375,23 +371,23 @@ main_init_globals(void)
 code.buf = malloc(bufsize);
 if (code.buf == NULL)
 	err(1, NULL);
-tokenbuf = malloc(bufsize);
-if (tokenbuf == NULL)
+token.buf = malloc(bufsize);
+if (token.buf == NULL)
 	err(1, NULL);
 alloc_typenames();
 init_constant_tt();
 com.l = com.buf + bufsize - 5;
 lab.l = lab.buf + bufsize - 5;
 code.l = code.buf + bufsize - 5;
-l_token = tokenbuf + bufsize - 5;
+token.l = token.buf + bufsize - 5;
 com.buf[0] = code.buf[0] = lab.buf[0] = ' ';	/* set up code, label, and
 		 * comment buffers */
-com.buf[1] = code.buf[1] = lab.buf[1] = tokenbuf[1] = '\0';
+com.buf[1] = code.buf[1] = lab.buf[1] = token.buf[1] = '\0';
 opt.else_if = 1;		/* Default else-if special processing to on */
 lab.s = lab.e = lab.buf + 1;
 code.s = code.e = code.buf + 1;
 com.s = com.e = com.buf + 1;
-s_token = e_token = tokenbuf + 1;
+token.s = token.e = token.buf + 1;
 
 in_buffer = malloc(10);
 if (in_buffer == NULL)
@@ -616,7 +612,7 @@ process_lparen_or_lbracket(int dec_ind, 
 	nitems(ps.paren_indents));
 	ps.p_l_follow--;
 }
-if (*s_token == '[')
+if (*token.s == '[')
 	/* not a function pointer declaration or a function call */;
 else if (ps.in_decl && !ps.block_init && !ps.dumped_decl_indent &&
 	ps.procname[0] == '\0' && ps.paren_level == 0) {
@@ -630,7 +626,7 @@ process_lparen_or_lbracket(int dec_ind, 
 	ps.keyword != rw_0 && ps.keyword != rw_offsetof)))
 	*code.e++ = ' ';
 ps.want_blank = false;
-*code.e++ = s_token[0];
+*code.e++ = token.s[0];
 
 ps.paren_indents[ps.p_l_follow - 1] =
 	indentation_after_range(0, code.s, code.e);
@@ -642,7 +638,7 @@ process_lparen_or_lbracket(int dec_ind, 
 	ps.paren_indents[0] = 2 * opt.indent_size;
 	debug_println("paren_indent[0] is now %d", ps.paren_indents[0]);
 }
-if (ps.in_or_st && *s_token == '(' && ps.tos <= 2) {
+if (ps.in_or_st && *token.s == '(' && ps.tos <= 2) {
 	/*
 	 * this is a kluge to make sure that declarations will be
 	 * aligned right if proc decl has an explicit type on it, i.e.
@@ -671,13 +667,13 @@ process_rparen_or_rbracket(int *inout_sp
 
 if (--ps.p_l_follow < 0) {
 	ps.p_l_follow = 0;
-	diag(0, "Extra 

CVS commit: src/usr.bin/indent

2021-09-25 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Sep 25 08:04:13 UTC 2021

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

Log Message:
indent: group global variables for token buffer

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.66 -r1.67 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.25 -r1.26 src/usr.bin/indent/indent_globs.h
cvs rdiff -u -r1.55 -r1.56 src/usr.bin/indent/io.c
cvs rdiff -u -r1.49 -r1.50 src/usr.bin/indent/lexi.c
cvs rdiff -u -r1.21 -r1.22 src/usr.bin/indent/parse.c
cvs rdiff -u -r1.38 -r1.39 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-09-25 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Sep 25 07:59:52 UTC 2021

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

Log Message:
indent: inline macro 'token'

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.65 -r1.66 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.24 -r1.25 src/usr.bin/indent/indent_globs.h
cvs rdiff -u -r1.48 -r1.49 src/usr.bin/indent/lexi.c
cvs rdiff -u -r1.20 -r1.21 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/indent.c
diff -u src/usr.bin/indent/indent.c:1.65 src/usr.bin/indent/indent.c:1.66
--- src/usr.bin/indent/indent.c:1.65	Sat Sep 25 07:55:24 2021
+++ src/usr.bin/indent/indent.c	Sat Sep 25 07:59:52 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.65 2021/09/25 07:55:24 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.66 2021/09/25 07:59:52 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -46,7 +46,7 @@ static char sccsid[] = "@(#)indent.c	5.1
 #include 
 #ifndef lint
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: indent.c,v 1.65 2021/09/25 07:55:24 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.66 2021/09/25 07:59:52 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -259,11 +259,11 @@ search_brace(token_type *inout_ttype, in
 
 	remove_newlines =
 		/* "} else" */
-		(*inout_ttype == keyword_do_else && *token == 'e' &&
+		(*inout_ttype == keyword_do_else && *s_token == 'e' &&
 		 code.e != code.s && code.e[-1] == '}')
 		/* "else if" */
 		|| (*inout_ttype == keyword_for_if_while &&
-			*token == 'i' && *inout_last_else && opt.else_if);
+			*s_token == 'i' && *inout_last_else && opt.else_if);
 	if (remove_newlines)
 		*inout_force_nl = false;
 	if (sc_end == NULL) {	/* ignore buffering if
@@ -292,7 +292,7 @@ search_brace(token_type *inout_ttype, in
  * not already broken */
 		diag(0, "Line broken");
 	}
-	for (const char *t_ptr = token; *t_ptr; ++t_ptr)
+	for (const char *t_ptr = s_token; *t_ptr; ++t_ptr)
 		*sc_end++ = *t_ptr;
 
 	sw_buffer:
@@ -616,7 +616,7 @@ process_lparen_or_lbracket(int dec_ind, 
 	nitems(ps.paren_indents));
 	ps.p_l_follow--;
 }
-if (*token == '[')
+if (*s_token == '[')
 	/* not a function pointer declaration or a function call */;
 else if (ps.in_decl && !ps.block_init && !ps.dumped_decl_indent &&
 	ps.procname[0] == '\0' && ps.paren_level == 0) {
@@ -630,7 +630,7 @@ process_lparen_or_lbracket(int dec_ind, 
 	ps.keyword != rw_0 && ps.keyword != rw_offsetof)))
 	*code.e++ = ' ';
 ps.want_blank = false;
-*code.e++ = token[0];
+*code.e++ = s_token[0];
 
 ps.paren_indents[ps.p_l_follow - 1] =
 	indentation_after_range(0, code.s, code.e);
@@ -642,7 +642,7 @@ process_lparen_or_lbracket(int dec_ind, 
 	ps.paren_indents[0] = 2 * opt.indent_size;
 	debug_println("paren_indent[0] is now %d", ps.paren_indents[0]);
 }
-if (ps.in_or_st && *token == '(' && ps.tos <= 2) {
+if (ps.in_or_st && *s_token == '(' && ps.tos <= 2) {
 	/*
 	 * this is a kluge to make sure that declarations will be
 	 * aligned right if proc decl has an explicit type on it, i.e.
@@ -671,13 +671,13 @@ process_rparen_or_rbracket(int *inout_sp
 
 if (--ps.p_l_follow < 0) {
 	ps.p_l_follow = 0;
-	diag(0, "Extra %c", *token);
+	diag(0, "Extra %c", *s_token);
 }
 
 if (code.e == code.s)	/* if the paren starts the line */
 	ps.paren_level = ps.p_l_follow;	/* then indent it */
 
-*code.e++ = token[0];
+*code.e++ = s_token[0];
 
 if (*inout_sp_sw && (ps.p_l_follow == 0)) {	/* check for end of if
  * (...), or some such */
@@ -706,7 +706,7 @@ process_unary_op(int dec_ind, int tabs_t
 	 * this token
 	 */
 	int i;
-	for (i = 0; token[i]; ++i)
+	for (i = 0; s_token[i]; ++i)
 	/* find length of token */;
 	indent_declaration(dec_ind - i, tabs_to_var);
 	ps.dumped_decl_indent = true;
@@ -717,7 +717,7 @@ process_unary_op(int dec_ind, int tabs_t
 	size_t len = e_token - s_token;
 
 	check_size_code(len);
-	memcpy(code.e, token, len);
+	memcpy(code.e, s_token, len);
 	code.e += len;
 }
 ps.want_blank = false;
@@ -731,7 +731,7 @@ process_binary_op(void)
 check_size_code(len + 1);
 if (ps.want_blank)
 	*code.e++ = ' ';
-memcpy(code.e, token, len);
+memcpy(code.e, s_token, len);
 code.e += len;
 
 ps.want_blank = true;
@@ -740,8 +740,8 @@ process_binary_op(void)
 static void
 process_postfix_op(void)
 {
-*code.e++ = token[0];
-*code.e++ = token[1];
+*code.e++ = s_token[0];
+*code.e++ = s_token[1];
 ps.want_blank = true;
 }
 
@@ -966,7 +966,7 @@ static void
 process_keyword_do_else(int *inout_force_nl, int *inout_last_else)
 {
 ps.in_stmt = false;
-if (*token == 'e') {
+if (*s_token == 'e') {
 	

CVS commit: src/usr.bin/indent

2021-09-25 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Sep 25 07:59:52 UTC 2021

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

Log Message:
indent: inline macro 'token'

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.65 -r1.66 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.24 -r1.25 src/usr.bin/indent/indent_globs.h
cvs rdiff -u -r1.48 -r1.49 src/usr.bin/indent/lexi.c
cvs rdiff -u -r1.20 -r1.21 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-09-25 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Sep 25 07:55:24 UTC 2021

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

Log Message:
indent: group global variables for code buffer

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.64 -r1.65 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.23 -r1.24 src/usr.bin/indent/indent_globs.h
cvs rdiff -u -r1.54 -r1.55 src/usr.bin/indent/io.c
cvs rdiff -u -r1.47 -r1.48 src/usr.bin/indent/lexi.c
cvs rdiff -u -r1.19 -r1.20 src/usr.bin/indent/parse.c
cvs rdiff -u -r1.37 -r1.38 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.64 src/usr.bin/indent/indent.c:1.65
--- src/usr.bin/indent/indent.c:1.64	Sat Sep 25 07:46:41 2021
+++ src/usr.bin/indent/indent.c	Sat Sep 25 07:55:24 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.64 2021/09/25 07:46:41 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.65 2021/09/25 07:55:24 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -46,7 +46,7 @@ static char sccsid[] = "@(#)indent.c	5.1
 #include 
 #ifndef lint
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: indent.c,v 1.64 2021/09/25 07:46:41 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.65 2021/09/25 07:55:24 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -72,12 +72,7 @@ struct options opt;
 struct parser_state ps;
 
 struct buffer lab;
-
-char   *codebuf;
-char   *s_code;
-char   *e_code;
-char   *l_code;
-
+struct buffer code;
 struct buffer com;
 
 char   *tokenbuf;
@@ -130,17 +125,17 @@ charbakfile[MAXPATHLEN] = "";
 static void
 check_size_code(size_t desired_size)
 {
-if (e_code + (desired_size) < l_code)
+if (code.e + desired_size < code.l)
 return;
 
-size_t nsize = l_code - s_code + 400 + desired_size;
-size_t code_len = e_code - s_code;
-codebuf = realloc(codebuf, nsize);
-if (codebuf == NULL)
+size_t nsize = code.l - code.s + 400 + desired_size;
+size_t code_len = code.e - code.s;
+code.buf = realloc(code.buf, nsize);
+if (code.buf == NULL)
 	err(1, NULL);
-e_code = codebuf + code_len + 1;
-l_code = codebuf + nsize - 5;
-s_code = codebuf + 1;
+code.e = code.buf + code_len + 1;
+code.l = code.buf + nsize - 5;
+code.s = code.buf + 1;
 }
 
 static void
@@ -265,7 +260,7 @@ search_brace(token_type *inout_ttype, in
 	remove_newlines =
 		/* "} else" */
 		(*inout_ttype == keyword_do_else && *token == 'e' &&
-		 e_code != s_code && e_code[-1] == '}')
+		 code.e != code.s && code.e[-1] == '}')
 		/* "else if" */
 		|| (*inout_ttype == keyword_for_if_while &&
 			*token == 'i' && *inout_last_else && opt.else_if);
@@ -377,8 +372,8 @@ main_init_globals(void)
 lab.buf = malloc(bufsize);
 if (lab.buf == NULL)
 	err(1, NULL);
-codebuf = malloc(bufsize);
-if (codebuf == NULL)
+code.buf = malloc(bufsize);
+if (code.buf == NULL)
 	err(1, NULL);
 tokenbuf = malloc(bufsize);
 if (tokenbuf == NULL)
@@ -387,14 +382,14 @@ main_init_globals(void)
 init_constant_tt();
 com.l = com.buf + bufsize - 5;
 lab.l = lab.buf + bufsize - 5;
-l_code = codebuf + bufsize - 5;
+code.l = code.buf + bufsize - 5;
 l_token = tokenbuf + bufsize - 5;
-com.buf[0] = codebuf[0] = lab.buf[0] = ' ';	/* set up code, label, and
+com.buf[0] = code.buf[0] = lab.buf[0] = ' ';	/* set up code, label, and
 		 * comment buffers */
-com.buf[1] = codebuf[1] = lab.buf[1] = tokenbuf[1] = '\0';
+com.buf[1] = code.buf[1] = lab.buf[1] = tokenbuf[1] = '\0';
 opt.else_if = 1;		/* Default else-if special processing to on */
 lab.s = lab.e = lab.buf + 1;
-s_code = e_code = codebuf + 1;
+code.s = code.e = code.buf + 1;
 com.s = com.e = com.buf + 1;
 s_token = e_token = tokenbuf + 1;
 
@@ -543,7 +538,7 @@ main_prepare_parsing(void)
 static void __attribute__((__noreturn__))
 process_end_of_file(void)
 {
-if (lab.s != lab.e || s_code != e_code || com.s != com.e)
+if (lab.s != lab.e || code.s != code.e || com.s != com.e)
 	dump_line();
 
 if (ps.tos > 1)		/* check for balanced braces */
@@ -583,11 +578,11 @@ process_comment_in_code(token_type ttype
 	size_t len = com.e - com.s;
 
 	check_size_code(len + 3);
-	*e_code++ = ' ';
-	memcpy(e_code, com.s, len);
-	e_code += len;
-	*e_code++ = ' ';
-	*e_code = '\0';
+	*code.e++ = ' ';
+	memcpy(code.e, com.s, len);
+	code.e += len;
+	*code.e++ = ' ';
+	*code.e = '\0';
 	ps.want_blank = false;
 	com.e = com.s;
 }
@@ -633,12 +628,12 @@ process_lparen_or_lbracket(int dec_ind, 
 	opt.proc_calls_space ||
 	(ps.keyword == rw_sizeof ? opt.Bill_Shannon :
 	ps.keyword != 

CVS commit: src/usr.bin/indent

2021-09-25 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Sep 25 07:55:24 UTC 2021

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

Log Message:
indent: group global variables for code buffer

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.64 -r1.65 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.23 -r1.24 src/usr.bin/indent/indent_globs.h
cvs rdiff -u -r1.54 -r1.55 src/usr.bin/indent/io.c
cvs rdiff -u -r1.47 -r1.48 src/usr.bin/indent/lexi.c
cvs rdiff -u -r1.19 -r1.20 src/usr.bin/indent/parse.c
cvs rdiff -u -r1.37 -r1.38 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-09-25 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Sep 25 07:46:41 UTC 2021

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

Log Message:
indent: rename variables of type token_type

The previous variable name 'code' conflicts with the buffer of the same
name.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.63 -r1.64 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.46 -r1.47 src/usr.bin/indent/lexi.c
cvs rdiff -u -r1.18 -r1.19 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/indent.c
diff -u src/usr.bin/indent/indent.c:1.63 src/usr.bin/indent/indent.c:1.64
--- src/usr.bin/indent/indent.c:1.63	Fri Sep 24 18:47:29 2021
+++ src/usr.bin/indent/indent.c	Sat Sep 25 07:46:41 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.63 2021/09/24 18:47:29 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.64 2021/09/25 07:46:41 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -46,7 +46,7 @@ static char sccsid[] = "@(#)indent.c	5.1
 #include 
 #ifndef lint
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: indent.c,v 1.63 2021/09/24 18:47:29 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.64 2021/09/25 07:46:41 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -178,11 +178,11 @@ init_capsicum(void)
 #endif
 
 static void
-search_brace(token_type *inout_type_code, int *inout_force_nl,
+search_brace(token_type *inout_ttype, int *inout_force_nl,
 	 int *inout_comment_buffered, int *inout_last_else)
 {
 while (ps.search_brace) {
-	switch (*inout_type_code) {
+	switch (*inout_ttype) {
 	case newline:
 	if (sc_end == NULL) {
 		save_com = sc_buf;
@@ -264,10 +264,10 @@ search_brace(token_type *inout_type_code
 
 	remove_newlines =
 		/* "} else" */
-		(*inout_type_code == keyword_do_else && *token == 'e' &&
+		(*inout_ttype == keyword_do_else && *token == 'e' &&
 		 e_code != s_code && e_code[-1] == '}')
 		/* "else if" */
-		|| (*inout_type_code == keyword_for_if_while &&
+		|| (*inout_ttype == keyword_for_if_while &&
 			*token == 'i' && *inout_last_else && opt.else_if);
 	if (remove_newlines)
 		*inout_force_nl = false;
@@ -317,7 +317,7 @@ search_brace(token_type *inout_type_code
 	 * We must make this check, just in case there was an unexpected
 	 * EOF.
 	 */
-	if (*inout_type_code != end_of_file) {
+	if (*inout_ttype != end_of_file) {
 	/*
 	 * The only intended purpose of calling lexi() below is to
 	 * categorize the next token in order to decide whether to
@@ -351,9 +351,9 @@ search_brace(token_type *inout_type_code
 
 	struct parser_state transient_state;
 	transient_state = ps;
-	*inout_type_code = lexi(_state);	/* read another token */
-	if (*inout_type_code != newline && *inout_type_code != form_feed &&
-		*inout_type_code != comment && !transient_state.search_brace) {
+	*inout_ttype = lexi(_state);	/* read another token */
+	if (*inout_ttype != newline && *inout_ttype != form_feed &&
+		*inout_ttype != comment && !transient_state.search_brace) {
 		ps = transient_state;
 	}
 	}
@@ -561,11 +561,11 @@ process_end_of_file(void)
 }
 
 static void
-process_comment_in_code(token_type type_code, int *inout_force_nl)
+process_comment_in_code(token_type ttype, int *inout_force_nl)
 {
 if (*inout_force_nl &&
-	type_code != semicolon &&
-	(type_code != lbrace || !opt.btype_2)) {
+	ttype != semicolon &&
+	(ttype != lbrace || !opt.btype_2)) {
 
 	/* we should force a broken line here */
 	if (opt.verbose)
@@ -587,7 +587,7 @@ process_comment_in_code(token_type type_
 	memcpy(e_code, com.s, len);
 	e_code += len;
 	*e_code++ = ' ';
-	*e_code = '\0';		/* null terminate code sect */
+	*e_code = '\0';
 	ps.want_blank = false;
 	com.e = com.s;
 }
@@ -1029,11 +1029,11 @@ process_decl(int *out_dec_ind, int *out_
 }
 
 static void
-process_ident(token_type type_code, int dec_ind, int tabs_to_var,
+process_ident(token_type ttype, int dec_ind, int tabs_to_var,
 	  int *inout_sp_sw, int *inout_force_nl, token_type hd_type)
 {
 if (ps.in_decl) {
-	if (type_code == funcname) {
+	if (ttype == funcname) {
 	ps.in_decl = false;
 	if (opt.procnames_start_line && s_code != e_code) {
 		*e_code = '\0';
@@ -1256,7 +1256,7 @@ process_preprocessing(void)
 static void __attribute__((__noreturn__))
 main_loop(void)
 {
-token_type type_code;
+token_type ttype;
 int force_nl;		/* when true, code must be broken */
 int last_else = false;	/* true iff last keyword was an else */
 int dec_ind;	/* current indentation for declarations */
@@ -1283,9 +1283,8 @@ main_loop(void)
  * reach eof */
 	int comment_buffered = false;
 
-	type_code = lexi();	/* lexi reads one token.  The actual
- * characters read are stored in "token". lexi
-		

CVS commit: src/usr.bin/indent

2021-09-25 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Sat Sep 25 07:46:41 UTC 2021

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

Log Message:
indent: rename variables of type token_type

The previous variable name 'code' conflicts with the buffer of the same
name.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.63 -r1.64 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.46 -r1.47 src/usr.bin/indent/lexi.c
cvs rdiff -u -r1.18 -r1.19 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-09-24 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Sep 24 18:47:29 UTC 2021

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

Log Message:
indent: group global variables for label buffer into struct

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.62 -r1.63 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.22 -r1.23 src/usr.bin/indent/indent_globs.h
cvs rdiff -u -r1.53 -r1.54 src/usr.bin/indent/io.c
cvs rdiff -u -r1.45 -r1.46 src/usr.bin/indent/lexi.c
cvs rdiff -u -r1.36 -r1.37 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.62 src/usr.bin/indent/indent.c:1.63
--- src/usr.bin/indent/indent.c:1.62	Fri Sep 24 18:14:06 2021
+++ src/usr.bin/indent/indent.c	Fri Sep 24 18:47:29 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.62 2021/09/24 18:14:06 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.63 2021/09/24 18:47:29 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -46,7 +46,7 @@ static char sccsid[] = "@(#)indent.c	5.1
 #include 
 #ifndef lint
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: indent.c,v 1.62 2021/09/24 18:14:06 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.63 2021/09/24 18:47:29 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -71,17 +71,14 @@ __FBSDID("$FreeBSD: head/usr.bin/indent/
 struct options opt;
 struct parser_state ps;
 
-char   *labbuf;
-char   *s_lab;
-char   *e_lab;
-char   *l_lab;
+struct buffer lab;
 
 char   *codebuf;
 char   *s_code;
 char   *e_code;
 char   *l_code;
 
-struct comment_buffer com;
+struct buffer com;
 
 char   *tokenbuf;
 char	   *s_token;
@@ -149,17 +146,17 @@ check_size_code(size_t desired_size)
 static void
 check_size_label(size_t desired_size)
 {
-if (e_lab + (desired_size) < l_lab)
+if (lab.e + (desired_size) < lab.l)
 return;
 
-size_t nsize = l_lab - s_lab + 400 + desired_size;
-size_t label_len = e_lab - s_lab;
-labbuf = realloc(labbuf, nsize);
-if (labbuf == NULL)
+size_t nsize = lab.l - lab.s + 400 + desired_size;
+size_t label_len = lab.e - lab.s;
+lab.buf = realloc(lab.buf, nsize);
+if (lab.buf == NULL)
 	err(1, NULL);
-e_lab = labbuf + label_len + 1;
-l_lab = labbuf + nsize - 5;
-s_lab = labbuf + 1;
+lab.e = lab.buf + label_len + 1;
+lab.l = lab.buf + nsize - 5;
+lab.s = lab.buf + 1;
 }
 
 #if HAVE_CAPSICUM
@@ -377,8 +374,8 @@ main_init_globals(void)
 com.buf = malloc(bufsize);
 if (com.buf == NULL)
 	err(1, NULL);
-labbuf = malloc(bufsize);
-if (labbuf == NULL)
+lab.buf = malloc(bufsize);
+if (lab.buf == NULL)
 	err(1, NULL);
 codebuf = malloc(bufsize);
 if (codebuf == NULL)
@@ -389,14 +386,14 @@ main_init_globals(void)
 alloc_typenames();
 init_constant_tt();
 com.l = com.buf + bufsize - 5;
-l_lab = labbuf + bufsize - 5;
+lab.l = lab.buf + bufsize - 5;
 l_code = codebuf + bufsize - 5;
 l_token = tokenbuf + bufsize - 5;
-com.buf[0] = codebuf[0] = labbuf[0] = ' ';	/* set up code, label, and
+com.buf[0] = codebuf[0] = lab.buf[0] = ' ';	/* set up code, label, and
 		 * comment buffers */
-com.buf[1] = codebuf[1] = labbuf[1] = tokenbuf[1] = '\0';
+com.buf[1] = codebuf[1] = lab.buf[1] = tokenbuf[1] = '\0';
 opt.else_if = 1;		/* Default else-if special processing to on */
-s_lab = e_lab = labbuf + 1;
+lab.s = lab.e = lab.buf + 1;
 s_code = e_code = codebuf + 1;
 com.s = com.e = com.buf + 1;
 s_token = e_token = tokenbuf + 1;
@@ -546,7 +543,7 @@ main_prepare_parsing(void)
 static void __attribute__((__noreturn__))
 process_end_of_file(void)
 {
-if (s_lab != e_lab || s_code != e_code || com.s != com.e)
+if (lab.s != lab.e || s_code != e_code || com.s != com.e)
 	dump_line();
 
 if (ps.tos > 1)		/* check for balanced braces */
@@ -790,10 +787,10 @@ process_colon(int *inout_squest, int *in
 	size_t len = e_code - s_code;
 
 	check_size_label(len + 3);
-	memcpy(e_lab, s_code, len);
-	e_lab += len;
-	*e_lab++ = ':';
-	*e_lab = '\0';
+	memcpy(lab.e, s_code, len);
+	lab.e += len;
+	*lab.e++ = ':';
+	*lab.e = '\0';
 	e_code = s_code;
 }
 *inout_force_nl = ps.pcase = *inout_scase;	/* ps.pcase will be used by
@@ -1120,10 +1117,10 @@ process_comma(int dec_ind, int tabs_to_v
 static void
 process_preprocessing(void)
 {
-if (com.s != com.e || s_lab != e_lab || s_code != e_code)
+if (com.s != com.e || lab.s != lab.e || s_code != e_code)
 	dump_line();
 check_size_label(1);
-*e_lab++ = '#';	/* move whole line to 'label' buffer */
+*lab.e++ = '#';	/* move whole line to 'label' buffer */
 
 {
 	int in_comment = 0;
@@ -1138,13 +1135,13 @@ 

CVS commit: src/usr.bin/indent

2021-09-24 Thread Roland Illig
Module Name:src
Committed By:   rillig
Date:   Fri Sep 24 18:47:29 UTC 2021

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

Log Message:
indent: group global variables for label buffer into struct

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.62 -r1.63 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.22 -r1.23 src/usr.bin/indent/indent_globs.h
cvs rdiff -u -r1.53 -r1.54 src/usr.bin/indent/io.c
cvs rdiff -u -r1.45 -r1.46 src/usr.bin/indent/lexi.c
cvs rdiff -u -r1.36 -r1.37 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.



<    3   4   5   6   7   8   9   >