Module Name:    src
Committed By:   rillig
Date:           Sun Dec  3 21:44:43 UTC 2023

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

Log Message:
indent: inline input-related macros

No binary change.


To generate a diff of this commit:
cvs rdiff -u -r1.85 -r1.86 src/usr.bin/indent/args.c
cvs rdiff -u -r1.389 -r1.390 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.206 -r1.207 src/usr.bin/indent/indent.h
cvs rdiff -u -r1.234 -r1.235 src/usr.bin/indent/io.c
cvs rdiff -u -r1.241 -r1.242 src/usr.bin/indent/lexi.c
cvs rdiff -u -r1.172 -r1.173 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/args.c
diff -u src/usr.bin/indent/args.c:1.85 src/usr.bin/indent/args.c:1.86
--- src/usr.bin/indent/args.c:1.85	Thu Jun 15 09:19:06 2023
+++ src/usr.bin/indent/args.c	Sun Dec  3 21:44:42 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: args.c,v 1.85 2023/06/15 09:19:06 rillig Exp $	*/
+/*	$NetBSD: args.c,v 1.86 2023/12/03 21:44:42 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: args.c,v 1.85 2023/06/15 09:19:06 rillig Exp $");
+__RCSID("$NetBSD: args.c,v 1.86 2023/12/03 21:44:42 rillig Exp $");
 
 /* Read options from profile files and from the command line. */
 
@@ -168,8 +168,8 @@ set_special_option(const char *arg, cons
 	}
 
 	if (strcmp(arg, "st") == 0) {
-		if (input == NULL)
-			input = stdin;
+		if (in.f == NULL)
+			in.f = stdin;
 		if (output == NULL)
 			output = stdout;
 		return true;

Index: src/usr.bin/indent/indent.c
diff -u src/usr.bin/indent/indent.c:1.389 src/usr.bin/indent/indent.c:1.390
--- src/usr.bin/indent/indent.c:1.389	Sun Dec  3 21:40:44 2023
+++ src/usr.bin/indent/indent.c	Sun Dec  3 21:44:42 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.389 2023/12/03 21:40:44 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.390 2023/12/03 21:44:42 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: indent.c,v 1.389 2023/12/03 21:40:44 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.390 2023/12/03 21:44:42 rillig Exp $");
 
 #include <sys/param.h>
 #include <err.h>
@@ -156,7 +156,7 @@ diag(int level, const char *msg, ...)
 
 	va_start(ap, msg);
 	fprintf(stderr, "%s: %s:%d: ",
-	    level == 0 ? "warning" : "error", in_name, token_start_line_no);
+	    level == 0 ? "warning" : "error", in_name, in.token_start_line);
 	vfprintf(stderr, msg, ap);
 	fprintf(stderr, "\n");
 	va_end(ap);
@@ -228,17 +228,17 @@ copy_to_bak_file(void)
 	if (bak == NULL)
 		err(1, "%s", backup_name);
 
-	while ((n = fread(buff, 1, sizeof(buff), input)) > 0)
+	while ((n = fread(buff, 1, sizeof(buff), in.f)) > 0)
 		if (fwrite(buff, 1, n, bak) != n)
 			err(1, "%s", backup_name);
-	if (fclose(input) != 0)
+	if (fclose(in.f) != 0)
 		err(1, "%s", in_name);
 	if (fclose(bak) != 0)
 		err(1, "%s", backup_name);
 
 	/* re-open the backup file as the input file */
-	input = fopen(backup_name, "r");
-	if (input == NULL)
+	in.f = fopen(backup_name, "r");
+	if (in.f == NULL)
 		err(1, "%s", backup_name);
 	/* now the original input file will be the output */
 	output = fopen(in_name, "w");
@@ -257,9 +257,9 @@ parse_command_line(int argc, char **argv
 		if (arg[0] == '-') {
 			set_option(arg, "Command line");
 
-		} else if (input == NULL) {
+		} else if (in.f == NULL) {
 			in_name = arg;
-			if ((input = fopen(in_name, "r")) == NULL)
+			if ((in.f = fopen(in_name, "r")) == NULL)
 				err(1, "%s", in_name);
 
 		} else if (output == NULL) {
@@ -273,8 +273,8 @@ parse_command_line(int argc, char **argv
 			errx(1, "too many arguments: %s", arg);
 	}
 
-	if (input == NULL) {
-		input = stdin;
+	if (in.f == NULL) {
+		in.f = stdin;
 		output = stdout;
 	} else if (output == NULL)
 		copy_to_bak_file();
@@ -300,7 +300,7 @@ set_initial_indentation(void)
 	inp_read_line();
 
 	int ind = 0;
-	for (const char *p = inp_p;; p++) {
+	for (const char *p = in.p;; p++) {
 		if (*p == ' ')
 			ind++;
 		else if (*p == '\t')
@@ -417,7 +417,7 @@ read_preprocessing_line(void)
 
 	buf_add_char(&lab, '#');
 
-	while (inp_p[0] != '\n' || (state == COMM && !had_eof)) {
+	while (in.p[0] != '\n' || (state == COMM && !had_eof)) {
 		buf_add_char(&lab, inp_next());
 		switch (lab.s[lab.len - 1]) {
 		case '\\':
@@ -425,9 +425,9 @@ read_preprocessing_line(void)
 				buf_add_char(&lab, inp_next());
 			break;
 		case '/':
-			if (inp_p[0] == '*' && state == PLAIN) {
+			if (in.p[0] == '*' && state == PLAIN) {
 				state = COMM;
-				buf_add_char(&lab, *inp_p++);
+				buf_add_char(&lab, *in.p++);
 			}
 			break;
 		case '"':
@@ -443,9 +443,9 @@ read_preprocessing_line(void)
 				state = CHR;
 			break;
 		case '*':
-			if (inp_p[0] == '/' && state == COMM) {
+			if (in.p[0] == '/' && state == COMM) {
 				state = PLAIN;
-				buf_add_char(&lab, *inp_p++);
+				buf_add_char(&lab, *in.p++);
 			}
 			break;
 		}
@@ -578,7 +578,7 @@ process_newline(void)
 	output_line();
 
 stay_in_line:
-	token_end_line_no++;
+	in.token_end_line++;
 }
 
 static bool
@@ -641,7 +641,7 @@ rparen_is_cast(bool paren_cast)
 		return true;
 	if (ps.spaced_expr_psym != psym_0 && ps.paren.len == 0)
 		return false;
-	return paren_cast || ch_isalpha(inp_p[0]) || inp_p[0] == '{';
+	return paren_cast || ch_isalpha(in.p[0]) || in.p[0] == '{';
 }
 
 static void
@@ -982,7 +982,7 @@ process_word(lexer_symbol lsym)
 		if (lsym == lsym_funcname) {
 			ps.in_decl = false;
 			if (opt.procnames_start_line
-			    && code.len > (*inp_p == ')' ? 1 : 0))
+			    && code.len > (*in.p == ')' ? 1 : 0))
 				output_line();
 			else if (ps.want_blank)
 				buf_add_char(&code, ' ');
@@ -1108,7 +1108,7 @@ indent(void)
 
 		debug_blank_line();
 		debug_printf("line %d: %s",
-		    token_start_line_no, lsym_name[lsym]);
+		    in.token_start_line, lsym_name[lsym]);
 		debug_print_buf("token", &token);
 		debug_buffers();
 		debug_blank_line();

Index: src/usr.bin/indent/indent.h
diff -u src/usr.bin/indent/indent.h:1.206 src/usr.bin/indent/indent.h:1.207
--- src/usr.bin/indent/indent.h:1.206	Sun Dec  3 21:40:44 2023
+++ src/usr.bin/indent/indent.h	Sun Dec  3 21:44:42 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.h,v 1.206 2023/12/03 21:40:44 rillig Exp $	*/
+/*	$NetBSD: indent.h,v 1.207 2023/12/03 21:44:42 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -161,12 +161,6 @@ extern struct input_state {
 	int token_end_line;
 } in;
 
-#define input in.f
-#define inp in.line
-#define inp_p in.p
-#define token_start_line_no in.token_start_line
-#define token_end_line_no in.token_end_line
-
 extern FILE *output;
 
 extern struct buffer token;	/* the current token to be processed, is

Index: src/usr.bin/indent/io.c
diff -u src/usr.bin/indent/io.c:1.234 src/usr.bin/indent/io.c:1.235
--- src/usr.bin/indent/io.c:1.234	Sun Dec  3 21:40:44 2023
+++ src/usr.bin/indent/io.c	Sun Dec  3 21:44:42 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: io.c,v 1.234 2023/12/03 21:40:44 rillig Exp $	*/
+/*	$NetBSD: io.c,v 1.235 2023/12/03 21:44:42 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: io.c,v 1.234 2023/12/03 21:40:44 rillig Exp $");
+__RCSID("$NetBSD: io.c,v 1.235 2023/12/03 21:44:42 rillig Exp $");
 
 #include <stdio.h>
 
@@ -62,26 +62,26 @@ static int paren_indent;	/* total indent
 static void
 inp_read_next_line(void)
 {
-	buf_clear(&inp);
+	buf_clear(&in.line);
 
 	for (;;) {
-		int ch = getc(input);
+		int ch = getc(in.f);
 		if (ch == EOF) {
 			if (indent_enabled == indent_on) {
-				buf_add_char(&inp, ' ');
-				buf_add_char(&inp, '\n');
+				buf_add_char(&in.line, ' ');
+				buf_add_char(&in.line, '\n');
 			}
 			had_eof = true;
 			break;
 		}
 
 		if (ch != '\0')
-			buf_add_char(&inp, (char)ch);
+			buf_add_char(&in.line, (char)ch);
 		if (ch == '\n')
 			break;
 	}
-	buf_terminate(&inp);
-	inp_p = inp.s;
+	buf_terminate(&in.line);
+	in.p = in.line.s;
 }
 
 void
@@ -89,22 +89,22 @@ inp_read_line(void)
 {
 	if (indent_enabled == indent_on)
 		buf_clear(&out.indent_off_text);
-	buf_add_chars(&out.indent_off_text, inp.s, inp.len);
+	buf_add_chars(&out.indent_off_text, in.line.s, in.line.len);
 	inp_read_next_line();
 }
 
 void
 inp_skip(void)
 {
-	inp_p++;
-	if ((size_t)(inp_p - inp.s) >= inp.len)
+	in.p++;
+	if ((size_t)(in.p - in.line.s) >= in.line.len)
 		inp_read_line();
 }
 
 char
 inp_next(void)
 {
-	char ch = inp_p[0];
+	char ch = in.p[0];
 	inp_skip();
 	return ch;
 }

Index: src/usr.bin/indent/lexi.c
diff -u src/usr.bin/indent/lexi.c:1.241 src/usr.bin/indent/lexi.c:1.242
--- src/usr.bin/indent/lexi.c:1.241	Sun Dec  3 21:03:58 2023
+++ src/usr.bin/indent/lexi.c	Sun Dec  3 21:44:42 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: lexi.c,v 1.241 2023/12/03 21:03:58 rillig Exp $	*/
+/*	$NetBSD: lexi.c,v 1.242 2023/12/03 21:44:42 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: lexi.c,v 1.241 2023/12/03 21:03:58 rillig Exp $");
+__RCSID("$NetBSD: lexi.c,v 1.242 2023/12/03 21:44:42 rillig Exp $");
 
 #include <stdlib.h>
 #include <string.h>
@@ -185,10 +185,10 @@ token_add_char(char ch)
 static bool
 skip_line_continuation(void)
 {
-	if (inp_p[0] == '\\' && inp_p[1] == '\n') {
-		inp_p++;
+	if (in.p[0] == '\\' && in.p[1] == '\n') {
+		in.p++;
 		inp_skip();
-		token_end_line_no++;
+		in.token_end_line++;
 		return true;
 	}
 	return false;
@@ -198,7 +198,7 @@ static void
 lex_number(void)
 {
 	for (unsigned char s = 'A'; s != 'f' && s != 'i' && s != 'u';) {
-		unsigned char ch = (unsigned char)*inp_p;
+		unsigned char ch = (unsigned char)*in.p;
 		if (skip_line_continuation())
 			continue;
 		if (ch >= array_length(lex_number_row)
@@ -221,8 +221,8 @@ static void
 lex_word(void)
 {
 	for (;;) {
-		if (is_identifier_part(*inp_p))
-			token_add_char(*inp_p++);
+		if (is_identifier_part(*in.p))
+			token_add_char(*in.p++);
 		else if (skip_line_continuation())
 			continue;
 		else
@@ -234,18 +234,18 @@ static void
 lex_char_or_string(void)
 {
 	for (char delim = token.s[token.len - 1];;) {
-		if (*inp_p == '\n') {
+		if (*in.p == '\n') {
 			diag(1, "Unterminated literal");
 			return;
 		}
 
-		token_add_char(*inp_p++);
+		token_add_char(*in.p++);
 		if (token.s[token.len - 1] == delim)
 			return;
 
 		if (token.s[token.len - 1] == '\\') {
-			if (*inp_p == '\n')
-				token_end_line_no++;
+			if (*in.p == '\n')
+				in.token_end_line++;
 			token_add_char(inp_next());
 		}
 	}
@@ -264,10 +264,10 @@ probably_typename(void)
 	if (ps.prev_lsym == lsym_semicolon
 	    || ps.prev_lsym == lsym_lbrace
 	    || ps.prev_lsym == lsym_rbrace) {
-		if (inp_p[0] == '*' && inp_p[1] != '=')
+		if (in.p[0] == '*' && in.p[1] != '=')
 			return true;
 		/* XXX: is_identifier_start */
-		if (ch_isalpha(inp_p[0]))
+		if (ch_isalpha(in.p[0]))
 			return true;
 	}
 	return false;
@@ -381,15 +381,15 @@ probably_function_definition(const char 
 static lexer_symbol
 lexi_alnum(void)
 {
-	if (ch_isdigit(inp_p[0]) ||
-	    (inp_p[0] == '.' && ch_isdigit(inp_p[1]))) {
+	if (ch_isdigit(in.p[0]) ||
+	    (in.p[0] == '.' && ch_isdigit(in.p[1]))) {
 		lex_number();
-	} else if (is_identifier_start(inp_p[0])) {
+	} else if (is_identifier_start(in.p[0])) {
 		lex_word();
 
 		if (token.len == 1 && token.s[0] == 'L' &&
-		    (inp_p[0] == '"' || inp_p[0] == '\'')) {
-			token_add_char(*inp_p++);
+		    (in.p[0] == '"' || in.p[0] == '\'')) {
+			token_add_char(*in.p++);
 			lex_char_or_string();
 			ps.next_unary = false;
 			return lsym_word;
@@ -397,18 +397,18 @@ lexi_alnum(void)
 	} else
 		return lsym_eof;	/* just as a placeholder */
 
-	while (ch_isblank(*inp_p))
-		inp_p++;
+	while (ch_isblank(*in.p))
+		in.p++;
 
 	ps.next_unary = ps.prev_lsym == lsym_tag
 	    || ps.prev_lsym == lsym_typedef
-	    || (ps.prev_lsym == lsym_modifier && *inp_p == '*');
+	    || (ps.prev_lsym == lsym_modifier && *in.p == '*');
 
 	if (ps.prev_lsym == lsym_tag && ps.paren.len == 0)
 		return lsym_type;
 	if (ps.spaced_expr_psym == psym_for_exprs
 	    && ps.prev_lsym == lsym_lparen && ps.paren.len == 1
-	    && *inp_p == '*') {
+	    && *in.p == '*') {
 		ps.next_unary = true;
 		return lsym_type;
 	}
@@ -439,13 +439,13 @@ found_typename:
 		}
 	}
 
-	const char *p = inp_p;
+	const char *p = in.p;
 	if (*p == ')')
 		p++;
 	if (*p == '(' && ps.psyms.len < 3 && ps.ind_level == 0 &&
 	    !ps.in_func_def_params && !ps.in_init) {
 
-		bool maybe_function_definition = *inp_p == ')'
+		bool maybe_function_definition = *in.p == ')'
 		    ? ps.paren.len == 1 && ps.prev_lsym != lsym_unary_op
 		    : ps.paren.len == 0;
 		if (maybe_function_definition
@@ -467,7 +467,7 @@ found_typename:
 static void
 check_parenthesized_function_definition(void)
 {
-	const char *p = inp_p;
+	const char *p = in.p;
 	while (ch_isblank(*p))
 		p++;
 	if (is_identifier_start(*p))
@@ -487,7 +487,7 @@ check_parenthesized_function_definition(
 static bool
 is_asterisk_unary(void)
 {
-	const char *p = inp_p;
+	const char *p = in.p;
 	while (*p == '*' || ch_isblank(*p))
 		p++;
 	if (*p == ')')
@@ -504,7 +504,7 @@ is_asterisk_unary(void)
 static bool
 probably_in_function_definition(void)
 {
-	for (const char *p = inp_p; *p != '\n';) {
+	for (const char *p = in.p; *p != '\n';) {
 		if (ch_isspace(*p))
 			p++;
 		else if (is_identifier_start(*p)) {
@@ -520,11 +520,11 @@ probably_in_function_definition(void)
 static void
 lex_asterisk_unary(void)
 {
-	while (*inp_p == '*' || ch_isspace(*inp_p)) {
-		if (*inp_p == '*')
+	while (*in.p == '*' || ch_isspace(*in.p)) {
+		if (*in.p == '*')
 			token_add_char('*');
-		if (*inp_p == '\n')
-			token_end_line_no++;
+		if (*in.p == '\n')
+			in.token_end_line++;
 		inp_skip();
 	}
 
@@ -548,7 +548,7 @@ skip(const char **pp, const char *s)
 static void
 lex_indent_comment(void)
 {
-	const char *p = inp.s;
+	const char *p = in.line.s;
 	if (skip(&p, "/*") && skip(&p, "INDENT")) {
 		enum indent_enabled enabled;
 		if (skip(&p, "ON") || *p == '*')
@@ -572,14 +572,14 @@ lexi(void)
 	buf_clear(&token);
 
 	for (;;) {
-		if (ch_isblank(*inp_p))
-			inp_p++;
+		if (ch_isblank(*in.p))
+			in.p++;
 		else if (skip_line_continuation())
 			continue;
 		else
 			break;
 	}
-	token_start_line_no = token_end_line_no;
+	in.token_start_line = in.token_end_line;
 
 	lexer_symbol alnum_lsym = lexi_alnum();
 	if (alnum_lsym != lsym_eof)
@@ -618,7 +618,7 @@ lexi(void)
 	/* INDENT ON */
 
 	case '(':
-		if (inp_p == inp.s + 1)
+		if (in.p == in.line.s + 1)
 			check_parenthesized_function_definition();
 		lsym = lsym_lparen;
 		next_unary = true;
@@ -630,8 +630,8 @@ lexi(void)
 		next_unary = true;
 
 		/* '++' or '--' */
-		if (*inp_p == token.s[token.len - 1]) {
-			token_add_char(*inp_p++);
+		if (*in.p == token.s[token.len - 1]) {
+			token_add_char(*in.p++);
 			if (ps.prev_lsym == lsym_word ||
 			    ps.prev_lsym == lsym_rparen ||
 			    ps.prev_lsym == lsym_rbracket) {
@@ -640,11 +640,11 @@ lexi(void)
 				next_unary = false;
 			}
 
-		} else if (*inp_p == '=') {	/* '+=' or '-=' */
-			token_add_char(*inp_p++);
+		} else if (*in.p == '=') {	/* '+=' or '-=' */
+			token_add_char(*in.p++);
 
-		} else if (*inp_p == '>') {	/* '->' */
-			token_add_char(*inp_p++);
+		} else if (*in.p == '>') {	/* '->' */
+			token_add_char(*in.p++);
 			lsym = lsym_unary_op;
 			next_unary = false;
 			ps.want_blank = false;
@@ -659,8 +659,8 @@ lexi(void)
 		break;
 
 	case '*':
-		if (*inp_p == '=') {
-			token_add_char(*inp_p++);
+		if (*in.p == '=') {
+			token_add_char(*in.p++);
 			lsym = lsym_binary_op;
 		} else if (is_asterisk_unary()) {
 			lex_asterisk_unary();
@@ -673,8 +673,8 @@ lexi(void)
 	case '=':
 		if (ps.in_var_decl)
 			ps.in_init = true;
-		if (*inp_p == '=')
-			token_add_char(*inp_p++);
+		if (*in.p == '=')
+			token_add_char(*in.p++);
 		lsym = lsym_binary_op;
 		next_unary = true;
 		break;
@@ -682,10 +682,10 @@ lexi(void)
 	case '>':
 	case '<':
 	case '!':		/* ops like <, <<, <=, !=, etc. */
-		if (*inp_p == '>' || *inp_p == '<' || *inp_p == '=')
-			token_add_char(*inp_p++);
-		if (*inp_p == '=')
-			token_add_char(*inp_p++);
+		if (*in.p == '>' || *in.p == '<' || *in.p == '=')
+			token_add_char(*in.p++);
+		if (*in.p == '=')
+			token_add_char(*in.p++);
 		lsym = ps.next_unary ? lsym_unary_op : lsym_binary_op;
 		next_unary = true;
 		break;
@@ -699,12 +699,12 @@ lexi(void)
 
 	default:
 		if (token.s[token.len - 1] == '/'
-		    && (*inp_p == '*' || *inp_p == '/')) {
+		    && (*in.p == '*' || *in.p == '/')) {
 			enum indent_enabled prev = indent_enabled;
 			lex_indent_comment();
 			if (prev == indent_on && indent_enabled == indent_off)
 				buf_clear(&out.indent_off_text);
-			token_add_char(*inp_p++);
+			token_add_char(*in.p++);
 			lsym = lsym_comment;
 			next_unary = ps.next_unary;
 			break;
@@ -712,10 +712,10 @@ lexi(void)
 
 		/* punctuation like '%', '&&', '/', '^', '||', '~' */
 		lsym = ps.next_unary ? lsym_unary_op : lsym_binary_op;
-		if (*inp_p == token.s[token.len - 1])
-			token_add_char(*inp_p++), lsym = lsym_binary_op;
-		if (*inp_p == '=')
-			token_add_char(*inp_p++), lsym = lsym_binary_op;
+		if (*in.p == token.s[token.len - 1])
+			token_add_char(*in.p++), lsym = lsym_binary_op;
+		if (*in.p == '=')
+			token_add_char(*in.p++), lsym = lsym_binary_op;
 
 		next_unary = true;
 	}

Index: src/usr.bin/indent/pr_comment.c
diff -u src/usr.bin/indent/pr_comment.c:1.172 src/usr.bin/indent/pr_comment.c:1.173
--- src/usr.bin/indent/pr_comment.c:1.172	Sun Dec  3 21:03:58 2023
+++ src/usr.bin/indent/pr_comment.c	Sun Dec  3 21:44:42 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: pr_comment.c,v 1.172 2023/12/03 21:03:58 rillig Exp $	*/
+/*	$NetBSD: pr_comment.c,v 1.173 2023/12/03 21:44:42 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
  */
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: pr_comment.c,v 1.172 2023/12/03 21:03:58 rillig Exp $");
+__RCSID("$NetBSD: pr_comment.c,v 1.173 2023/12/03 21:44:42 rillig Exp $");
 
 #include <string.h>
 
@@ -60,9 +60,9 @@ com_add_star(void)
 static bool
 fits_in_one_line(int max_line_length)
 {
-	for (const char *start = inp_p, *p = start; *p != '\n'; p++) {
+	for (const char *start = in.p, *p = start; *p != '\n'; p++) {
 		if (p[0] == '*' && p[1] == '/') {
-			while (p - inp_p >= 2
+			while (p - in.p >= 2
 			    && ch_isblank(p[-1])
 			    && ch_isblank(p[-2]))
 				p--;
@@ -78,7 +78,7 @@ fits_in_one_line(int max_line_length)
 static bool
 is_block_comment(void)
 {
-	const char *p = inp_p;
+	const char *p = in.p;
 	while (*p == '*')
 		p++;
 	return *p == '\n';
@@ -92,13 +92,13 @@ analyze_comment(bool *p_may_wrap, bool *
 	int ind;
 	int line_length = opt.max_line_length;
 
-	if (inp_p - inp.s == 2 && !opt.format_col1_comments) {
+	if (in.p - in.line.s == 2 && !opt.format_col1_comments) {
 		may_wrap = false;
 		ind = 0;
 	} else {
-		if (inp_p[0] == '-' || inp_p[0] == '*' ||
+		if (in.p[0] == '-' || in.p[0] == '*' ||
 		    token.s[token.len - 1] == '/' ||
-		    (inp_p[0] == '\n' && !opt.format_block_comments))
+		    (in.p[0] == '\n' && !opt.format_block_comments))
 			may_wrap = false;
 
 		if (com.len > 0)
@@ -111,7 +111,7 @@ analyze_comment(bool *p_may_wrap, bool *
 			if (ind <= 0)
 				ind = opt.format_col1_comments ? 0 : 1;
 			line_length = opt.block_comment_max_line_length;
-			if (may_wrap && inp_p[0] == '\n')
+			if (may_wrap && in.p[0] == '\n')
 				delim = true;
 			if (may_wrap && opt.comment_delimiter_on_blank_line)
 				delim = true;
@@ -133,13 +133,13 @@ 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_p - 2 - inp.s);
-		ps.comment_shift = -ind_add(0, inp.s, len);
+		size_t len = (size_t)(in.p - 2 - in.line.s);
+		ps.comment_shift = -ind_add(0, in.line.s, len);
 	} else {
 		ps.comment_shift = 0;
-		if (!(inp_p[0] == '\t' && !ch_isblank(inp_p[1])))
-			while (ch_isblank(inp_p[0]))
-				inp_p++;
+		if (!(in.p[0] == '\t' && !ch_isblank(in.p[1])))
+			while (ch_isblank(in.p[0]))
+				in.p++;
 	}
 
 	ps.comment_ind = ind;
@@ -155,7 +155,7 @@ copy_comment_start(bool may_wrap, bool *
 	buf_add_chars(&com, token.s, token.len);	// "/*" or "//"
 
 	if (may_wrap) {
-		if (!ch_isblank(inp_p[0]))
+		if (!ch_isblank(in.p[0]))
 			com_add_char(' ');
 
 		if (*delim && fits_in_one_line(line_length))
@@ -177,7 +177,7 @@ copy_comment_wrap_text(int line_length, 
 			*last_blank = (ssize_t)com.len;
 		com_add_char(ch);
 		ind++;
-		if (memchr("*\n\r\t", inp_p[0], 5) != NULL)
+		if (memchr("*\n\r\t", in.p[0], 5) != NULL)
 			break;
 		if (ind >= line_length && *last_blank != -1)
 			break;
@@ -227,18 +227,18 @@ copy_comment_wrap_newline(ssize_t *last_
 			com_add_char(' ');
 		*last_blank = (int)com.len - 1;
 	}
-	token_end_line_no++;
+	in.token_end_line++;
 
 	/* flush any blanks and/or tabs at start of next line */
 	inp_skip();		/* '\n' */
-	while (ch_isblank(inp_p[0]))
-		inp_p++;
-	if (inp_p[0] == '*' && inp_p[1] == '/')
+	while (ch_isblank(in.p[0]))
+		in.p++;
+	if (in.p[0] == '*' && in.p[1] == '/')
 		return false;
-	if (inp_p[0] == '*') {
-		inp_p++;
-		while (ch_isblank(inp_p[0]))
-			inp_p++;
+	if (in.p[0] == '*') {
+		in.p++;
+		while (ch_isblank(in.p[0]))
+			in.p++;
 	}
 
 	return true;
@@ -266,7 +266,7 @@ copy_comment_wrap_finish(int line_length
 		com.len--;
 	buf_terminate(&com);
 
-	inp_p += 2;
+	in.p += 2;
 	if (com.len > 0 && ch_isblank(com.s[com.len - 1]))
 		buf_add_chars(&com, "*/", 2);
 	else
@@ -280,14 +280,14 @@ copy_comment_wrap(int line_length, bool 
 	bool seen_newline = false;
 
 	for (;;) {
-		if (inp_p[0] == '\n') {
+		if (in.p[0] == '\n') {
 			if (had_eof)
 				goto unterminated_comment;
 			if (!copy_comment_wrap_newline(&last_blank,
 				seen_newline))
 				break;
 			seen_newline = true;
-		} else if (inp_p[0] == '*' && inp_p[1] == '/')
+		} else if (in.p[0] == '*' && in.p[1] == '/')
 			break;
 		else {
 			copy_comment_wrap_text(line_length, &last_blank);
@@ -299,7 +299,7 @@ copy_comment_wrap(int line_length, bool 
 	return;
 
 unterminated_comment:
-	token_start_line_no = token_end_line_no;
+	in.token_start_line = in.token_end_line;
 	diag(1, "Unterminated comment");
 	output_line();
 }
@@ -310,30 +310,30 @@ copy_comment_nowrap(void)
 	char kind = token.s[token.len - 1];
 
 	for (;;) {
-		if (inp_p[0] == '\n') {
+		if (in.p[0] == '\n') {
 			if (kind == '/')
 				return;
 
 			if (had_eof) {
-				token_start_line_no = token_end_line_no;
+				in.token_start_line = in.token_end_line;
 				diag(1, "Unterminated comment");
 				output_line();
 				return;
 			}
 
 			output_line();
-			token_end_line_no++;
+			in.token_end_line++;
 			inp_skip();
 			continue;
 		}
 
-		if (kind == '*' && inp_p[0] == '*' && inp_p[1] == '/') {
-			com_add_char(*inp_p++);
-			com_add_char(*inp_p++);
+		if (kind == '*' && in.p[0] == '*' && in.p[1] == '/') {
+			com_add_char(*in.p++);
+			com_add_char(*in.p++);
 			return;
 		}
 
-		com_add_char(*inp_p++);
+		com_add_char(*in.p++);
 	}
 }
 

Reply via email to