Module Name:    src
Committed By:   rillig
Date:           Sun Jun  4 20:51:19 UTC 2023

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

Log Message:
indent: remove read pointer from buffers that don't need it

The only buffer that needs a read pointer is the current input line in
'inp'.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 src/usr.bin/indent/debug.c
cvs rdiff -u -r1.326 -r1.327 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.170 -r1.171 src/usr.bin/indent/indent.h
cvs rdiff -u -r1.192 -r1.193 src/usr.bin/indent/io.c
cvs rdiff -u -r1.211 -r1.212 src/usr.bin/indent/lexi.c
cvs rdiff -u -r1.150 -r1.151 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/debug.c
diff -u src/usr.bin/indent/debug.c:1.33 src/usr.bin/indent/debug.c:1.34
--- src/usr.bin/indent/debug.c:1.33	Sun Jun  4 17:54:11 2023
+++ src/usr.bin/indent/debug.c	Sun Jun  4 20:51:19 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: debug.c,v 1.33 2023/06/04 17:54:11 rillig Exp $	*/
+/*	$NetBSD: debug.c,v 1.34 2023/06/04 20:51:19 rillig Exp $	*/
 
 /*-
  * Copyright (c) 2023 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: debug.c,v 1.33 2023/06/04 17:54:11 rillig Exp $");
+__RCSID("$NetBSD: debug.c,v 1.34 2023/06/04 20:51:19 rillig Exp $");
 
 #include <stdarg.h>
 
@@ -196,7 +196,7 @@ debug_print_buf(const char *name, const 
 {
 	if (buf->len > 0) {
 		debug_printf(" %s ", name);
-		debug_vis_range("\"", buf->st, buf->len, "\"");
+		debug_vis_range("\"", buf->s, buf->len, "\"");
 	}
 }
 

Index: src/usr.bin/indent/indent.c
diff -u src/usr.bin/indent/indent.c:1.326 src/usr.bin/indent/indent.c:1.327
--- src/usr.bin/indent/indent.c:1.326	Sun Jun  4 17:54:11 2023
+++ src/usr.bin/indent/indent.c	Sun Jun  4 20:51:19 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.326 2023/06/04 17:54:11 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.327 2023/06/04 20:51:19 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: indent.c,v 1.326 2023/06/04 17:54:11 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.327 2023/06/04 20:51:19 rillig Exp $");
 
 #include <sys/param.h>
 #include <err.h>
@@ -110,8 +110,7 @@ static void
 buf_expand(struct buffer *buf, size_t add_size)
 {
 	buf->cap = buf->cap + add_size + 400;
-	buf->mem = nonnull(realloc(buf->mem, buf->cap));
-	buf->st = buf->mem;
+	buf->s = nonnull(realloc(buf->s, buf->cap));
 }
 
 void
@@ -119,7 +118,7 @@ buf_add_char(struct buffer *buf, char ch
 {
 	if (buf->len == buf->cap)
 		buf_expand(buf, 1);
-	buf->mem[buf->len++] = ch;
+	buf->s[buf->len++] = ch;
 }
 
 void
@@ -129,14 +128,14 @@ buf_add_chars(struct buffer *buf, const 
 		return;
 	if (len > buf->cap - buf->len)
 		buf_expand(buf, len);
-	memcpy(buf->mem + buf->len, s, len);
+	memcpy(buf->s + buf->len, s, len);
 	buf->len += len;
 }
 
 static void
 buf_add_buf(struct buffer *buf, const struct buffer *add)
 {
-	buf_add_chars(buf, add->st, add->len);
+	buf_add_chars(buf, add->s, add->len);
 }
 
 void
@@ -301,7 +300,7 @@ set_initial_indentation(void)
 	inp_read_line();
 
 	int ind = 0;
-	for (const char *p = inp.st;; p++) {
+	for (const char *p = inp_p;; p++) {
 		if (*p == ' ')
 			ind++;
 		else if (*p == '\t')
@@ -349,13 +348,13 @@ update_ps_decl_ptr(lexer_symbol lsym)
 			ps.decl_ptr = dp_other;
 		break;
 	case dp_word:
-		if (lsym == lsym_unary_op && token.st[0] == '*')
+		if (lsym == lsym_unary_op && token.s[0] == '*')
 			ps.decl_ptr = dp_word_asterisk;
 		else
 			ps.decl_ptr = dp_other;
 		break;
 	case dp_word_asterisk:
-		if (lsym == lsym_unary_op && token.st[0] == '*')
+		if (lsym == lsym_unary_op && token.s[0] == '*')
 			ps.decl_ptr = dp_word_asterisk;
 		else
 			ps.decl_ptr = dp_other;
@@ -375,8 +374,8 @@ static void
 update_ps_prev_tag(lexer_symbol lsym)
 {
 	if (lsym == lsym_tag) {
-		ps.lbrace_kind = token.mem[0] == 's' ? psym_lbrace_struct :
-		    token.mem[0] == 'u' ? psym_lbrace_union :
+		ps.lbrace_kind = token.s[0] == 's' ? psym_lbrace_struct :
+		    token.s[0] == 'u' ? psym_lbrace_union :
 		    psym_lbrace_enum;
 	} else if (lsym != lsym_type_outside_parentheses
 	    && lsym != lsym_word
@@ -493,7 +492,7 @@ process_lparen(void)
 	} else if (want_blank_before_lparen())
 		buf_add_char(&code, ' ');
 	ps.want_blank = false;
-	buf_add_char(&code, token.st[0]);
+	buf_add_char(&code, token.s[0]);
 
 	if (opt.extra_expr_indent && !opt.lineup_to_parens
 	    && ps.spaced_expr_psym != psym_0 && ps.nparen == 1
@@ -508,7 +507,7 @@ process_lparen(void)
 		ps.init_or_struct = false;
 	}
 
-	int indent = ind_add(0, code.st, code.len);
+	int indent = ind_add(0, code.s, code.len);
 	if (opt.extra_expr_indent && ps.spaced_expr_psym != psym_0
 	    && ps.nparen == 1 && indent < 2 * opt.indent_size)
 		indent = 2 * opt.indent_size;
@@ -548,9 +547,9 @@ process_lbracket(void)
 	if (want_blank_before_lbracket())
 		buf_add_char(&code, ' ');
 	ps.want_blank = false;
-	buf_add_char(&code, token.st[0]);
+	buf_add_char(&code, token.s[0]);
 
-	int indent = ind_add(0, code.st, code.len);
+	int indent = ind_add(0, code.s, code.len);
 
 	ps.paren[ps.nparen - 1].indent = indent;
 	ps.paren[ps.nparen - 1].cast = cast_no;
@@ -561,7 +560,7 @@ static void
 process_rparen(void)
 {
 	if (ps.nparen == 0) {
-		diag(0, "Extra '%c'", *token.st);
+		diag(0, "Extra '%c'", *token.s);
 		goto unbalanced;
 	}
 
@@ -579,7 +578,7 @@ process_rparen(void)
 		ps.line_start_nparen = ps.nparen;
 
 unbalanced:
-	buf_add_char(&code, token.st[0]);
+	buf_add_char(&code, token.s[0]);
 
 	if (ps.spaced_expr_psym != psym_0 && ps.nparen == 0) {
 		if (ps.extra_expr_indent == eei_yes)
@@ -598,7 +597,7 @@ static void
 process_rbracket(void)
 {
 	if (ps.nparen == 0) {
-		diag(0, "Extra '%c'", *token.st);
+		diag(0, "Extra '%c'", *token.s);
 		goto unbalanced;
 	}
 	--ps.nparen;
@@ -608,7 +607,7 @@ process_rbracket(void)
 		ps.line_start_nparen = ps.nparen;
 
 unbalanced:
-	buf_add_char(&code, token.st[0]);
+	buf_add_char(&code, token.s[0]);
 }
 
 static bool
@@ -616,8 +615,8 @@ want_blank_before_unary_op(void)
 {
 	if (ps.want_blank)
 		return true;
-	if (token.st[0] == '+' || token.st[0] == '-')
-		return code.len > 0 && code.mem[code.len - 1] == token.st[0];
+	if (token.s[0] == '+' || token.s[0] == '-')
+		return code.len > 0 && code.s[code.len - 1] == token.s[0];
 	return false;
 }
 
@@ -771,7 +770,7 @@ process_lbrace(void)
 
 	if (code.len > 0 && !ps.block_init) {
 		if (!opt.brace_same_line ||
-		    (code.len > 0 && code.mem[code.len - 1] == '}'))
+		    (code.len > 0 && code.s[code.len - 1] == '}'))
 			output_line();
 		else if (ps.in_func_def_params && !ps.init_or_struct) {
 			ps.ind_level_follow = 0;
@@ -886,7 +885,7 @@ process_else(void)
 	ps.in_stmt_or_decl = false;
 
 	if (code.len > 0
-	    && !(opt.cuddle_else && code.mem[code.len - 1] == '}')) {
+	    && !(opt.cuddle_else && code.s[code.len - 1] == '}')) {
 		if (opt.verbose)
 			diag(0, "Line broken");
 		output_line();
@@ -940,9 +939,9 @@ process_ident(lexer_symbol lsym)
 		} else if (!ps.block_init && !ps.decl_indent_done &&
 		    ps.line_start_nparen == 0) {
 			if (opt.decl_indent == 0
-			    && code.len > 0 && code.mem[code.len - 1] == '}')
+			    && code.len > 0 && code.s[code.len - 1] == '}')
 				ps.decl_ind =
-				    ind_add(0, code.st, code.len) + 1;
+				    ind_add(0, code.s, code.len) + 1;
 			code_add_decl_indent(ps.decl_ind, ps.tabs_to_var);
 			ps.decl_indent_done = true;
 			ps.want_blank = false;
@@ -960,7 +959,7 @@ process_ident(lexer_symbol lsym)
 static void
 process_period(void)
 {
-	if (code.len > 0 && code.mem[code.len - 1] == ',')
+	if (code.len > 0 && code.s[code.len - 1] == ',')
 		buf_add_char(&code, ' ');
 	buf_add_char(&code, '.');
 	ps.want_blank = false;
@@ -986,7 +985,7 @@ process_comma(void)
 			ps.block_init = false;
 		int typical_varname_length = 8;
 		if (ps.break_after_comma && (opt.break_after_comma ||
-		    ind_add(compute_code_indent(), code.st, code.len)
+		    ind_add(compute_code_indent(), code.s, code.len)
 		    >= opt.max_line_length - typical_varname_length))
 			ps.force_nl = true;
 	}
@@ -1002,20 +1001,20 @@ read_preprocessing_line(void)
 
 	buf_add_char(&lab, '#');
 
-	while (ch_isblank(inp.st[0]))
-		buf_add_char(&lab, *inp.st++);
+	while (ch_isblank(inp_p[0]))
+		buf_add_char(&lab, *inp_p++);
 
-	while (inp.st[0] != '\n' || (state == COMM && !had_eof)) {
+	while (inp_p[0] != '\n' || (state == COMM && !had_eof)) {
 		buf_add_char(&lab, inp_next());
-		switch (lab.mem[lab.len - 1]) {
+		switch (lab.s[lab.len - 1]) {
 		case '\\':
 			if (state != COMM)
 				buf_add_char(&lab, inp_next());
 			break;
 		case '/':
-			if (inp.st[0] == '*' && state == PLAIN) {
+			if (inp_p[0] == '*' && state == PLAIN) {
 				state = COMM;
-				buf_add_char(&lab, *inp.st++);
+				buf_add_char(&lab, *inp_p++);
 			}
 			break;
 		case '"':
@@ -1031,15 +1030,15 @@ read_preprocessing_line(void)
 				state = CHR;
 			break;
 		case '*':
-			if (inp.st[0] == '/' && state == COMM) {
+			if (inp_p[0] == '/' && state == COMM) {
 				state = PLAIN;
-				buf_add_char(&lab, *inp.st++);
+				buf_add_char(&lab, *inp_p++);
 			}
 			break;
 		}
 	}
 
-	while (lab.len > 0 && ch_isblank(lab.mem[lab.len - 1]))
+	while (lab.len > 0 && ch_isblank(lab.s[lab.len - 1]))
 		lab.len--;
 }
 
@@ -1051,8 +1050,8 @@ process_preprocessing(void)
 
 	read_preprocessing_line();
 
-	const char *end = lab.mem + lab.len;
-	const char *dir = lab.st + 1;
+	const char *end = lab.s + lab.len;
+	const char *dir = lab.s + 1;
 	while (dir < end && ch_isblank(*dir))
 		dir++;
 	size_t dir_len = 0;

Index: src/usr.bin/indent/indent.h
diff -u src/usr.bin/indent/indent.h:1.170 src/usr.bin/indent/indent.h:1.171
--- src/usr.bin/indent/indent.h:1.170	Sun Jun  4 17:54:11 2023
+++ src/usr.bin/indent/indent.h	Sun Jun  4 20:51:19 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.h,v 1.170 2023/06/04 17:54:11 rillig Exp $	*/
+/*	$NetBSD: indent.h,v 1.171 2023/06/04 20:51:19 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -139,9 +139,8 @@ typedef enum parser_symbol {
 
 /* A range of characters, not null-terminated. */
 struct buffer {
-	const char *st;		/* start of the usable text */
-	char *mem;
-	size_t len;		/* length of the usable text, from 'mem' */
+	char *s;
+	size_t len;
 	size_t cap;
 };
 
@@ -150,12 +149,13 @@ extern FILE *output;
 
 /*
  * The current line from the input file, used by the lexer to generate tokens.
- * To read from the line, start at inp.st and continue up to and including the
+ * To read from the line, start at inp_p and continue up to and including the
  * next '\n'. To read beyond the '\n', call inp_skip or inp_next, which will
  * make the next line available, invalidating any pointers into the previous
  * line.
  */
 extern struct buffer inp;
+extern const char *inp_p;
 
 extern struct buffer token;	/* the current token to be processed, is
 				 * typically copied to the buffer 'code', or in

Index: src/usr.bin/indent/io.c
diff -u src/usr.bin/indent/io.c:1.192 src/usr.bin/indent/io.c:1.193
--- src/usr.bin/indent/io.c:1.192	Sun Jun  4 18:58:30 2023
+++ src/usr.bin/indent/io.c	Sun Jun  4 20:51:19 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: io.c,v 1.192 2023/06/04 18:58:30 rillig Exp $	*/
+/*	$NetBSD: io.c,v 1.193 2023/06/04 20:51:19 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -38,13 +38,14 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: io.c,v 1.192 2023/06/04 18:58:30 rillig Exp $");
+__RCSID("$NetBSD: io.c,v 1.193 2023/06/04 20:51:19 rillig Exp $");
 
 #include <stdio.h>
 
 #include "indent.h"
 
 struct buffer inp;
+const char *inp_p;
 struct output_state out;
 static unsigned wrote_newlines = 2;	/* 0 in the middle of a line, 1 after a
 					 * single '\n', > 1 means there were (n
@@ -55,15 +56,15 @@ static int paren_indent;
 void
 inp_skip(void)
 {
-	inp.st++;
-	if ((size_t)(inp.st - inp.mem) >= inp.len)
+	inp_p++;
+	if ((size_t)(inp_p - inp.s) >= inp.len)
 		inp_read_line();
 }
 
 char
 inp_next(void)
 {
-	char ch = inp.st[0];
+	char ch = inp_p[0];
 	inp_skip();
 	return ch;
 }
@@ -71,7 +72,6 @@ inp_next(void)
 static void
 inp_read_next_line(FILE *f)
 {
-	inp.st = inp.mem;
 	inp.len = 0;
 
 	for (;;) {
@@ -90,6 +90,7 @@ inp_read_next_line(FILE *f)
 		if (ch == '\n')
 			break;
 	}
+	inp_p = inp.s;
 }
 
 static void
@@ -175,12 +176,12 @@ static int
 output_line_label(void)
 {
 
-	while (lab.len > 0 && ch_isblank(lab.mem[lab.len - 1]))
+	while (lab.len > 0 && ch_isblank(lab.s[lab.len - 1]))
 		lab.len--;
 
 	int ind = output_indent(0, compute_label_indent());
-	output_range(lab.st, lab.len);
-	return ind_add(ind, lab.st, lab.len);
+	output_range(lab.s, lab.len);
+	return ind_add(ind, lab.s, lab.len);
 }
 
 static int
@@ -202,15 +203,15 @@ output_line_code(int ind)
 	int code_ind = output_indent(ind, target_ind);
 	if (ind > 0 && code_ind == ind)
 		output_range(" ", 1), code_ind++;
-	output_range(code.st, code.len);
-	return ind_add(code_ind, code.st, code.len);
+	output_range(code.s, code.len);
+	return ind_add(code_ind, code.s, code.len);
 }
 
 static void
 output_line_comment(int ind)
 {
 	int target_ind = ps.com_ind;
-	const char *p = com.st;
+	const char *p = com.s;
 
 	target_ind += ps.comment_delta;
 
@@ -235,11 +236,11 @@ output_line_comment(int ind)
 		ind = 0;
 	}
 
-	while (com.mem + com.len > p && ch_isspace(com.mem[com.len - 1]))
+	while (com.s + com.len > p && ch_isspace(com.s[com.len - 1]))
 		com.len--;
 
 	(void)output_indent(ind, target_ind);
-	output_range(p, com.len - (size_t)(p - com.mem));
+	output_range(p, com.len - (size_t)(p - com.s));
 
 	ps.comment_delta = ps.n_comment_delta;
 }
@@ -296,7 +297,7 @@ output_line(void)
 
 	if (indent_enabled == indent_last_off_line) {
 		indent_enabled = indent_on;
-		output_range(out.indent_off_text.st, out.indent_off_text.len);
+		output_range(out.indent_off_text.s, out.indent_off_text.len);
 		out.indent_off_text.len = 0;
 	}
 
@@ -329,11 +330,11 @@ static int
 compute_code_indent_lineup(int base_ind)
 {
 	int ind = paren_indent;
-	int overflow = ind_add(ind, code.st, code.len) - opt.max_line_length;
+	int overflow = ind_add(ind, code.s, code.len) - opt.max_line_length;
 	if (overflow < 0)
 		return ind;
 
-	if (ind_add(base_ind, code.st, code.len) < opt.max_line_length) {
+	if (ind_add(base_ind, code.s, code.len) < opt.max_line_length) {
 		ind -= overflow + 2;
 		if (ind > base_ind)
 			return ind;
@@ -377,7 +378,7 @@ compute_label_indent(void)
 {
 	if (out.line_kind == lk_case_or_default)
 		return (int)(case_ind * (float)opt.indent_size);
-	if (lab.st[0] == '#')
+	if (lab.s[0] == '#')
 		return 0;
 	return opt.indent_size * (ps.ind_level - 2);
 }
@@ -387,6 +388,6 @@ inp_read_line(void)
 {
 	if (indent_enabled == indent_on)
 		out.indent_off_text.len = 0;
-	buf_add_chars(&out.indent_off_text, inp.mem, inp.len);
+	buf_add_chars(&out.indent_off_text, inp.s, inp.len);
 	inp_read_next_line(input);
 }

Index: src/usr.bin/indent/lexi.c
diff -u src/usr.bin/indent/lexi.c:1.211 src/usr.bin/indent/lexi.c:1.212
--- src/usr.bin/indent/lexi.c:1.211	Sun Jun  4 14:20:00 2023
+++ src/usr.bin/indent/lexi.c	Sun Jun  4 20:51:19 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: lexi.c,v 1.211 2023/06/04 14:20:00 rillig Exp $	*/
+/*	$NetBSD: lexi.c,v 1.212 2023/06/04 20:51:19 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: lexi.c,v 1.211 2023/06/04 14:20:00 rillig Exp $");
+__RCSID("$NetBSD: lexi.c,v 1.212 2023/06/04 20:51:19 rillig Exp $");
 
 #include <stdlib.h>
 #include <string.h>
@@ -176,9 +176,9 @@ static void
 lex_number(void)
 {
 	for (unsigned char s = 'A'; s != 'f' && s != 'i' && s != 'u';) {
-		unsigned char ch = (unsigned char)inp.st[0];
-		if (ch == '\\' && inp.st[1] == '\n') {
-			inp.st++;
+		unsigned char ch = (unsigned char)inp_p[0];
+		if (ch == '\\' && inp_p[1] == '\n') {
+			inp_p++;
 			inp_skip();
 			line_no++;
 			continue;
@@ -217,10 +217,10 @@ static void
 lex_word(void)
 {
 	for (;;) {
-		if (is_identifier_part(inp.st[0]))
-			token_add_char(*inp.st++);
-		else if (inp.st[0] == '\\' && inp.st[1] == '\n') {
-			inp.st++;
+		if (is_identifier_part(inp_p[0]))
+			token_add_char(*inp_p++);
+		else if (inp_p[0] == '\\' && inp_p[1] == '\n') {
+			inp_p++;
 			inp_skip();
 			line_no++;
 		} else
@@ -231,18 +231,18 @@ lex_word(void)
 static void
 lex_char_or_string(void)
 {
-	for (char delim = token.mem[token.len - 1];;) {
-		if (inp.st[0] == '\n') {
+	for (char delim = token.s[token.len - 1];;) {
+		if (inp_p[0] == '\n') {
 			diag(1, "Unterminated literal");
 			return;
 		}
 
-		token_add_char(*inp.st++);
-		if (token.mem[token.len - 1] == delim)
+		token_add_char(*inp_p++);
+		if (token.s[token.len - 1] == delim)
 			return;
 
-		if (token.mem[token.len - 1] == '\\') {
-			if (inp.st[0] == '\n')
+		if (token.s[token.len - 1] == '\\') {
+			if (inp_p[0] == '\n')
 				++line_no;
 			token_add_char(inp_next());
 		}
@@ -259,10 +259,10 @@ probably_typename(void)
 		return false;
 	if (ps.in_stmt_or_decl)	/* XXX: this condition looks incorrect */
 		return false;
-	if (inp.st[0] == '*' && inp.st[1] != '=')
+	if (inp_p[0] == '*' && inp_p[1] != '=')
 		goto maybe;
 	/* XXX: is_identifier_start */
-	if (ch_isalpha(inp.st[0]))
+	if (ch_isalpha(inp_p[0]))
 		goto maybe;
 	return false;
 maybe:
@@ -295,10 +295,10 @@ static bool
 is_typename(void)
 {
 	if (opt.auto_typedefs &&
-	    token.len >= 2 && memcmp(token.mem + token.len - 2, "_t", 2) == 0)
+	    token.len >= 2 && memcmp(token.s + token.len - 2, "_t", 2) == 0)
 		return true;
 
-	return bsearch_typenames(token.st) >= 0;
+	return bsearch_typenames(token.s) >= 0;
 }
 
 static int
@@ -315,7 +315,7 @@ static bool
 probably_looking_at_definition(void)
 {
 	int paren_level = 0;
-	for (const char *p = inp.st; *p != '\n'; p++) {
+	for (const char *p = inp_p; *p != '\n'; p++) {
 		if (*p == '(')
 			paren_level++;
 		if (*p == ')' && --paren_level == 0) {
@@ -353,15 +353,15 @@ probably_looking_at_definition(void)
 static lexer_symbol
 lexi_alnum(void)
 {
-	if (ch_isdigit(inp.st[0]) ||
-	    (inp.st[0] == '.' && ch_isdigit(inp.st[1]))) {
+	if (ch_isdigit(inp_p[0]) ||
+	    (inp_p[0] == '.' && ch_isdigit(inp_p[1]))) {
 		lex_number();
-	} else if (is_identifier_start(inp.st[0])) {
+	} else if (is_identifier_start(inp_p[0])) {
 		lex_word();
 
-		if (token.len == 1 && token.st[0] == 'L' &&
-		    (inp.st[0] == '"' || inp.st[0] == '\'')) {
-			token_add_char(*inp.st++);
+		if (token.len == 1 && token.s[0] == 'L' &&
+		    (inp_p[0] == '"' || inp_p[0] == '\'')) {
+			token_add_char(*inp_p++);
 			lex_char_or_string();
 			ps.next_unary = false;
 			return lsym_word;
@@ -369,8 +369,8 @@ lexi_alnum(void)
 	} else
 		return lsym_eof;	/* just as a placeholder */
 
-	while (ch_isblank(inp.st[0]))
-		inp.st++;
+	while (ch_isblank(inp_p[0]))
+		inp_p++;
 
 	ps.next_unary = ps.prev_lsym == lsym_tag
 	    || ps.prev_lsym == lsym_typedef;
@@ -380,7 +380,7 @@ lexi_alnum(void)
 
 	token_add_char('\0');
 	token.len--;
-	const struct keyword *kw = bsearch(token.st, keywords,
+	const struct keyword *kw = bsearch(token.s, keywords,
 	    array_length(keywords), sizeof(keywords[0]), cmp_keyword_by_name);
 	lexer_symbol lsym = lsym_word;
 	if (kw != NULL) {
@@ -411,7 +411,7 @@ found_typename:
 		}
 	}
 
-	if (inp.st[0] == '(' && ps.tos <= 1 && ps.ind_level == 0 &&
+	if (inp_p[0] == '(' && ps.tos <= 1 && ps.ind_level == 0 &&
 	    !ps.in_func_def_params && !ps.block_init) {
 
 		if (ps.nparen == 0 && probably_looking_at_definition()) {
@@ -446,7 +446,7 @@ is_asterisk_unary(void)
 static bool
 probably_in_function_definition(void)
 {
-	for (const char *tp = inp.st; *tp != '\n';) {
+	for (const char *tp = inp_p; *tp != '\n';) {
 		if (ch_isspace(*tp))
 			tp++;
 		else if (is_identifier_start(*tp)) {
@@ -462,8 +462,8 @@ probably_in_function_definition(void)
 static void
 lex_asterisk_unary(void)
 {
-	while (inp.st[0] == '*' || ch_isspace(inp.st[0])) {
-		if (inp.st[0] == '*')
+	while (inp_p[0] == '*' || ch_isspace(inp_p[0])) {
+		if (inp_p[0] == '*')
 			token_add_char('*');
 		inp_skip();
 	}
@@ -493,7 +493,7 @@ skip_string(const char **pp, const char 
 static void
 lex_indent_comment(void)
 {
-	const char *p = inp.mem;
+	const char *p = inp.s;
 
 	skip_blank(&p);
 	if (!skip_string(&p, "/*"))
@@ -530,11 +530,11 @@ lexi(void)
 	ps.next_col_1 = false;
 
 	for (;;) {
-		if (ch_isblank(inp.st[0])) {
+		if (ch_isblank(inp_p[0])) {
 			ps.curr_col_1 = false;
-			inp.st++;
-		} else if (inp.st[0] == '\\' && inp.st[1] == '\n') {
-			inp.st++;
+			inp_p++;
+		} else if (inp_p[0] == '\\' && inp_p[1] == '\n') {
+			inp_p++;
 			inp_skip();
 			line_no++;
 		} else
@@ -552,7 +552,7 @@ lexi(void)
 	lexer_symbol lsym;
 	bool next_unary;
 
-	switch (token.mem[token.len - 1]) {
+	switch (token.s[token.len - 1]) {
 
 	/* INDENT OFF */
 	case '(':	lsym = lsym_lparen;	next_unary = true;	break;
@@ -601,8 +601,8 @@ lexi(void)
 		next_unary = true;
 
 		/* '++' or '--' */
-		if (inp.st[0] == token.mem[token.len - 1]) {
-			token_add_char(*inp.st++);
+		if (inp_p[0] == token.s[token.len - 1]) {
+			token_add_char(*inp_p++);
 			if (ps.prev_lsym == lsym_word ||
 			    ps.prev_lsym == lsym_rparen ||
 			    ps.prev_lsym == lsym_rbracket) {
@@ -611,11 +611,11 @@ lexi(void)
 				next_unary = false;
 			}
 
-		} else if (inp.st[0] == '=') {	/* '+=' or '-=' */
-			token_add_char(*inp.st++);
+		} else if (inp_p[0] == '=') {	/* '+=' or '-=' */
+			token_add_char(*inp_p++);
 
-		} else if (inp.st[0] == '>') {	/* '->' */
-			token_add_char(*inp.st++);
+		} else if (inp_p[0] == '>') {	/* '->' */
+			token_add_char(*inp_p++);
 			lsym = lsym_unary_op;
 			next_unary = false;
 			ps.want_blank = false;
@@ -625,8 +625,8 @@ lexi(void)
 	case '=':
 		if (ps.init_or_struct)
 			ps.block_init = true;
-		if (inp.st[0] == '=')
-			token_add_char(*inp.st++);
+		if (inp_p[0] == '=')
+			token_add_char(*inp_p++);
 		lsym = lsym_binary_op;
 		next_unary = true;
 		break;
@@ -634,10 +634,10 @@ lexi(void)
 	case '>':
 	case '<':
 	case '!':		/* ops like <, <<, <=, !=, etc */
-		if (inp.st[0] == '>' || inp.st[0] == '<' || inp.st[0] == '=')
-			token_add_char(*inp.st++);
-		if (inp.st[0] == '=')
-			token_add_char(*inp.st++);
+		if (inp_p[0] == '>' || inp_p[0] == '<' || inp_p[0] == '=')
+			token_add_char(*inp_p++);
+		if (inp_p[0] == '=')
+			token_add_char(*inp_p++);
 		lsym = ps.next_unary ? lsym_unary_op : lsym_binary_op;
 		next_unary = true;
 		break;
@@ -648,30 +648,30 @@ lexi(void)
 			lsym = lsym_unary_op;
 			next_unary = true;
 		} else {
-			if (inp.st[0] == '=')
-				token_add_char(*inp.st++);
+			if (inp_p[0] == '=')
+				token_add_char(*inp_p++);
 			lsym = lsym_binary_op;
 			next_unary = true;
 		}
 		break;
 
 	default:
-		if (token.mem[token.len - 1] == '/'
-		    && (inp.st[0] == '*' || inp.st[0] == '/')) {
+		if (token.s[token.len - 1] == '/'
+		    && (inp_p[0] == '*' || inp_p[0] == '/')) {
 			enum indent_enabled prev = indent_enabled;
 			lex_indent_comment();
 			if (prev == indent_on && indent_enabled == indent_off)
 				out.indent_off_text.len = 0;
-			token_add_char(*inp.st++);
+			token_add_char(*inp_p++);
 			lsym = lsym_comment;
 			next_unary = ps.next_unary;
 			break;
 		}
 
 		/* things like '||', '&&', '<<=', 'int *****i' */
-		while (inp.st[0] == token.mem[token.len - 1]
-		    || inp.st[0] == '=')
-			token_add_char(*inp.st++);
+		while (inp_p[0] == token.s[token.len - 1]
+		    || inp_p[0] == '=')
+			token_add_char(*inp_p++);
 
 		lsym = ps.next_unary ? lsym_unary_op : lsym_binary_op;
 		next_unary = true;

Index: src/usr.bin/indent/pr_comment.c
diff -u src/usr.bin/indent/pr_comment.c:1.150 src/usr.bin/indent/pr_comment.c:1.151
--- src/usr.bin/indent/pr_comment.c:1.150	Sun Jun  4 20:23:12 2023
+++ src/usr.bin/indent/pr_comment.c	Sun Jun  4 20:51:19 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: pr_comment.c,v 1.150 2023/06/04 20:23:12 rillig Exp $	*/
+/*	$NetBSD: pr_comment.c,v 1.151 2023/06/04 20:51:19 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: pr_comment.c,v 1.150 2023/06/04 20:23:12 rillig Exp $");
+__RCSID("$NetBSD: pr_comment.c,v 1.151 2023/06/04 20:51:19 rillig Exp $");
 
 #include <string.h>
 
@@ -61,7 +61,7 @@ com_add_delim(void)
 static bool
 fits_in_one_line(int com_ind, int max_line_length)
 {
-	for (const char *start = inp.st, *p = start; *p != '\n'; p++) {
+	for (const char *start = inp_p, *p = start; *p != '\n'; p++) {
 		if (p[0] == '*' && p[1] == '/') {
 			int len = ind_add(com_ind + 3,
 			    start, (size_t)(p - start));
@@ -86,13 +86,13 @@ analyze_comment(bool *p_may_wrap, bool *
 		ind = 0;
 
 	} else {
-		if (inp.st[0] == '-' || inp.st[0] == '*' ||
-		    token.mem[token.len - 1] == '/' ||
-		    (inp.st[0] == '\n' && !opt.format_block_comments)) {
+		if (inp_p[0] == '-' || inp_p[0] == '*' ||
+		    token.s[token.len - 1] == '/' ||
+		    (inp_p[0] == '\n' && !opt.format_block_comments)) {
 			may_wrap = false;
 			delim = false;
 		}
-		if (code.len == 0 && inp.st[strspn(inp.st, "*")] == '\n')
+		if (code.len == 0 && inp_p[strspn(inp_p, "*")] == '\n')
 			out.line_kind = lk_block_comment;
 
 		if (com.len > 0)
@@ -107,8 +107,8 @@ analyze_comment(bool *p_may_wrap, bool *
 			delim = false;
 
 			int target_ind = code.len > 0
-			    ? ind_add(compute_code_indent(), code.st, code.len)
-			    : ind_add(compute_label_indent(), lab.st, lab.len);
+			    ? ind_add(compute_code_indent(), code.s, code.len)
+			    : ind_add(compute_label_indent(), lab.s, lab.len);
 
 			ind = ps.decl_on_line || ps.ind_level == 0
 			    ? opt.decl_comment_column - 1
@@ -125,20 +125,20 @@ analyze_comment(bool *p_may_wrap, bool *
 	if (!may_wrap) {
 		/* Find out how much indentation there was originally, because
 		 * that much will have to be ignored by output_line. */
-		size_t len = (size_t)(inp.st - 2 - inp.mem);
-		ps.n_comment_delta = -ind_add(0, inp.mem, len);
+		size_t len = (size_t)(inp_p - 2 - inp.s);
+		ps.n_comment_delta = -ind_add(0, inp.s, len);
 	} else {
 		ps.n_comment_delta = 0;
-		if (!(inp.st[0] == '\t' && !ch_isblank(inp.st[1])))
-			while (ch_isblank(inp.st[0]))
-				inp.st++;
+		if (!(inp_p[0] == '\t' && !ch_isblank(inp_p[1])))
+			while (ch_isblank(inp_p[0]))
+				inp_p++;
 	}
 
 	ps.comment_delta = 0;
 	com_add_char('/');
-	com_add_char(token.mem[token.len - 1]);	/* either '*' or '/' */
+	com_add_char(token.s[token.len - 1]);	/* either '*' or '/' */
 
-	if (may_wrap && !ch_isblank(inp.st[0]))
+	if (may_wrap && !ch_isblank(inp_p[0]))
 		com_add_char(' ');
 
 	if (delim && fits_in_one_line(ind, line_length))
@@ -163,11 +163,10 @@ analyze_comment(bool *p_may_wrap, bool *
 static void
 copy_comment_wrap(int line_length, bool delim)
 {
-	ssize_t last_blank = -1;	/* index of the last blank in com.mem
-					 */
+	ssize_t last_blank = -1;	/* index of the last blank in 'com' */
 
 	for (;;) {
-		switch (inp.st[0]) {
+		switch (inp_p[0]) {
 		case '\n':
 			if (had_eof) {
 				diag(1, "Unterminated comment");
@@ -191,7 +190,7 @@ copy_comment_wrap(int line_length, bool 
 			} else {
 				ps.next_col_1 = true;
 				if (!(com.len > 0
-				    && ch_isblank(com.mem[com.len - 1])))
+				    && ch_isblank(com.s[com.len - 1])))
 					com_add_char(' ');
 				last_blank = (int)com.len - 1;
 			}
@@ -201,21 +200,21 @@ copy_comment_wrap(int line_length, bool 
 			do {	/* flush any blanks and/or tabs at start of
 				 * next line */
 				inp_skip();
-				if (inp.st[0] == '*' && skip_asterisk) {
+				if (inp_p[0] == '*' && skip_asterisk) {
 					skip_asterisk = false;
-					inp.st++;
-					if (inp.st[0] == '/')
+					inp_p++;
+					if (inp_p[0] == '/')
 						goto end_of_comment;
 				}
-			} while (ch_isblank(inp.st[0]));
+			} while (ch_isblank(inp_p[0]));
 
 			break;	/* end of case for newline */
 
 		case '*':
-			inp.st++;
-			if (inp.st[0] == '/') {
+			inp_p++;
+			if (inp_p[0] == '/') {
 		end_of_comment:
-				inp.st++;
+				inp_p++;
 
 				if (delim) {
 					if (com.len > 3)
@@ -225,16 +224,16 @@ copy_comment_wrap(int line_length, bool 
 					com_add_char(' ');
 				} else {
 					size_t len = com.len;
-					while (ch_isblank(com.mem[len - 1]))
+					while (ch_isblank(com.s[len - 1]))
 						len--;
 					int now_len = ind_add(
-					    ps.com_ind, com.st, len);
+					    ps.com_ind, com.s, len);
 					if (now_len + 3 > line_length)
 						output_line();
 				}
 
 				if (!(com.len > 0
-				    && ch_isblank(com.mem[com.len - 1])))
+				    && ch_isblank(com.s[com.len - 1])))
 					com_add_char(' ');
 				com_add_char('*');
 				com_add_char('/');
@@ -246,14 +245,14 @@ copy_comment_wrap(int line_length, bool 
 
 		default:
 			;
-			int now_len = ind_add(ps.com_ind, com.st, com.len);
+			int now_len = ind_add(ps.com_ind, com.s, com.len);
 			for (;;) {
 				char ch = inp_next();
 				if (ch_isblank(ch))
 					last_blank = (ssize_t)com.len;
 				com_add_char(ch);
 				now_len++;
-				if (memchr("*\n\r\b\t", inp.st[0], 6) != NULL)
+				if (memchr("*\n\r\b\t", inp_p[0], 6) != NULL)
 					break;
 				if (now_len >= line_length && last_blank != -1)
 					break;
@@ -263,7 +262,7 @@ copy_comment_wrap(int line_length, bool 
 
 			if (now_len <= line_length)
 				break;
-			if (ch_isspace(com.mem[com.len - 1]))
+			if (ch_isspace(com.s[com.len - 1]))
 				break;
 
 			if (last_blank == -1) {
@@ -273,7 +272,7 @@ copy_comment_wrap(int line_length, bool 
 				break;
 			}
 
-			const char *last_word_s = com.mem + last_blank + 1;
+			const char *last_word_s = com.s + last_blank + 1;
 			size_t last_word_len = com.len
 			- (size_t)(last_blank + 1);
 			com.len = (size_t)last_blank;
@@ -282,8 +281,8 @@ copy_comment_wrap(int line_length, bool 
 
 			/* Assume that output_line and com_add_delim don't
 			 * invalidate the "unused" part of the buffer beyond
-			 * com.mem + com.len. */
-			memmove(com.mem + com.len, last_word_s, last_word_len);
+			 * com.s + com.len. */
+			memmove(com.s + com.len, last_word_s, last_word_len);
 			com.len += last_word_len;
 			last_blank = -1;
 		}
@@ -293,10 +292,10 @@ copy_comment_wrap(int line_length, bool 
 static void
 copy_comment_nowrap(void)
 {
-	char kind = token.mem[token.len - 1];
+	char kind = token.s[token.len - 1];
 
 	for (;;) {
-		if (inp.st[0] == '\n') {
+		if (inp_p[0] == '\n') {
 			if (kind == '/')
 				return;
 
@@ -315,10 +314,10 @@ copy_comment_nowrap(void)
 			continue;
 		}
 
-		com_add_char(*inp.st++);
+		com_add_char(*inp_p++);
 		if (com.len >= 2
-		    && com.mem[com.len - 2] == '*'
-		    && com.mem[com.len - 1] == '/'
+		    && com.s[com.len - 2] == '*'
+		    && com.s[com.len - 1] == '/'
 		    && kind == '*')
 			return;
 	}

Reply via email to