Module Name:    src
Committed By:   rillig
Date:           Tue Oct  5 06:09:42 UTC 2021

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

Log Message:
indent: merge duplicate code into is_hspace

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.100 -r1.101 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.28 -r1.29 src/usr.bin/indent/indent.h
cvs rdiff -u -r1.68 -r1.69 src/usr.bin/indent/io.c
cvs rdiff -u -r1.67 -r1.68 src/usr.bin/indent/lexi.c
cvs rdiff -u -r1.49 -r1.50 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.100 src/usr.bin/indent/indent.c:1.101
--- src/usr.bin/indent/indent.c:1.100	Tue Oct  5 05:56:49 2021
+++ src/usr.bin/indent/indent.c	Tue Oct  5 06:09:42 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.100 2021/10/05 05:56:49 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.101 2021/10/05 06:09:42 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@ static char sccsid[] = "@(#)indent.c	5.1
 
 #include <sys/cdefs.h>
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: indent.c,v 1.100 2021/10/05 05:56:49 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.101 2021/10/05 06:09:42 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -324,7 +324,7 @@ search_brace_lookahead(token_type *inout
 	 * into the buffer so that the later lexi() call will read them.
 	 */
 	if (sc_end != NULL) {
-	    while (*buf_ptr == ' ' || *buf_ptr == '\t') {
+	    while (is_hspace(*buf_ptr)) {
 		*sc_end++ = *buf_ptr++;
 		if (sc_end >= &save_com[sc_size]) {
 		    errx(1, "input too long");
@@ -1103,7 +1103,7 @@ process_preprocessing(void)
 	char quote = '\0';
 	int com_end = 0;
 
-	while (*buf_ptr == ' ' || *buf_ptr == '\t')
+	while (is_hspace(*buf_ptr))
 	    inbuf_skip();
 
 	while (*buf_ptr != '\n' || (in_comment && !had_eof)) {
@@ -1143,7 +1143,7 @@ process_preprocessing(void)
 	    }
 	}
 
-	while (lab.e > lab.s && (lab.e[-1] == ' ' || lab.e[-1] == '\t'))
+	while (lab.e > lab.s && is_hspace(lab.e[-1]))
 	    lab.e--;
 	if (lab.e - lab.s == com_end && bp_save == NULL) {
 	    /* comment on preprocessor line */
@@ -1161,7 +1161,7 @@ process_preprocessing(void)
 	    memmove(sc_end, lab.s + com_start, (size_t)(com_end - com_start));
 	    sc_end += com_end - com_start;
 	    lab.e = lab.s + com_start;
-	    while (lab.e > lab.s && (lab.e[-1] == ' ' || lab.e[-1] == '\t'))
+	    while (lab.e > lab.s && is_hspace(lab.e[-1]))
 		lab.e--;
 	    bp_save = buf_ptr;	/* save current input buffer */
 	    be_save = buf_end;

Index: src/usr.bin/indent/indent.h
diff -u src/usr.bin/indent/indent.h:1.28 src/usr.bin/indent/indent.h:1.29
--- src/usr.bin/indent/indent.h:1.28	Tue Oct  5 05:39:14 2021
+++ src/usr.bin/indent/indent.h	Tue Oct  5 06:09:42 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.h,v 1.28 2021/10/05 05:39:14 rillig Exp $	*/
+/*	$NetBSD: indent.h,v 1.29 2021/10/05 06:09:42 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -73,3 +73,9 @@ void		*xrealloc(void *, size_t);
 char		*xstrdup(const char *);
 
 void		buf_expand(struct buffer *, size_t);
+
+static inline bool
+is_hspace(char ch)
+{
+    return ch == ' ' || ch == '\t';
+}

Index: src/usr.bin/indent/io.c
diff -u src/usr.bin/indent/io.c:1.68 src/usr.bin/indent/io.c:1.69
--- src/usr.bin/indent/io.c:1.68	Sun Sep 26 21:23:31 2021
+++ src/usr.bin/indent/io.c	Tue Oct  5 06:09:42 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: io.c,v 1.68 2021/09/26 21:23:31 rillig Exp $	*/
+/*	$NetBSD: io.c,v 1.69 2021/10/05 06:09:42 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@ static char sccsid[] = "@(#)io.c	8.1 (Be
 
 #include <sys/cdefs.h>
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: io.c,v 1.68 2021/09/26 21:23:31 rillig Exp $");
+__RCSID("$NetBSD: io.c,v 1.69 2021/10/05 06:09:42 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/io.c 334927 2018-06-10 16:44:18Z pstef $");
 #endif
@@ -151,7 +151,7 @@ dump_line(void)
 		comment_open = false;
 		output_string(".*/\n");
 	    }
-	    while (lab.e > lab.s && (lab.e[-1] == ' ' || lab.e[-1] == '\t'))
+	    while (lab.e > lab.s && is_hspace(lab.e[-1]))
 		lab.e--;
 	    *lab.e = '\0';
 	    cur_col = 1 + output_indent(0, compute_label_indent());
@@ -163,7 +163,7 @@ dump_line(void)
 		do {
 		    output_char(*s++);
 		} while (s < lab.e && 'a' <= *s && *s <= 'z');
-		while ((*s == ' ' || *s == '\t') && s < lab.e)
+		while (s < lab.e && is_hspace(*s))
 		    s++;
 		if (s < lab.e) {
 		    if (s[0] == '/' && s[1] == '*') {
@@ -328,7 +328,7 @@ compute_label_indent(void)
 static void
 skip_hspace(const char **pp)
 {
-    while (**pp == ' ' || **pp == '\t')
+    while (is_hspace(**pp))
 	(*pp)++;
 }
 

Index: src/usr.bin/indent/lexi.c
diff -u src/usr.bin/indent/lexi.c:1.67 src/usr.bin/indent/lexi.c:1.68
--- src/usr.bin/indent/lexi.c:1.67	Tue Oct  5 05:56:49 2021
+++ src/usr.bin/indent/lexi.c	Tue Oct  5 06:09:42 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: lexi.c,v 1.67 2021/10/05 05:56:49 rillig Exp $	*/
+/*	$NetBSD: lexi.c,v 1.68 2021/10/05 06:09:42 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@ static char sccsid[] = "@(#)lexi.c	8.1 (
 
 #include <sys/cdefs.h>
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: lexi.c,v 1.67 2021/10/05 05:56:49 rillig Exp $");
+__RCSID("$NetBSD: lexi.c,v 1.68 2021/10/05 06:09:42 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/lexi.c 337862 2018-08-15 18:19:45Z pstef $");
 #endif
@@ -367,9 +367,8 @@ lexi(struct parser_state *state)
 					 * scanned was a newline */
     state->last_nl = false;
 
-    while (*buf_ptr == ' ' || *buf_ptr == '\t') {	/* get rid of blanks */
-	state->col_1 = false;	/* leading blanks imply token is not in column
-				 * 1 */
+    while (is_hspace(*buf_ptr)) {
+	state->col_1 = false;
 	inbuf_skip();
     }
 
@@ -391,7 +390,7 @@ lexi(struct parser_state *state)
 	    (*buf_ptr == '"' || *buf_ptr == '\''))
 	    return lexi_end(string_prefix);
 
-	while (*buf_ptr == ' ' || *buf_ptr == '\t')	/* get rid of blanks */
+	while (is_hspace(inbuf_peek()))
 	    inbuf_skip();
 	state->keyword = kw_0;
 

Index: src/usr.bin/indent/pr_comment.c
diff -u src/usr.bin/indent/pr_comment.c:1.49 src/usr.bin/indent/pr_comment.c:1.50
--- src/usr.bin/indent/pr_comment.c:1.49	Tue Oct  5 05:56:49 2021
+++ src/usr.bin/indent/pr_comment.c	Tue Oct  5 06:09:42 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: pr_comment.c,v 1.49 2021/10/05 05:56:49 rillig Exp $	*/
+/*	$NetBSD: pr_comment.c,v 1.50 2021/10/05 06:09:42 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@ static char sccsid[] = "@(#)pr_comment.c
 
 #include <sys/cdefs.h>
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: pr_comment.c,v 1.49 2021/10/05 05:56:49 rillig Exp $");
+__RCSID("$NetBSD: pr_comment.c,v 1.50 2021/10/05 06:09:42 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/pr_comment.c 334927 2018-06-10 16:44:18Z pstef $");
 #endif
@@ -160,7 +160,7 @@ process_comment(void)
 	ps.n_comment_delta = -indentation_after_range(0, start, buf_ptr - 2);
     } else {
 	ps.n_comment_delta = 0;
-	while (*buf_ptr == ' ' || *buf_ptr == '\t')
+	while (is_hspace(*buf_ptr))
 	    buf_ptr++;
     }
     ps.comment_delta = 0;
@@ -216,8 +216,9 @@ process_comment(void)
 		last_blank = -1;
 		if (!ps.box_com && opt.star_comment_cont)
 		    *com.e++ = ' ', *com.e++ = '*', *com.e++ = ' ';
-		while (*++buf_ptr == ' ' || *buf_ptr == '\t')
-		    ;
+		buf_ptr++;
+		while (is_hspace(*buf_ptr))
+		    buf_ptr++;
 	    } else {
 		inbuf_skip();
 		*com.e++ = 014;
@@ -250,7 +251,7 @@ process_comment(void)
 		    *com.e++ = ' ', *com.e++ = '*', *com.e++ = ' ';
 	    } else {
 		ps.last_nl = true;
-		if (!(com.e[-1] == ' ' || com.e[-1] == '\t'))
+		if (!is_hspace(com.e[-1]))
 		    *com.e++ = ' ';
 		last_blank = com.e - 1 - com.buf;
 	    }
@@ -265,7 +266,7 @@ process_comment(void)
 			if (*buf_ptr == '/')
 			    goto end_of_comment;
 		    }
-		} while (*buf_ptr == ' ' || *buf_ptr == '\t');
+		} while (is_hspace(*buf_ptr));
 	    } else
 		inbuf_skip();
 	    break;		/* end of case for newline */
@@ -284,7 +285,7 @@ process_comment(void)
 			com.s = com.e;
 		    *com.e++ = ' ';
 		}
-		if (com.e[-1] != ' ' && com.e[-1] != '\t' && !ps.box_com)
+		if (!is_hspace(com.e[-1]) && !ps.box_com)
 		    *com.e++ = ' ';	/* ensure blank before end */
 		if (token.e[-1] == '/')
 		    *com.e++ = '\n', *com.e = '\0';
@@ -301,7 +302,7 @@ process_comment(void)
 	    do {
 		check_size_comment(1);
 		char ch = inbuf_next();
-		if (ch == ' ' || ch == '\t')
+		if (is_hspace(ch))
 		    last_blank = com.e - com.buf;
 		*com.e++ = ch;
 		now_len++;
@@ -326,7 +327,7 @@ process_comment(void)
 		if (!ps.box_com && opt.star_comment_cont)
 		    *com.e++ = ' ', *com.e++ = '*', *com.e++ = ' ';
 		for (t_ptr = com.buf + last_blank + 1;
-		     *t_ptr == ' ' || *t_ptr == '\t'; t_ptr++)
+		     is_hspace(*t_ptr); t_ptr++)
 		    continue;
 		last_blank = -1;
 		/*
@@ -335,7 +336,7 @@ process_comment(void)
 		 * com.e without any check_size_comment().
 		 */
 		while (*t_ptr != '\0') {
-		    if (*t_ptr == ' ' || *t_ptr == '\t')
+		    if (is_hspace(*t_ptr))
 			last_blank = com.e - com.buf;
 		    *com.e++ = *t_ptr++;
 		}

Reply via email to