Module Name:    src
Committed By:   rillig
Date:           Fri Nov 19 18:23:59 UTC 2021

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

Log Message:
indent: use character input API from pr_comment.c

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.94 -r1.95 src/usr.bin/indent/indent.h
cvs rdiff -u -r1.122 -r1.123 src/usr.bin/indent/io.c
cvs rdiff -u -r1.119 -r1.120 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.h
diff -u src/usr.bin/indent/indent.h:1.94 src/usr.bin/indent/indent.h:1.95
--- src/usr.bin/indent/indent.h:1.94	Fri Nov 19 18:14:18 2021
+++ src/usr.bin/indent/indent.h	Fri Nov 19 18:23:59 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.h,v 1.94 2021/11/19 18:14:18 rillig Exp $	*/
+/*	$NetBSD: indent.h,v 1.95 2021/11/19 18:23:59 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -380,6 +380,7 @@ int ind_add(int, const char *, const cha
 void inp_init(void);
 
 const char *inp_p(void);
+const char *inp_line_start(void);
 const char *inp_line_end(void);
 char inp_peek(void);
 char inp_lookahead(size_t);

Index: src/usr.bin/indent/io.c
diff -u src/usr.bin/indent/io.c:1.122 src/usr.bin/indent/io.c:1.123
--- src/usr.bin/indent/io.c:1.122	Fri Nov 19 18:14:18 2021
+++ src/usr.bin/indent/io.c	Fri Nov 19 18:23:59 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: io.c,v 1.122 2021/11/19 18:14:18 rillig Exp $	*/
+/*	$NetBSD: io.c,v 1.123 2021/11/19 18:23:59 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.122 2021/11/19 18:14:18 rillig Exp $");
+__RCSID("$NetBSD: io.c,v 1.123 2021/11/19 18:23:59 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/io.c 334927 2018-06-10 16:44:18Z pstef $");
 #endif
@@ -79,6 +79,21 @@ inp_p(void)
 }
 
 const char *
+inp_line_start(void)
+{
+    /*
+     * The comment we're about to read usually comes from inp.buf, unless
+     * it has been copied into save_com.
+     *
+     * XXX: ordered comparison between pointers from different objects
+     * invokes undefined behavior (C99 6.5.8).
+     */
+    return inbuf.inp.s >= inbuf.save_com_buf &&
+	inbuf.inp.s < inbuf.save_com_buf + array_length(inbuf.save_com_buf)
+	? inbuf.save_com_buf : inbuf.inp.buf;
+}
+
+const char *
 inp_line_end(void)
 {
     return inbuf.inp.e;

Index: src/usr.bin/indent/pr_comment.c
diff -u src/usr.bin/indent/pr_comment.c:1.119 src/usr.bin/indent/pr_comment.c:1.120
--- src/usr.bin/indent/pr_comment.c:1.119	Fri Nov 19 17:11:46 2021
+++ src/usr.bin/indent/pr_comment.c	Fri Nov 19 18:23:59 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: pr_comment.c,v 1.119 2021/11/19 17:11:46 rillig Exp $	*/
+/*	$NetBSD: pr_comment.c,v 1.120 2021/11/19 18:23:59 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.119 2021/11/19 17:11:46 rillig Exp $");
+__RCSID("$NetBSD: pr_comment.c,v 1.120 2021/11/19 18:23:59 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/pr_comment.c 334927 2018-06-10 16:44:18Z pstef $");
 #endif
@@ -86,13 +86,13 @@ com_terminate(void)
 static bool
 fits_in_one_line(int max_line_length)
 {
-    for (const char *p = inbuf.inp.s; *p != '\n'; p++) {
+    for (const char *p = inp_p(); *p != '\n'; p++) {
 	assert(*p != '\0');
-	assert(inbuf.inp.e - p >= 2);
+	assert(inp_line_end() - p >= 2);
 	if (!(p[0] == '*' && p[1] == '/'))
 	    continue;
 
-	int len = ind_add(ps.com_ind + 3, inbuf.inp.s, p);
+	int len = ind_add(ps.com_ind + 3, inp_p(), p);
 	len += ch_isblank(p[-1]) ? 2 : 3;
 	return len <= max_line_length;
     }
@@ -152,22 +152,13 @@ analyze_comment(bool *p_may_wrap, bool *
 	/*
 	 * Find out how much indentation there was originally, because that
 	 * much will have to be ignored by dump_line().
-	 *
-	 * The comment we're about to read usually comes from inp.buf, unless
-	 * it has been copied into save_com.
-	 *
-	 * XXX: ordered comparison between pointers from different objects
-	 * invokes undefined behavior (C99 6.5.8).
 	 */
-	const char *start = inbuf.inp.s >= inbuf.save_com_buf &&
-		inbuf.inp.s <
-		    inbuf.save_com_buf + array_length(inbuf.save_com_buf)
-	    ? inbuf.save_com_buf : inbuf.inp.buf;
-	ps.n_comment_delta = -ind_add(0, start, inbuf.inp.s - 2);
+	const char *start = inp_line_start();
+	ps.n_comment_delta = -ind_add(0, start, inp_p() - 2);
     } else {
 	ps.n_comment_delta = 0;
 	while (ch_isblank(inp_peek()))
-	    inbuf.inp.s++;
+	    inp_skip();
     }
 
     ps.comment_delta = 0;
@@ -213,9 +204,9 @@ copy_comment_wrap(int adj_max_line_lengt
 	    dump_line_ff();
 	    last_blank = -1;
 	    com_add_delim();
-	    inbuf.inp.s++;
+	    inp_skip();
 	    while (ch_isblank(inp_peek()))
-		inbuf.inp.s++;
+		inp_skip();
 	    break;
 
 	case '\n':

Reply via email to