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 column calculations with inde...



details:   https://anonhg.NetBSD.org/src/rev/e76d4ea6da90
branches:  trunk
changeset: 988637:e76d4ea6da90
user:      rillig <rillig%NetBSD.org@localhost>
date:      Fri Oct 08 17:07:36 2021 +0000

description:
indent: replace column calculations with indent, part 2

No functional change.

diffstat:

 usr.bin/indent/io.c |  22 +++++++++++-----------
 1 files changed, 11 insertions(+), 11 deletions(-)

diffs (59 lines):

diff -r 8a2cb74636a5 -r e76d4ea6da90 usr.bin/indent/io.c
--- a/usr.bin/indent/io.c       Fri Oct 08 17:04:13 2021 +0000
+++ b/usr.bin/indent/io.c       Fri Oct 08 17:07:36 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: io.c,v 1.82 2021/10/08 17:04:13 rillig Exp $   */
+/*     $NetBSD: io.c,v 1.83 2021/10/08 17:07:36 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.82 2021/10/08 17:04:13 rillig Exp $");
+__RCSID("$NetBSD: io.c,v 1.83 2021/10/08 17:07:36 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/io.c 334927 2018-06-10 16:44:18Z pstef $");
 #endif
@@ -217,23 +217,23 @@
        }
 
        if (com.s != com.e) {   /* print comment, if any */
-           int target_col = ps.com_col;
+           int target_ind = ps.com_col - 1;
            char *com_st = com.s;
 
-           target_col += ps.comment_delta;
+           target_ind += ps.comment_delta;
            while (*com_st == '\t')     /* consider original indentation in
                                         * case this is a box comment */
-               com_st++, target_col += opt.tabsize;
-           while (target_col <= 0) {
+               com_st++, target_ind += opt.tabsize;
+           while (target_ind < 0) {
                if (*com_st == ' ')
-                   target_col++, com_st++;
+                   target_ind++, com_st++;
                else if (*com_st == '\t') {
-                   target_col = opt.tabsize * (1 + (target_col - 1) / opt.tabsize) + 1;
+                   target_ind = opt.tabsize * (1 + target_ind / opt.tabsize);
                    com_st++;
                } else
-                   target_col = 1;
+                   target_ind = 0;
            }
-           if (cur_ind + 1 > target_col) {     /* if comment can't fit on this line,
+           if (cur_ind > target_ind) { /* if comment can't fit on this line,
                                         * put it on next line */
                output_char('\n');
                cur_ind = 0;
@@ -241,7 +241,7 @@
            }
            while (com.e > com_st && isspace((unsigned char)com.e[-1]))
                com.e--;
-           (void)output_indent(cur_ind, target_col - 1);
+           (void)output_indent(cur_ind, target_ind);
            output_range(com_st, com.e);
            ps.comment_delta = ps.n_comment_delta;
            ps.stats.comment_lines++;



Home | Main Index | Thread Index | Old Index