Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/indent indent: reorder global variables to be more i...



details:   https://anonhg.NetBSD.org/src/rev/15f7834450d0
branches:  trunk
changeset: 1024594:15f7834450d0
user:      rillig <rillig%NetBSD.org@localhost>
date:      Fri Oct 29 18:18:03 2021 +0000

description:
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.

diffstat:

 usr.bin/indent/indent.h |  26 ++++++++++++++++----------
 usr.bin/indent/io.c     |  12 ++++++------
 2 files changed, 22 insertions(+), 16 deletions(-)

diffs (94 lines):

diff -r 35dae6bca752 -r 15f7834450d0 usr.bin/indent/indent.h
--- a/usr.bin/indent/indent.h   Fri Oct 29 17:50:37 2021 +0000
+++ b/usr.bin/indent/indent.h   Fri Oct 29 18:18:03 2021 +0000
@@ -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 @@
                                 * 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 */
diff -r 35dae6bca752 -r 15f7834450d0 usr.bin/indent/io.c
--- a/usr.bin/indent/io.c       Fri Oct 29 17:50:37 2021 +0000
+++ b/usr.bin/indent/io.c       Fri Oct 29 18:18:03 2021 +0000
@@ -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 @@
 
 #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 @@
            /* 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 @@
        }
     }
 
-    /* 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 @@
 }
 
 /*
- * 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)



Home | Main Index | Thread Index | Old Index