Module Name:    src
Committed By:   rillig
Date:           Sat May 13 12:31:02 UTC 2023

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

Log Message:
indent: rename struct fields for buffers

No binary change except for assertion line numbers.


To generate a diff of this commit:
cvs rdiff -u -r1.258 -r1.259 src/usr.bin/indent/indent.c
cvs rdiff -u -r1.124 -r1.125 src/usr.bin/indent/indent.h
cvs rdiff -u -r1.156 -r1.157 src/usr.bin/indent/io.c
cvs rdiff -u -r1.177 -r1.178 src/usr.bin/indent/lexi.c
cvs rdiff -u -r1.130 -r1.131 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.258 src/usr.bin/indent/indent.c:1.259
--- src/usr.bin/indent/indent.c:1.258	Sat May 13 09:40:47 2023
+++ src/usr.bin/indent/indent.c	Sat May 13 12:31:02 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.c,v 1.258 2023/05/13 09:40:47 rillig Exp $	*/
+/*	$NetBSD: indent.c,v 1.259 2023/05/13 12:31:02 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.258 2023/05/13 09:40:47 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.259 2023/05/13 12:31:02 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -112,12 +112,12 @@ static void
 buf_init(struct buffer *buf)
 {
     size_t size = 200;
-    buf->buf = xmalloc(size);
-    buf->l = buf->buf + size - 5 /* safety margin */;
-    buf->s = buf->buf + 1;	/* allow accessing buf->e[-1] */
+    buf->mem = xmalloc(size);
+    buf->limit = buf->mem + size - 5 /* safety margin */;
+    buf->s = buf->mem + 1;	/* allow accessing buf->e[-1] */
     buf->e = buf->s;
-    buf->buf[0] = ' ';
-    buf->buf[1] = '\0';
+    buf->mem[0] = ' ';
+    buf->e[0] = '\0';
 }
 
 static size_t
@@ -129,11 +129,11 @@ buf_len(const struct buffer *buf)
 void
 buf_expand(struct buffer *buf, size_t add_size)
 {
-    size_t new_size = (size_t)(buf->l - buf->s) + 400 + add_size;
+    size_t new_size = (size_t)(buf->limit - buf->s) + 400 + add_size;
     size_t len = buf_len(buf);
-    buf->buf = xrealloc(buf->buf, new_size);
-    buf->l = buf->buf + new_size - 5;
-    buf->s = buf->buf + 1;
+    buf->mem = xrealloc(buf->mem, new_size);
+    buf->limit = buf->mem + new_size - 5;
+    buf->s = buf->mem + 1;
     buf->e = buf->s + len;
     /* At this point, the buffer may not be null-terminated anymore. */
 }
@@ -141,7 +141,7 @@ buf_expand(struct buffer *buf, size_t ad
 static void
 buf_reserve(struct buffer *buf, size_t n)
 {
-    if (n >= (size_t)(buf->l - buf->e))
+    if (n >= (size_t)(buf->limit - buf->e))
 	buf_expand(buf, n);
 }
 

Index: src/usr.bin/indent/indent.h
diff -u src/usr.bin/indent/indent.h:1.124 src/usr.bin/indent/indent.h:1.125
--- src/usr.bin/indent/indent.h:1.124	Sat May 13 09:40:47 2023
+++ src/usr.bin/indent/indent.h	Sat May 13 12:31:02 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: indent.h,v 1.124 2023/05/13 09:40:47 rillig Exp $	*/
+/*	$NetBSD: indent.h,v 1.125 2023/05/13 12:31:02 rillig Exp $	*/
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -131,8 +131,8 @@ typedef enum parser_symbol {
 struct buffer {
     char *s;			/* start of the usable text */
     char *e;			/* end of the usable text */
-    char *buf;			/* start of the allocated memory */
-    char *l;			/* end of the allocated memory */
+    char *mem;			/* start of the allocated memory */
+    char *limit;		/* end of the allocated memory */
 };
 
 extern FILE *input;

Index: src/usr.bin/indent/io.c
diff -u src/usr.bin/indent/io.c:1.156 src/usr.bin/indent/io.c:1.157
--- src/usr.bin/indent/io.c:1.156	Sat May 13 09:27:49 2023
+++ src/usr.bin/indent/io.c	Sat May 13 12:31:02 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: io.c,v 1.156 2023/05/13 09:27:49 rillig Exp $	*/
+/*	$NetBSD: io.c,v 1.157 2023/05/13 12:31:02 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.156 2023/05/13 09:27:49 rillig Exp $");
+__RCSID("$NetBSD: io.c,v 1.157 2023/05/13 12:31:02 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/io.c 334927 2018-06-10 16:44:18Z pstef $");
 #endif
@@ -57,8 +57,7 @@ __FBSDID("$FreeBSD: head/usr.bin/indent/
 
 /*
  * The current line, ready to be split into tokens, terminated with '\n'. The
- * current read position is inp.s, and the invariant inp.buf <= inp.s < inp.e
- * holds.
+ * current read position is inp.s, and the invariant inp.s < inp.e holds.
  */
 static struct buffer inp;
 
@@ -68,10 +67,10 @@ static int paren_indent;
 void
 inp_init(void)
 {
-    inp.buf = xmalloc(10);
-    inp.l = inp.buf + 8;
-    inp.s = inp.buf;
-    inp.e = inp.buf;
+    inp.mem = xmalloc(10);
+    inp.limit = inp.mem + 8;
+    inp.s = inp.mem;
+    inp.e = inp.mem;
 }
 
 const char *
@@ -84,7 +83,7 @@ inp_p(void)
 const char *
 inp_line_start(void)
 {
-    return inp.buf;
+    return inp.mem;
 }
 
 const char *
@@ -127,13 +126,13 @@ inp_next(void)
 static void
 inp_add(char ch)
 {
-    if (inp.e >= inp.l) {
-	size_t new_size = (size_t)(inp.l - inp.buf) * 2 + 10;
-	size_t offset = (size_t)(inp.e - inp.buf);
-	inp.buf = xrealloc(inp.buf, new_size);
-	inp.s = inp.buf;
-	inp.e = inp.buf + offset;
-	inp.l = inp.buf + new_size - 2;
+    if (inp.e >= inp.limit) {
+	size_t new_size = (size_t)(inp.limit - inp.mem) * 2 + 10;
+	size_t e_offset = (size_t)(inp.e - inp.mem);
+	inp.mem = xrealloc(inp.mem, new_size);
+	inp.s = inp.mem;
+	inp.e = inp.mem + e_offset;
+	inp.limit = inp.mem + new_size - 2;
     }
     *inp.e++ = ch;
 }
@@ -141,8 +140,8 @@ inp_add(char ch)
 static void
 inp_read_next_line(FILE *f)
 {
-    inp.s = inp.buf;
-    inp.e = inp.buf;
+    inp.s = inp.mem;
+    inp.e = inp.mem;
 
     for (;;) {
 	int ch = getc(f);
@@ -314,7 +313,7 @@ output_complete_line(char line_terminato
 
     *(lab.e = lab.s) = '\0';	/* reset buffers */
     *(code.e = code.s) = '\0';
-    *(com.e = com.s = com.buf + 1) = '\0';
+    *(com.e = com.s = com.mem + 1) = '\0';
 
     ps.ind_level = ps.ind_level_follow;
     ps.line_start_nparen = ps.nparen;
@@ -412,7 +411,7 @@ parse_indent_comment(void)
 {
     bool on;
 
-    const char *p = inp.buf;
+    const char *p = inp.mem;
 
     skip_blank(&p);
     if (!skip_string(&p, "/*"))

Index: src/usr.bin/indent/lexi.c
diff -u src/usr.bin/indent/lexi.c:1.177 src/usr.bin/indent/lexi.c:1.178
--- src/usr.bin/indent/lexi.c:1.177	Sat May 13 09:27:49 2023
+++ src/usr.bin/indent/lexi.c	Sat May 13 12:31:02 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: lexi.c,v 1.177 2023/05/13 09:27:49 rillig Exp $	*/
+/*	$NetBSD: lexi.c,v 1.178 2023/05/13 12:31:02 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.177 2023/05/13 09:27:49 rillig Exp $");
+__RCSID("$NetBSD: lexi.c,v 1.178 2023/05/13 12:31:02 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/lexi.c 337862 2018-08-15 18:19:45Z pstef $");
 #endif
@@ -180,7 +180,7 @@ static const unsigned char lex_number_ro
 static void
 check_size_token(size_t desired_size)
 {
-    if (token.e + desired_size >= token.l)
+    if (token.e + desired_size >= token.limit)
 	buf_expand(&token, desired_size);
 }
 

Index: src/usr.bin/indent/pr_comment.c
diff -u src/usr.bin/indent/pr_comment.c:1.130 src/usr.bin/indent/pr_comment.c:1.131
--- src/usr.bin/indent/pr_comment.c:1.130	Fri May 12 10:53:33 2023
+++ src/usr.bin/indent/pr_comment.c	Sat May 13 12:31:02 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: pr_comment.c,v 1.130 2023/05/12 10:53:33 rillig Exp $	*/
+/*	$NetBSD: pr_comment.c,v 1.131 2023/05/13 12:31:02 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.130 2023/05/12 10:53:33 rillig Exp $");
+__RCSID("$NetBSD: pr_comment.c,v 1.131 2023/05/13 12:31:02 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/pr_comment.c 334927 2018-06-10 16:44:18Z pstef $");
 #endif
@@ -57,7 +57,7 @@ __FBSDID("$FreeBSD: head/usr.bin/indent/
 static void
 com_add_char(char ch)
 {
-    if (1 >= com.l - com.e)
+    if (1 >= com.limit - com.e)
 	buf_expand(&com, 1);
     *com.e++ = ch;
 }
@@ -74,7 +74,7 @@ com_add_delim(void)
 static void
 com_terminate(void)
 {
-    if (1 >= com.l - com.e)
+    if (1 >= com.limit - com.e)
 	buf_expand(&com, 1);
     *com.e = '\0';
 }
@@ -193,7 +193,7 @@ analyze_comment(bool *p_may_wrap, bool *
 static void
 copy_comment_wrap(int adj_max_line_length, bool break_delim)
 {
-    ssize_t last_blank = -1;	/* index of the last blank in com.buf */
+    ssize_t last_blank = -1;	/* index of the last blank in com.mem */
 
     for (;;) {
 	switch (inp_peek()) {
@@ -228,7 +228,7 @@ copy_comment_wrap(int adj_max_line_lengt
 		ps.next_col_1 = true;
 		if (!(com.e > com.s && ch_isblank(com.e[-1])))
 		    com_add_char(' ');
-		last_blank = com.e - 1 - com.buf;
+		last_blank = com.e - 1 - com.mem;
 	    }
 	    ++line_no;
 
@@ -277,7 +277,7 @@ copy_comment_wrap(int adj_max_line_lengt
 	    for (;;) {
 		char ch = inp_next();
 		if (ch_isblank(ch))
-		    last_blank = com.e - com.buf;
+		    last_blank = com.e - com.mem;
 		com_add_char(ch);
 		now_len++;
 		if (memchr("*\n\r\b\t", inp_peek(), 6) != NULL)
@@ -299,9 +299,9 @@ copy_comment_wrap(int adj_max_line_lengt
 		break;
 	    }
 
-	    const char *last_word_s = com.buf + last_blank + 1;
+	    const char *last_word_s = com.mem + last_blank + 1;
 	    size_t last_word_len = (size_t)(com.e - last_word_s);
-	    com.e = com.buf + last_blank;
+	    com.e = com.mem + last_blank;
 	    output_line();
 	    com_add_delim();
 

Reply via email to