Module Name: src
Committed By: rillig
Date: Fri Oct 29 18:18:03 UTC 2021
Modified Files:
src/usr.bin/indent: indent.h io.c
Log Message:
indent: reorder global variables to be more intuitive
The buffer 'inp' comes first. From there, a single token is read into
the buffer 'token'. From there, it usually ends up in 'code'. The buffer
'token' does not belong to the group of the other 3 buffers, which
together make up a line of formatted output.
No functional change.
To generate a diff of this commit:
cvs rdiff -u -r1.60 -r1.61 src/usr.bin/indent/indent.h
cvs rdiff -u -r1.104 -r1.105 src/usr.bin/indent/io.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.60 src/usr.bin/indent/indent.h:1.61
--- src/usr.bin/indent/indent.h:1.60 Fri Oct 29 17:50:37 2021
+++ src/usr.bin/indent/indent.h Fri Oct 29 18:18:03 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: indent.h,v 1.60 2021/10/29 17:50:37 rillig Exp $ */
+/* $NetBSD: indent.h,v 1.61 2021/10/29 18:18:03 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -135,22 +135,28 @@ typedef enum stmt_head {
* of code */
+/* A range of characters, in some cases null-terminated. */
struct buffer {
- char *buf; /* buffer */
- char *s; /* start */
- char *e; /* end */
- char *l; /* limit */
+ 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 */
};
extern FILE *input;
extern FILE *output;
-extern struct buffer lab; /* label or preprocessor directive */
-extern struct buffer code; /* code */
-extern struct buffer com; /* comment */
-extern struct buffer token; /* the last token scanned */
+extern struct buffer inp; /* one line of input, ready to be split into
+ * tokens */
-extern struct buffer inp;
+extern struct buffer token; /* the current token to be processed, is
+ * typically copied to the buffer 'code',
+ * or in some cases to 'lab'. */
+
+extern struct buffer lab; /* the label or preprocessor directive */
+extern struct buffer code; /* the main part of the current line of code */
+extern struct buffer com; /* the trailing comment of the line, or the
+ * start or end of a multi-line comment */
extern char sc_buf[sc_size]; /* input text is saved here when looking for
* the brace after an if, while, etc */
Index: src/usr.bin/indent/io.c
diff -u src/usr.bin/indent/io.c:1.104 src/usr.bin/indent/io.c:1.105
--- src/usr.bin/indent/io.c:1.104 Fri Oct 29 17:32:22 2021
+++ src/usr.bin/indent/io.c Fri Oct 29 18:18:03 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: io.c,v 1.104 2021/10/29 17:32:22 rillig Exp $ */
+/* $NetBSD: io.c,v 1.105 2021/10/29 18:18:03 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.104 2021/10/29 17:32:22 rillig Exp $");
+__RCSID("$NetBSD: io.c,v 1.105 2021/10/29 18:18:03 rillig Exp $");
#elif defined(__FreeBSD__)
__FBSDID("$FreeBSD: head/usr.bin/indent/io.c 334927 2018-06-10 16:44:18Z pstef $");
#endif
@@ -153,7 +153,7 @@ dump_line_code(int ind)
/* XXX: the '+ 1' smells like an off-by-one error. */
ps.paren_indents[i] = (short)-(paren_ind + target_ind + 1);
debug_println(
- "setting pi[%d] from %d to %d for column %d",
+ "setting paren_indents[%d] from %d to %d for column %d",
i, paren_ind, ps.paren_indents[i], target_ind + 1);
}
}
@@ -186,7 +186,7 @@ dump_line_comment(int ind)
}
}
- /* if comment can't fit on this line, put it on next line */
+ /* if comment can't fit on this line, put it on the next line */
if (ind > target_ind) {
output_char('\n');
ind = 0;
@@ -204,8 +204,8 @@ dump_line_comment(int ind)
}
/*
- * Write a line of formatted source to the output file. The line consists of a
- * label, the code and the comment.
+ * Write a line of formatted source to the output file. The line consists of
+ * the label, the code and the comment.
*/
static void
output_line(char line_terminator)