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: move character input handling from le...
details: https://anonhg.NetBSD.org/src/rev/d6a8dd7c8862
branches: trunk
changeset: 1026330:d6a8dd7c8862
user: rillig <rillig%NetBSD.org@localhost>
date: Fri Nov 19 17:20:57 2021 +0000
description:
indent: move character input handling from lexi.c to io.c
No functional change.
diffstat:
usr.bin/indent/indent.h | 3 ++-
usr.bin/indent/io.c | 34 ++++++++++++++++++++++++++++++++--
usr.bin/indent/lexi.c | 41 +++++++++--------------------------------
3 files changed, 43 insertions(+), 35 deletions(-)
diffs (166 lines):
diff -r 7ad7941bd719 -r d6a8dd7c8862 usr.bin/indent/indent.h
--- a/usr.bin/indent/indent.h Fri Nov 19 17:11:46 2021 +0000
+++ b/usr.bin/indent/indent.h Fri Nov 19 17:20:57 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: indent.h,v 1.89 2021/11/19 17:11:46 rillig Exp $ */
+/* $NetBSD: indent.h,v 1.90 2021/11/19 17:20:57 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -378,6 +378,7 @@
int ind_add(int, const char *, const char *);
char inp_peek(void);
+char inp_lookahead(size_t);
void inp_skip(void);
char inp_next(void);
diff -r 7ad7941bd719 -r d6a8dd7c8862 usr.bin/indent/io.c
--- a/usr.bin/indent/io.c Fri Nov 19 17:11:46 2021 +0000
+++ b/usr.bin/indent/io.c Fri Nov 19 17:20:57 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: io.c,v 1.117 2021/11/19 15:28:32 rillig Exp $ */
+/* $NetBSD: io.c,v 1.118 2021/11/19 17:20:57 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.117 2021/11/19 15:28:32 rillig Exp $");
+__RCSID("$NetBSD: io.c,v 1.118 2021/11/19 17:20:57 rillig Exp $");
#elif defined(__FreeBSD__)
__FBSDID("$FreeBSD: head/usr.bin/indent/io.c 334927 2018-06-10 16:44:18Z pstef $");
#endif
@@ -58,6 +58,36 @@
static int paren_indent;
static bool suppress_blanklines;
+
+char
+inp_peek(void)
+{
+ return *inbuf.inp.s;
+}
+
+char
+inp_lookahead(size_t i)
+{
+ return inbuf.inp.s[i];
+}
+
+void
+inp_skip(void)
+{
+ inbuf.inp.s++;
+ if (inbuf.inp.s >= inbuf.inp.e)
+ inp_read_line();
+}
+
+char
+inp_next(void)
+{
+ char ch = inp_peek();
+ inp_skip();
+ return ch;
+}
+
+
static void
output_char(char ch)
{
diff -r 7ad7941bd719 -r d6a8dd7c8862 usr.bin/indent/lexi.c
--- a/usr.bin/indent/lexi.c Fri Nov 19 17:11:46 2021 +0000
+++ b/usr.bin/indent/lexi.c Fri Nov 19 17:20:57 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lexi.c,v 1.141 2021/11/19 17:11:46 rillig Exp $ */
+/* $NetBSD: lexi.c,v 1.142 2021/11/19 17:20:57 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-4-Clause
@@ -43,11 +43,12 @@
#include <sys/cdefs.h>
#if defined(__NetBSD__)
-__RCSID("$NetBSD: lexi.c,v 1.141 2021/11/19 17:11:46 rillig Exp $");
+__RCSID("$NetBSD: lexi.c,v 1.142 2021/11/19 17:20:57 rillig Exp $");
#elif defined(__FreeBSD__)
__FBSDID("$FreeBSD: head/usr.bin/indent/lexi.c 337862 2018-08-15 18:19:45Z pstef $");
#endif
+#include <assert.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
@@ -178,28 +179,6 @@
['.'] = 15,
};
-char
-inp_peek(void)
-{
- return *inbuf.inp.s;
-}
-
-void
-inp_skip(void)
-{
- inbuf.inp.s++;
- if (inbuf.inp.s >= inbuf.inp.e)
- inp_read_line();
-}
-
-char
-inp_next(void)
-{
- char ch = inp_peek();
- inp_skip();
- return ch;
-}
-
static void
check_size_token(size_t desired_size)
{
@@ -378,10 +357,9 @@
inp_peek() == '_' || inp_peek() == '$') {
if (inp_peek() == '\\') {
- if (inbuf.inp.s[1] == '\n') {
- inbuf.inp.s += 2;
- if (inbuf.inp.s >= inbuf.inp.e)
- inp_read_line();
+ if (inp_lookahead(1) == '\n') {
+ inp_skip();
+ inp_skip();
} else
break;
}
@@ -417,7 +395,7 @@
{
if (ps.block_init || ps.in_stmt)
return false;
- if (inbuf.inp.s[0] == '*' && inbuf.inp.s[1] != '=')
+ if (inp_peek() == '*' && inp_lookahead(1) != '=')
goto maybe;
if (isalpha((unsigned char)inp_peek()))
goto maybe;
@@ -469,7 +447,7 @@
lexi_alnum(void)
{
if (isdigit((unsigned char)inp_peek()) ||
- (inbuf.inp.s[0] == '.' && isdigit((unsigned char)inbuf.inp.s[1]))) {
+ (inp_peek() == '.' && isdigit((unsigned char)inp_lookahead(1)))) {
lex_number();
} else if (isalnum((unsigned char)inp_peek()) ||
inp_peek() == '_' || inp_peek() == '$') {
@@ -738,8 +716,7 @@
unary_delim = true;
}
- if (inbuf.inp.s >= inbuf.inp.e)
- inp_read_line();
+ assert(inbuf.inp.s < inbuf.inp.e);
ps.next_unary = unary_delim;
Home |
Main Index |
Thread Index |
Old Index