Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/indent indent: use character input API from pr_comme...
details: https://anonhg.NetBSD.org/src/rev/67a228645e8f
branches: trunk
changeset: 1026335:67a228645e8f
user: rillig <rillig%NetBSD.org@localhost>
date: Fri Nov 19 18:23:59 2021 +0000
description:
indent: use character input API from pr_comment.c
No functional change.
diffstat:
usr.bin/indent/indent.h | 3 ++-
usr.bin/indent/io.c | 19 +++++++++++++++++--
usr.bin/indent/pr_comment.c | 29 ++++++++++-------------------
3 files changed, 29 insertions(+), 22 deletions(-)
diffs (130 lines):
diff -r 75398561b64f -r 67a228645e8f usr.bin/indent/indent.h
--- a/usr.bin/indent/indent.h Fri Nov 19 18:14:18 2021 +0000
+++ b/usr.bin/indent/indent.h Fri Nov 19 18:23:59 2021 +0000
@@ -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 @@
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);
diff -r 75398561b64f -r 67a228645e8f usr.bin/indent/io.c
--- a/usr.bin/indent/io.c Fri Nov 19 18:14:18 2021 +0000
+++ b/usr.bin/indent/io.c Fri Nov 19 18:23:59 2021 +0000
@@ -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 @@
#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 @@
}
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;
diff -r 75398561b64f -r 67a228645e8f usr.bin/indent/pr_comment.c
--- a/usr.bin/indent/pr_comment.c Fri Nov 19 18:14:18 2021 +0000
+++ b/usr.bin/indent/pr_comment.c Fri Nov 19 18:23:59 2021 +0000
@@ -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 @@
#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 @@
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 @@
/*
* 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 @@
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':
Home |
Main Index |
Thread Index |
Old Index