Module Name:    src
Committed By:   rillig
Date:           Thu Oct  7 23:15:16 UTC 2021

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

Log Message:
indent: group variables for the input buffer

The input buffer follows the same concept as the intermediate buffers
for label, code, comment and token, so use the same type for it.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.123 -r1.124 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.46 -r1.47 src/usr.bin/indent/indent_globs.h
cvs rdiff -u -r1.78 -r1.79 src/usr.bin/indent/io.c
cvs rdiff -u -r1.77 -r1.78 src/usr.bin/indent/lexi.c
cvs rdiff -u -r1.57 -r1.58 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/indent.c
diff -u src/usr.bin/indent/indent.c:1.123 src/usr.bin/indent/indent.c:1.124
--- src/usr.bin/indent/indent.c:1.123	Thu Oct  7 23:01:32 2021
+++ src/usr.bin/indent/indent.c	Thu Oct  7 23:15:15 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.123 2021/10/07 23:01:32 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.124 2021/10/07 23:15:15 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@ static char sccsid[] = "@(#)indent.c	5.1
 
 #include <sys/cdefs.h>
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: indent.c,v 1.123 2021/10/07 23:01:32 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.124 2021/10/07 23:15:15 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -92,10 +92,7 @@ struct buffer code;
 struct buffer com;
 struct buffer token;
 
-char *in_buffer;
-char *in_buffer_limit;
-char *buf_ptr;
-char *buf_end;
+struct buffer inp;
 
 char sc_buf[sc_size];
 char *save_com;
@@ -176,8 +173,8 @@ search_brace_comment(bool *comment_buffe
 	 * process_comment() will use that to calculate original indentation
 	 * of a boxed comment.
 	 */
-	memcpy(sc_buf, in_buffer, (size_t)(buf_ptr - in_buffer) - 4);
-	save_com = sc_buf + (buf_ptr - in_buffer - 4);
+	memcpy(sc_buf, inp.buf, (size_t)(inp.s - inp.buf) - 4);
+	save_com = sc_buf + (inp.s - inp.buf - 4);
 	save_com[0] = save_com[1] = ' ';
 	sc_end = &save_com[2];
     }
@@ -188,7 +185,7 @@ search_brace_comment(bool *comment_buffe
 
     for (;;) {			/* loop until the end of the comment */
 	*sc_end++ = inbuf_next();
-	if (sc_end[-1] == '*' && *buf_ptr == '/')
+	if (sc_end[-1] == '*' && *inp.s == '/')
 	    break;		/* we are at end of comment */
 	if (sc_end >= &save_com[sc_size]) {	/* check for temp buffer
 						 * overflow */
@@ -216,9 +213,9 @@ search_brace_lbrace(void)
 	 * will be moved into "the else's line", so if there was a newline
 	 * resulting from the "{" before, it must be scanned now and ignored.
 	 */
-	while (isspace((unsigned char)*buf_ptr)) {
+	while (isspace((unsigned char)*inp.s)) {
 	    inbuf_skip();
-	    if (*buf_ptr == '\n')
+	    if (*inp.s == '\n')
 		break;
 	}
 	return true;
@@ -279,14 +276,14 @@ static void
 switch_buffer(void)
 {
     ps.search_brace = false;	/* stop looking for start of stmt */
-    bp_save = buf_ptr;		/* save current input buffer */
-    be_save = buf_end;
-    buf_ptr = save_com;		/* fix so that subsequent calls to lexi will
+    bp_save = inp.s;		/* save current input buffer */
+    be_save = inp.e;
+    inp.s = save_com;		/* fix so that subsequent calls to lexi will
 				 * take tokens out of save_com */
     *sc_end++ = ' ';		/* add trailing blank, just in case */
-    buf_end = sc_end;
+    inp.e = sc_end;
     sc_end = NULL;
-    debug_println("switched buf_ptr to save_com");
+    debug_println("switched inp.s to save_com");
 }
 
 static void
@@ -314,12 +311,12 @@ search_brace_lookahead(token_type *ttype
      * into the buffer so that the later lexi() call will read them.
      */
     if (sc_end != NULL) {
-	while (is_hspace(*buf_ptr)) {
-	    *sc_end++ = *buf_ptr++;
+	while (is_hspace(*inp.s)) {
+	    *sc_end++ = *inp.s++;
 	    if (sc_end >= &save_com[sc_size])
 		errx(1, "input too long");
 	}
-	if (buf_ptr >= buf_end)
+	if (inp.s >= inp.e)
 	    fill_buffer();
     }
 
@@ -443,9 +440,9 @@ main_init_globals(void)
 
     opt.else_if = true;		/* XXX: redundant? */
 
-    in_buffer = xmalloc(10);
-    in_buffer_limit = in_buffer + 8;
-    buf_ptr = buf_end = in_buffer;
+    inp.buf = xmalloc(10);
+    inp.l = inp.buf + 8;
+    inp.s = inp.e = inp.buf;
     line_no = 1;
     had_eof = ps.in_decl = ps.decl_on_line = break_comma = false;
 
@@ -536,7 +533,7 @@ main_prepare_parsing(void)
 
     parse(semicolon);
 
-    char *p = buf_ptr;
+    char *p = inp.s;
     int ind = 0;
 
     for (;;) {
@@ -1124,10 +1121,10 @@ read_preprocessing_line(void)
     int com_start = 0, com_end = 0;
     char quote = '\0';
 
-    while (is_hspace(*buf_ptr))
+    while (is_hspace(*inp.s))
 	inbuf_skip();
 
-    while (*buf_ptr != '\n' || (in_comment && !had_eof)) {
+    while (*inp.s != '\n' || (in_comment && !had_eof)) {
 	buf_reserve(&lab, 2);
 	*lab.e++ = inbuf_next();
 	switch (lab.e[-1]) {
@@ -1136,9 +1133,9 @@ read_preprocessing_line(void)
 		*lab.e++ = inbuf_next();
 	    break;
 	case '/':
-	    if (*buf_ptr == '*' && !in_comment && quote == '\0') {
+	    if (*inp.s == '*' && !in_comment && quote == '\0') {
 		in_comment = true;
-		*lab.e++ = *buf_ptr++;
+		*lab.e++ = *inp.s++;
 		com_start = (int)buf_len(&lab) - 2;
 	    }
 	    break;
@@ -1155,9 +1152,9 @@ read_preprocessing_line(void)
 		quote = '\'';
 	    break;
 	case '*':
-	    if (*buf_ptr == '/' && in_comment) {
+	    if (*inp.s == '/' && in_comment) {
 		in_comment = false;
-		*lab.e++ = *buf_ptr++;
+		*lab.e++ = *inp.s++;
 		com_end = (int)buf_len(&lab);
 	    }
 	    break;
@@ -1184,14 +1181,14 @@ read_preprocessing_line(void)
 	lab.e = lab.s + com_start;
 	while (lab.e > lab.s && is_hspace(lab.e[-1]))
 	    lab.e--;
-	bp_save = buf_ptr;	/* save current input buffer */
-	be_save = buf_end;
-	buf_ptr = save_com;	/* fix so that subsequent calls to lexi will
+	bp_save = inp.s;	/* save current input buffer */
+	be_save = inp.e;
+	inp.s = save_com;	/* fix so that subsequent calls to lexi will
 				 * take tokens out of save_com */
 	*sc_end++ = ' ';	/* add trailing blank, just in case */
-	buf_end = sc_end;
+	inp.e = sc_end;
 	sc_end = NULL;
-	debug_println("switched buf_ptr to save_com");
+	debug_println("switched inp.s to save_com");
     }
     buf_terminate(&lab);
 }

Index: src/usr.bin/indent/indent_globs.h
diff -u src/usr.bin/indent/indent_globs.h:1.46 src/usr.bin/indent/indent_globs.h:1.47
--- src/usr.bin/indent/indent_globs.h:1.46	Thu Oct  7 23:01:32 2021
+++ src/usr.bin/indent/indent_globs.h	Thu Oct  7 23:15:15 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent_globs.h,v 1.46 2021/10/07 23:01:32 rillig Exp $	*/
+/*	$NetBSD: indent_globs.h,v 1.47 2021/10/07 23:15:15 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -60,19 +60,15 @@ extern struct buffer code;		/* code */
 extern struct buffer com;		/* comment */
 extern struct buffer token;		/* the last token scanned */
 
-extern char       *in_buffer;		/* input buffer */
-extern char	   *in_buffer_limit;	/* the end of the input buffer */
-extern char       *buf_ptr;		/* ptr to next character to be taken from
-				 * in_buffer */
-extern char       *buf_end;		/* ptr to first after last char in in_buffer */
+extern struct buffer inp;
 
 extern char        sc_buf[sc_size];	/* input text is saved here when looking for
 				 * the brace after an if, while, etc */
 extern char       *save_com;		/* start of the comment stored in sc_buf */
 
-extern char       *bp_save;		/* saved value of buf_ptr when taking input
+extern char       *bp_save;		/* saved value of inp.s when taking input
 				 * from save_com */
-extern char       *be_save;		/* similarly saved value of buf_end */
+extern char       *be_save;		/* similarly saved value of inp.e */
 
 
 extern struct options {

Index: src/usr.bin/indent/io.c
diff -u src/usr.bin/indent/io.c:1.78 src/usr.bin/indent/io.c:1.79
--- src/usr.bin/indent/io.c:1.78	Thu Oct  7 21:57:21 2021
+++ src/usr.bin/indent/io.c	Thu Oct  7 23:15:15 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: io.c,v 1.78 2021/10/07 21:57:21 rillig Exp $	*/
+/*	$NetBSD: io.c,v 1.79 2021/10/07 23:15:15 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.78 2021/10/07 21:57:21 rillig Exp $");
+__RCSID("$NetBSD: io.c,v 1.79 2021/10/07 23:15:15 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/io.c 334927 2018-06-10 16:44:18Z pstef $");
 #endif
@@ -362,7 +362,7 @@ parse_indent_comment(void)
 {
     bool on_off;
 
-    const char *p = in_buffer;
+    const char *p = inp.buf;
 
     skip_hspace(&p);
     if (!skip_string(&p, "/*"))
@@ -411,22 +411,22 @@ fill_buffer(void)
     FILE *f = input;
 
     if (bp_save != NULL) {	/* there is a partly filled input buffer left */
-	buf_ptr = bp_save;	/* do not read anything, just switch buffers */
-	buf_end = be_save;
+	inp.s = bp_save;	/* do not read anything, just switch buffers */
+	inp.e = be_save;
 	bp_save = be_save = NULL;
-	debug_println("switched buf_ptr back to bp_save");
-	if (buf_ptr < buf_end)
+	debug_println("switched inp.s back to bp_save");
+	if (inp.s < inp.e)
 	    return;		/* only return if there is really something in
 				 * this buffer */
     }
 
-    for (p = in_buffer;;) {
-	if (p >= in_buffer_limit) {
-	    size_t size = (size_t)(in_buffer_limit - in_buffer) * 2 + 10;
-	    size_t offset = (size_t)(p - in_buffer);
-	    in_buffer = xrealloc(in_buffer, size);
-	    p = in_buffer + offset;
-	    in_buffer_limit = in_buffer + size - 2;
+    for (p = inp.buf;;) {
+	if (p >= inp.l) {
+	    size_t size = (size_t)(inp.l - inp.buf) * 2 + 10;
+	    size_t offset = (size_t)(p - inp.buf);
+	    inp.buf = xrealloc(inp.buf, size);
+	    p = inp.buf + offset;
+	    inp.l = inp.buf + size - 2;
 	}
 
 	if ((ch = getc(f)) == EOF) {
@@ -442,18 +442,18 @@ fill_buffer(void)
 	    break;
     }
 
-    buf_ptr = in_buffer;
-    buf_end = p;
+    inp.s = inp.buf;
+    inp.e = p;
 
-    if (p - in_buffer > 2 && p[-2] == '/' && p[-3] == '*') {
-	if (in_buffer[3] == 'I' && strncmp(in_buffer, "/**INDENT**", 11) == 0)
+    if (p - inp.buf > 2 && p[-2] == '/' && p[-3] == '*') {
+	if (inp.buf[3] == 'I' && strncmp(inp.buf, "/**INDENT**", 11) == 0)
 	    fill_buffer();	/* flush indent error message */
 	else
 	    parse_indent_comment();
     }
 
     if (inhibit_formatting) {
-	p = in_buffer;
+	p = inp.buf;
 	do {
 	    output_char(*p);
 	} while (*p++ != '\n');

Index: src/usr.bin/indent/lexi.c
diff -u src/usr.bin/indent/lexi.c:1.77 src/usr.bin/indent/lexi.c:1.78
--- src/usr.bin/indent/lexi.c:1.77	Thu Oct  7 22:52:13 2021
+++ src/usr.bin/indent/lexi.c	Thu Oct  7 23:15:15 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: lexi.c,v 1.77 2021/10/07 22:52:13 rillig Exp $	*/
+/*	$NetBSD: lexi.c,v 1.78 2021/10/07 23:15:15 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@ static char sccsid[] = "@(#)lexi.c	8.1 (
 
 #include <sys/cdefs.h>
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: lexi.c,v 1.77 2021/10/07 22:52:13 rillig Exp $");
+__RCSID("$NetBSD: lexi.c,v 1.78 2021/10/07 23:15:15 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/lexi.c 337862 2018-08-15 18:19:45Z pstef $");
 #endif
@@ -179,14 +179,14 @@ static const uint8_t num_lex_row[] = {
 static char
 inbuf_peek(void)
 {
-    return *buf_ptr;
+    return *inp.s;
 }
 
 void
 inbuf_skip(void)
 {
-    buf_ptr++;
-    if (buf_ptr >= buf_end)
+    inp.s++;
+    if (inp.s >= inp.e)
 	fill_buffer();
 }
 
@@ -268,7 +268,7 @@ static void
 lex_number(void)
 {
     for (uint8_t s = 'A'; s != 'f' && s != 'i' && s != 'u';) {
-	uint8_t ch = (uint8_t)*buf_ptr;
+	uint8_t ch = (uint8_t)*inp.s;
 	if (ch >= nitems(num_lex_row) || num_lex_row[ch] == 0)
 	    break;
 
@@ -290,15 +290,15 @@ lex_number(void)
 static void
 lex_word(void)
 {
-    while (isalnum((unsigned char)*buf_ptr) ||
-	   *buf_ptr == '\\' ||
-	   *buf_ptr == '_' || *buf_ptr == '$') {
+    while (isalnum((unsigned char)*inp.s) ||
+	   *inp.s == '\\' ||
+	   *inp.s == '_' || *inp.s == '$') {
 
 	/* fill_buffer() terminates buffer with newline */
-	if (*buf_ptr == '\\') {
-	    if (buf_ptr[1] == '\n') {
-		buf_ptr += 2;
-		if (buf_ptr >= buf_end)
+	if (*inp.s == '\\') {
+	    if (inp.s[1] == '\n') {
+		inp.s += 2;
+		if (inp.s >= inp.e)
 		    fill_buffer();
 	    } else
 		break;
@@ -313,7 +313,7 @@ static void
 lex_char_or_string(void)
 {
     for (char delim = *token.s;;) {
-	if (*buf_ptr == '\n') {
+	if (*inp.s == '\n') {
 	    diag(1, "Unterminated literal");
 	    return;
 	}
@@ -324,7 +324,7 @@ lex_char_or_string(void)
 	    return;
 
 	if (token.e[-1] == '\\') {
-	    if (*buf_ptr == '\n')
+	    if (*inp.s == '\n')
 		++line_no;
 	    *token.e++ = inbuf_next();
 	}
@@ -342,9 +342,9 @@ probably_typedef(const struct parser_sta
 	return false;
     if (state->block_init || state->in_stmt)
 	return false;
-    if (buf_ptr[0] == '*' && buf_ptr[1] != '=')
+    if (inp.s[0] == '*' && inp.s[1] != '=')
 	goto maybe;
-    if (isalpha((unsigned char)*buf_ptr))
+    if (isalpha((unsigned char)*inp.s))
 	goto maybe;
     return false;
 maybe:
@@ -383,19 +383,19 @@ lexi(struct parser_state *state)
 					 * scanned was a newline */
     state->last_nl = false;
 
-    while (is_hspace(*buf_ptr)) {
+    while (is_hspace(*inp.s)) {
 	state->col_1 = false;
 	inbuf_skip();
     }
 
     /* Scan an alphanumeric token */
-    if (isalnum((unsigned char)*buf_ptr) ||
-	*buf_ptr == '_' || *buf_ptr == '$' ||
-	(buf_ptr[0] == '.' && isdigit((unsigned char)buf_ptr[1]))) {
+    if (isalnum((unsigned char)*inp.s) ||
+	*inp.s == '_' || *inp.s == '$' ||
+	(inp.s[0] == '.' && isdigit((unsigned char)inp.s[1]))) {
 	struct keyword *kw;
 
-	if (isdigit((unsigned char)*buf_ptr) ||
-	    (buf_ptr[0] == '.' && isdigit((unsigned char)buf_ptr[1]))) {
+	if (isdigit((unsigned char)*inp.s) ||
+	    (inp.s[0] == '.' && isdigit((unsigned char)inp.s[1]))) {
 	    lex_number();
 	} else {
 	    lex_word();
@@ -403,7 +403,7 @@ lexi(struct parser_state *state)
 	*token.e = '\0';
 
 	if (token.s[0] == 'L' && token.s[1] == '\0' &&
-	    (*buf_ptr == '"' || *buf_ptr == '\''))
+	    (*inp.s == '"' || *inp.s == '\''))
 	    return lexi_end(string_prefix);
 
 	while (is_hspace(inbuf_peek()))
@@ -475,10 +475,10 @@ lexi(struct parser_state *state)
 	    }			/* end of switch */
 	}			/* end of if (found_it) */
 
-	if (*buf_ptr == '(' && state->tos <= 1 && state->ind_level == 0 &&
+	if (*inp.s == '(' && state->tos <= 1 && state->ind_level == 0 &&
 	    !state->in_parameter_declaration && !state->block_init) {
 
-	    for (char *tp = buf_ptr; tp < buf_end;)
+	    for (char *tp = inp.s; tp < inp.e;)
 		if (*tp++ == ')' && (*tp == ';' || *tp == ','))
 		    goto not_proc;
 
@@ -585,9 +585,9 @@ lexi(struct parser_state *state)
 	ttype = state->last_u_d ? unary_op : binary_op;
 	unary_delim = true;
 
-	if (*buf_ptr == token.s[0]) {
+	if (*inp.s == token.s[0]) {
 	    /* check for doubled character */
-	    *token.e++ = *buf_ptr++;
+	    *token.e++ = *inp.s++;
 	    /* buffer overflow will be checked at end of loop */
 	    if (state->last_token == ident || state->last_token == rparen) {
 		ttype = state->last_u_d ? unary_op : postfix_op;
@@ -595,13 +595,13 @@ lexi(struct parser_state *state)
 		unary_delim = false;
 	    }
 
-	} else if (*buf_ptr == '=') {
+	} else if (*inp.s == '=') {
 	    /* check for operator += */
-	    *token.e++ = *buf_ptr++;
+	    *token.e++ = *inp.s++;
 
-	} else if (*buf_ptr == '>') {
+	} else if (*inp.s == '>') {
 	    /* check for operator -> */
-	    *token.e++ = *buf_ptr++;
+	    *token.e++ = *inp.s++;
 	    unary_delim = false;
 	    ttype = unary_op;
 	    state->want_blank = false;
@@ -612,8 +612,8 @@ lexi(struct parser_state *state)
     case '=':
 	if (state->in_or_st)
 	    state->block_init = true;
-	if (*buf_ptr == '=') {	/* == */
-	    *token.e++ = *buf_ptr++;
+	if (*inp.s == '=') {	/* == */
+	    *token.e++ = *inp.s++;
 	    *token.e = '\0';
 	}
 	ttype = binary_op;
@@ -623,10 +623,10 @@ lexi(struct parser_state *state)
     case '>':
     case '<':
     case '!':			/* ops like <, <<, <=, !=, etc */
-	if (*buf_ptr == '>' || *buf_ptr == '<' || *buf_ptr == '=')
+	if (*inp.s == '>' || *inp.s == '<' || *inp.s == '=')
 	    *token.e++ = inbuf_next();
-	if (*buf_ptr == '=')
-	    *token.e++ = *buf_ptr++;
+	if (*inp.s == '=')
+	    *token.e++ = *inp.s++;
 	ttype = state->last_u_d ? unary_op : binary_op;
 	unary_delim = true;
 	break;
@@ -634,26 +634,26 @@ lexi(struct parser_state *state)
     case '*':
 	unary_delim = true;
 	if (!state->last_u_d) {
-	    if (*buf_ptr == '=')
-		*token.e++ = *buf_ptr++;
+	    if (*inp.s == '=')
+		*token.e++ = *inp.s++;
 	    ttype = binary_op;
 	    break;
 	}
 
-	while (*buf_ptr == '*' || isspace((unsigned char)*buf_ptr)) {
-	    if (*buf_ptr == '*') {
+	while (*inp.s == '*' || isspace((unsigned char)*inp.s)) {
+	    if (*inp.s == '*') {
 		check_size_token(1);
-		*token.e++ = *buf_ptr;
+		*token.e++ = *inp.s;
 	    }
 	    inbuf_skip();
 	}
 
 	if (ps.in_decl) {
-	    char *tp = buf_ptr;
+	    char *tp = inp.s;
 
 	    while (isalpha((unsigned char)*tp) ||
 		   isspace((unsigned char)*tp)) {
-		if (++tp >= buf_end)
+		if (++tp >= inp.e)
 		    fill_buffer();
 	    }
 	    if (*tp == '(')
@@ -664,7 +664,7 @@ lexi(struct parser_state *state)
 	break;
 
     default:
-	if (token.s[0] == '/' && (*buf_ptr == '*' || *buf_ptr == '/')) {
+	if (token.s[0] == '/' && (*inp.s == '*' || *inp.s == '/')) {
 	    /* it is start of comment */
 	    *token.e++ = inbuf_next();
 
@@ -673,7 +673,7 @@ lexi(struct parser_state *state)
 	    break;
 	}
 
-	while (token.e[-1] == *buf_ptr || *buf_ptr == '=') {
+	while (token.e[-1] == *inp.s || *inp.s == '=') {
 	    /*
 	     * handle ||, &&, etc, and also things as in int *****i
 	     */
@@ -685,7 +685,7 @@ lexi(struct parser_state *state)
 	unary_delim = true;
     }
 
-    if (buf_ptr >= buf_end)	/* check for input buffer empty */
+    if (inp.s >= inp.e)	/* check for input buffer empty */
 	fill_buffer();
 
     state->last_u_d = unary_delim;

Index: src/usr.bin/indent/pr_comment.c
diff -u src/usr.bin/indent/pr_comment.c:1.57 src/usr.bin/indent/pr_comment.c:1.58
--- src/usr.bin/indent/pr_comment.c:1.57	Thu Oct  7 21:57:21 2021
+++ src/usr.bin/indent/pr_comment.c	Thu Oct  7 23:15:15 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: pr_comment.c,v 1.57 2021/10/07 21:57:21 rillig Exp $	*/
+/*	$NetBSD: pr_comment.c,v 1.58 2021/10/07 23:15:15 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@ static char sccsid[] = "@(#)pr_comment.c
 
 #include <sys/cdefs.h>
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: pr_comment.c,v 1.57 2021/10/07 21:57:21 rillig Exp $");
+__RCSID("$NetBSD: pr_comment.c,v 1.58 2021/10/07 23:15:15 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/pr_comment.c 334927 2018-06-10 16:44:18Z pstef $");
 #endif
@@ -105,8 +105,8 @@ process_comment(void)
 	ps.com_col = 1;
 
     } else {
-	if (*buf_ptr == '-' || *buf_ptr == '*' || token.e[-1] == '/' ||
-	    (*buf_ptr == '\n' && !opt.format_block_comments)) {
+	if (*inp.s == '-' || *inp.s == '*' || token.e[-1] == '/' ||
+	    (*inp.s == '\n' && !opt.format_block_comments)) {
 	    ps.box_com = true;	/* A comment with a '-' or '*' immediately
 				 * after the /+* is assumed to be a boxed
 				 * comment. A comment with a newline
@@ -150,7 +150,7 @@ process_comment(void)
 	 * much will have to be ignored by dump_line(). This is a box comment,
 	 * so nothing changes -- not even indentation.
 	 *
-	 * The comment we're about to read usually comes from in_buffer,
+	 * The comment we're about to read usually comes from inp.buf,
 	 * unless it has been copied into save_com.
 	 */
 	const char *start;
@@ -159,25 +159,25 @@ process_comment(void)
 	 * XXX: ordered comparison between pointers from different objects
 	 * invokes undefined behavior (C99 6.5.8).
 	 */
-	start = buf_ptr >= save_com && buf_ptr < save_com + sc_size ?
-	    sc_buf : in_buffer;
-	ps.n_comment_delta = -indentation_after_range(0, start, buf_ptr - 2);
+	start = inp.s >= save_com && inp.s < save_com + sc_size ?
+	    sc_buf : inp.buf;
+	ps.n_comment_delta = -indentation_after_range(0, start, inp.s - 2);
     } else {
 	ps.n_comment_delta = 0;
-	while (is_hspace(*buf_ptr))
-	    buf_ptr++;
+	while (is_hspace(*inp.s))
+	    inp.s++;
     }
 
     ps.comment_delta = 0;
     *com.e++ = '/';
     *com.e++ = token.e[-1];
-    if (*buf_ptr != ' ' && !ps.box_com)
+    if (*inp.s != ' ' && !ps.box_com)
 	*com.e++ = ' ';
 
     /* Don't put a break delimiter if this is a one-liner that won't wrap. */
     if (break_delim) {
-	for (t_ptr = buf_ptr; *t_ptr != '\0' && *t_ptr != '\n'; t_ptr++) {
-	    if (t_ptr >= buf_end)
+	for (t_ptr = inp.s; *t_ptr != '\0' && *t_ptr != '\n'; t_ptr++) {
+	    if (t_ptr >= inp.e)
 		fill_buffer();
 	    if (t_ptr[0] == '*' && t_ptr[1] == '/') {
 		/*
@@ -186,7 +186,7 @@ process_comment(void)
 		 * out since they are equally long.
 		 */
 		int right_margin = indentation_after_range(ps.com_col - 1,
-		    buf_ptr, t_ptr + 2);
+		    inp.s, t_ptr + 2);
 		if (right_margin < adj_max_line_length)
 		    break_delim = false;
 		break;
@@ -210,7 +210,7 @@ process_comment(void)
 
     for (;;) {			/* this loop will go until the comment is
 				 * copied */
-	switch (*buf_ptr) {	/* this checks for various special cases */
+	switch (*inp.s) {	/* this checks for various special cases */
 	case '\f':
 	    check_size_comment(3);
 	    if (!ps.box_com) {	/* in a text comment, break the line here */
@@ -219,9 +219,9 @@ process_comment(void)
 		last_blank = -1;
 		if (!ps.box_com && opt.star_comment_cont)
 		    *com.e++ = ' ', *com.e++ = '*', *com.e++ = ' ';
-		buf_ptr++;
-		while (is_hspace(*buf_ptr))
-		    buf_ptr++;
+		inp.s++;
+		while (is_hspace(*inp.s))
+		    inp.s++;
 	    } else {
 		inbuf_skip();
 		*com.e++ = '\f';
@@ -267,12 +267,12 @@ process_comment(void)
 		do {		/* flush any blanks and/or tabs at start of
 				 * next line */
 		    inbuf_skip();
-		    if (*buf_ptr == '*' && --asterisks_to_skip >= 0) {
+		    if (*inp.s == '*' && --asterisks_to_skip >= 0) {
 			inbuf_skip();
-			if (*buf_ptr == '/')
+			if (*inp.s == '/')
 			    goto end_of_comment;
 		    }
-		} while (is_hspace(*buf_ptr));
+		} while (is_hspace(*inp.s));
 	    } else
 		inbuf_skip();
 	    break;		/* end of case for newline */
@@ -280,7 +280,7 @@ process_comment(void)
 	case '*':
 	    inbuf_skip();
 	    check_size_comment(4);
-	    if (*buf_ptr == '/') {
+	    if (*inp.s == '/') {
 	end_of_comment:
 		inbuf_skip();
 
@@ -316,7 +316,7 @@ process_comment(void)
 		    last_blank = com.e - com.buf;
 		*com.e++ = ch;
 		now_len++;
-	    } while (memchr("*\n\r\b\t", *buf_ptr, 6) == NULL &&
+	    } while (memchr("*\n\r\b\t", *inp.s, 6) == NULL &&
 		(now_len < adj_max_line_length || last_blank == -1));
 
 	    ps.last_nl = false;

Reply via email to