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: clean up code_add_decl_indent



details:   https://anonhg.NetBSD.org/src/rev/729b3096e5a1
branches:  trunk
changeset: 1024638:729b3096e5a1
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sat Oct 30 11:05:26 2021 +0000

description:
indent: clean up code_add_decl_indent

In layout computations, it is helpful for human readers to list the
summands in logical order. In this case, the expression 'code_len +
base_ind' was rather confusing, so replace it with 'base_ind +
code_len'. This makes the code straight-forward enough that it doesn't
need any comments anymore.

No functional change.

diffstat:

 usr.bin/indent/indent.c |  28 ++++++++++------------------
 1 files changed, 10 insertions(+), 18 deletions(-)

diffs (53 lines):

diff -r 53b61ae0a93a -r 729b3096e5a1 usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c   Sat Oct 30 11:04:48 2021 +0000
+++ b/usr.bin/indent/indent.c   Sat Oct 30 11:05:26 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: indent.c,v 1.183 2021/10/30 10:59:07 rillig Exp $      */
+/*     $NetBSD: indent.c,v 1.184 2021/10/30 11:05:26 rillig Exp $      */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: indent.c,v 1.183 2021/10/30 10:59:07 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.184 2021/10/30 11:05:26 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
 #endif
@@ -601,26 +601,18 @@
 }
 
 static void
-code_add_decl_indent(int cur_decl_ind, bool tabs_to_var)
+code_add_decl_indent(int decl_ind, bool tabs_to_var)
 {
-    int ind = (int)buf_len(&code);
+    int base_ind = ps.ind_level * opt.indent_size;
+    int ind = base_ind + (int)buf_len(&code);
+    int target_ind = base_ind + decl_ind;
     char *orig_code_e = code.e;
 
-    /*
-     * get the tab math right for indentations that are not multiples of
-     * tabsize
-     */
-    if (ps.ind_level * opt.indent_size != 0) {
-       ind += ps.ind_level * opt.indent_size;
-       cur_decl_ind += ps.ind_level * opt.indent_size;
-    }
+    if (tabs_to_var)
+       for (int next; (next = next_tab(ind)) <= target_ind; ind = next)
+           buf_add_char(&code, '\t');
 
-    if (tabs_to_var) {
-       for (int next; (next = next_tab(ind)) <= cur_decl_ind; ind = next)
-           buf_add_char(&code, '\t');
-    }
-
-    for (; ind < cur_decl_ind; ind++)
+    for (; ind < target_ind; ind++)
        buf_add_char(&code, ' ');
 
     if (code.e == orig_code_e && ps.want_blank) {



Home | Main Index | Thread Index | Old Index