Module Name:    src
Committed By:   rillig
Date:           Fri Nov 19 17:20:57 UTC 2021

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

Log Message:
indent: move character input handling from lexi.c to io.c

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.89 -r1.90 src/usr.bin/indent/indent.h
cvs rdiff -u -r1.117 -r1.118 src/usr.bin/indent/io.c
cvs rdiff -u -r1.141 -r1.142 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.h
diff -u src/usr.bin/indent/indent.h:1.89 src/usr.bin/indent/indent.h:1.90
--- src/usr.bin/indent/indent.h:1.89	Fri Nov 19 17:11:46 2021
+++ src/usr.bin/indent/indent.h	Fri Nov 19 17:20:57 2021
@@ -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 compute_label_indent(void);
 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);
 

Index: src/usr.bin/indent/io.c
diff -u src/usr.bin/indent/io.c:1.117 src/usr.bin/indent/io.c:1.118
--- src/usr.bin/indent/io.c:1.117	Fri Nov 19 15:28:32 2021
+++ src/usr.bin/indent/io.c	Fri Nov 19 17:20:57 2021
@@ -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 @@ static char sccsid[] = "@(#)io.c	8.1 (Be
 
 #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 @@ __FBSDID("$FreeBSD: head/usr.bin/indent/
 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)
 {

Index: src/usr.bin/indent/lexi.c
diff -u src/usr.bin/indent/lexi.c:1.141 src/usr.bin/indent/lexi.c:1.142
--- src/usr.bin/indent/lexi.c:1.141	Fri Nov 19 17:11:46 2021
+++ src/usr.bin/indent/lexi.c	Fri Nov 19 17:20:57 2021
@@ -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 @@ static char sccsid[] = "@(#)lexi.c	8.1 (
 
 #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 @@ static const unsigned char lex_number_ro
     ['.'] = 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 @@ lex_word(void)
 	    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 @@ probably_typename(void)
 {
     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 @@ static lexer_symbol
 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 @@ lexi(void)
 	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;
 

Reply via email to