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: turn ps.com_ind into local variable



details:   https://anonhg.NetBSD.org/src/rev/3ca2cb0379f3
branches:  trunk
changeset: 989501:3ca2cb0379f3
user:      rillig <rillig%NetBSD.org@localhost>
date:      Thu Oct 14 20:15:18 2021 +0000

description:
indent: turn ps.com_ind into local variable

This makes it immediately clear that ps.com_ind is computed in the first
part of process_comment and then only used from there.

No functional change.

diffstat:

 usr.bin/indent/pr_comment.c |  25 ++++++++++++++-----------
 1 files changed, 14 insertions(+), 11 deletions(-)

diffs (73 lines):

diff -r 52d8cc3054b7 -r 3ca2cb0379f3 usr.bin/indent/pr_comment.c
--- a/usr.bin/indent/pr_comment.c       Thu Oct 14 20:00:59 2021 +0000
+++ b/usr.bin/indent/pr_comment.c       Thu Oct 14 20:15:18 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pr_comment.c,v 1.77 2021/10/13 22:38:02 rillig Exp $   */
+/*     $NetBSD: pr_comment.c,v 1.78 2021/10/14 20:15:18 rillig Exp $   */
 
 /*-
  * SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__NetBSD__)
-__RCSID("$NetBSD: pr_comment.c,v 1.77 2021/10/13 22:38:02 rillig Exp $");
+__RCSID("$NetBSD: pr_comment.c,v 1.78 2021/10/14 20:15:18 rillig Exp $");
 #elif defined(__FreeBSD__)
 __FBSDID("$FreeBSD: head/usr.bin/indent/pr_comment.c 334927 2018-06-10 16:44:18Z pstef $");
 #endif
@@ -125,6 +125,7 @@
     ssize_t last_blank;                /* index of the last blank in com.buf */
     bool break_delim = opt.comment_delimiter_on_blankline;
     int l_just_saw_decl = ps.just_saw_decl;
+    int com_ind;
 
     adj_max_line_length = opt.max_line_length;
     ps.just_saw_decl = 0;
@@ -137,7 +138,7 @@
     if (ps.col_1 && !opt.format_col1_comments) {
        may_wrap = false;
        break_delim = false;
-       ps.com_ind = 0;
+       com_ind = 0;
 
     } else {
        if (*inp.s == '-' || *inp.s == '*' || token.e[-1] == '/' ||
@@ -147,10 +148,10 @@
        }
 
        if (lab.s == lab.e && code.s == code.e) {
-           ps.com_ind = (ps.ind_level - opt.unindent_displace) * opt.indent_size;
+           com_ind = (ps.ind_level - opt.unindent_displace) * opt.indent_size;
            adj_max_line_length = opt.block_comment_max_line_length;
-           if (ps.com_ind <= 0)
-               ps.com_ind = opt.format_col1_comments ? 0 : 1;
+           if (com_ind <= 0)
+               com_ind = opt.format_col1_comments ? 0 : 1;
 
        } else {
            break_delim = false;
@@ -163,16 +164,18 @@
            else
                target_ind = 0;
 
-           ps.com_ind = ps.decl_on_line || ps.ind_level == 0
+           com_ind = ps.decl_on_line || ps.ind_level == 0
                ? opt.decl_comment_column - 1 : opt.comment_column - 1;
-           if (ps.com_ind <= target_ind)
-               ps.com_ind = next_tab(target_ind);
+           if (com_ind <= target_ind)
+               com_ind = next_tab(target_ind);
            /* XXX: the '+ 1' smells like an off-by-one error */
-           if (ps.com_ind + 1 + 24 > adj_max_line_length)
-               adj_max_line_length = ps.com_ind + 1 + 24;
+           if (com_ind + 1 + 24 > adj_max_line_length)
+               adj_max_line_length = com_ind + 1 + 24;
        }
     }
 
+    ps.com_ind = com_ind;
+
     if (!may_wrap) {
        /*
         * Find out how much indentation there was originally, because that



Home | Main Index | Thread Index | Old Index