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: replace compute_label_column with com...



details:   https://anonhg.NetBSD.org/src/rev/c92b87b0c5ea
branches:  trunk
changeset: 953565:c92b87b0c5ea
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Mar 13 09:54:11 2021 +0000

description:
indent: replace compute_label_column with compute_label_indent

Using the invariant 'column == 1 + indent'.  This removes several overly
complicated '+ 1' from the code that are not needed conceptually.

No functional change.

diffstat:

 usr.bin/indent/indent.h     |   6 +++---
 usr.bin/indent/io.c         |  17 +++++++++--------
 usr.bin/indent/pr_comment.c |   6 +++---
 3 files changed, 15 insertions(+), 14 deletions(-)

diffs (100 lines):

diff -r 9eff7e882539 -r c92b87b0c5ea usr.bin/indent/indent.h
--- a/usr.bin/indent/indent.h   Sat Mar 13 09:48:04 2021 +0000
+++ b/usr.bin/indent/indent.h   Sat Mar 13 09:54:11 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: indent.h,v 1.9 2021/03/13 09:21:57 rillig Exp $        */
+/*     $NetBSD: indent.h,v 1.10 2021/03/13 09:54:11 rillig Exp $       */
 
 /*-
  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
@@ -30,7 +30,7 @@
 
 #if 0
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: indent.h,v 1.9 2021/03/13 09:21:57 rillig Exp $");
+__RCSID("$NetBSD: indent.h,v 1.10 2021/03/13 09:54:11 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.h 336333 2018-07-16 05:46:50Z pstef $");
 #endif
@@ -46,7 +46,7 @@
 void   add_typename(const char *);
 void   alloc_typenames(void);
 int    compute_code_column(void);
-int    compute_label_column(void);
+int    compute_label_indent(void);
 int    count_spaces(int, const char *);
 int    count_spaces_until(int, const char *, const char *);
 void   init_constant_tt(void);
diff -r 9eff7e882539 -r c92b87b0c5ea usr.bin/indent/io.c
--- a/usr.bin/indent/io.c       Sat Mar 13 09:48:04 2021 +0000
+++ b/usr.bin/indent/io.c       Sat Mar 13 09:54:11 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: io.c,v 1.37 2021/03/13 09:48:04 rillig Exp $   */
+/*     $NetBSD: io.c,v 1.38 2021/03/13 09:54:11 rillig Exp $   */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -46,7 +46,7 @@
 #include <sys/cdefs.h>
 #ifndef lint
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: io.c,v 1.37 2021/03/13 09:48:04 rillig Exp $");
+__RCSID("$NetBSD: io.c,v 1.38 2021/03/13 09:54:11 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/io.c 334927 2018-06-10 16:44:18Z pstef $");
 #endif
@@ -162,7 +162,7 @@
            while (e_lab > s_lab && (e_lab[-1] == ' ' || e_lab[-1] == '\t'))
                e_lab--;
            *e_lab = '\0';
-           cur_col = 1 + output_indent(0, compute_label_column() - 1);
+           cur_col = 1 + output_indent(0, compute_label_indent());
            if (s_lab[0] == '#' && (strncmp(s_lab, "#else", 5) == 0
                                    || strncmp(s_lab, "#endif", 6) == 0)) {
                char *s = s_lab;
@@ -315,12 +315,13 @@
 }
 
 int
-compute_label_column(void)
+compute_label_indent(void)
 {
-    return
-       ps.pcase ? (int) (case_ind * opt.ind_size) + 1
-       : *s_lab == '#' ? 1
-       : opt.ind_size * (ps.ind_level - label_offset) + 1;
+    if (ps.pcase)
+       return (int) (case_ind * opt.ind_size);
+    if (s_lab[0] == '#')
+        return 0;
+    return opt.ind_size * (ps.ind_level - label_offset);
 }
 
 
diff -r 9eff7e882539 -r c92b87b0c5ea usr.bin/indent/pr_comment.c
--- a/usr.bin/indent/pr_comment.c       Sat Mar 13 09:48:04 2021 +0000
+++ b/usr.bin/indent/pr_comment.c       Sat Mar 13 09:54:11 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pr_comment.c,v 1.21 2021/03/13 00:26:56 rillig Exp $   */
+/*     $NetBSD: pr_comment.c,v 1.22 2021/03/13 09:54:11 rillig Exp $   */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -46,7 +46,7 @@
 #include <sys/cdefs.h>
 #ifndef lint
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: pr_comment.c,v 1.21 2021/03/13 00:26:56 rillig Exp $");
+__RCSID("$NetBSD: pr_comment.c,v 1.22 2021/03/13 09:54:11 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/pr_comment.c 334927 2018-06-10 16:44:18Z pstef $");
 #endif
@@ -166,7 +166,7 @@
            else {
                target_col = 1;
                if (s_lab != e_lab)
-                   target_col = count_spaces(compute_label_column(), s_lab);
+                   target_col = count_spaces(compute_label_indent() + 1, s_lab);
            }
            ps.com_col = ps.decl_on_line || ps.ind_level == 0 ? opt.decl_com_ind : opt.com_ind;
            if (ps.com_col <= target_col)



Home | Main Index | Thread Index | Old Index