Module Name: src Committed By: rillig Date: Fri Oct 8 17:12:08 UTC 2021
Modified Files: src/usr.bin/indent: io.c pr_comment.c Log Message: indent: replace column calculations with indent, part 3 No functional change. To generate a diff of this commit: cvs rdiff -u -r1.83 -r1.84 src/usr.bin/indent/io.c cvs rdiff -u -r1.58 -r1.59 src/usr.bin/indent/pr_comment.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.bin/indent/io.c diff -u src/usr.bin/indent/io.c:1.83 src/usr.bin/indent/io.c:1.84 --- src/usr.bin/indent/io.c:1.83 Fri Oct 8 17:07:36 2021 +++ src/usr.bin/indent/io.c Fri Oct 8 17:12:08 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: io.c,v 1.83 2021/10/08 17:07:36 rillig Exp $ */ +/* $NetBSD: io.c,v 1.84 2021/10/08 17:12:08 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -43,7 +43,7 @@ static char sccsid[] = "@(#)io.c 8.1 (Be #include <sys/cdefs.h> #if defined(__NetBSD__) -__RCSID("$NetBSD: io.c,v 1.83 2021/10/08 17:07:36 rillig Exp $"); +__RCSID("$NetBSD: io.c,v 1.84 2021/10/08 17:12:08 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/io.c 334927 2018-06-10 16:44:18Z pstef $"); #endif @@ -196,22 +196,19 @@ dump_line(void) output_string(".*/\n"); } - int target_col = 1 + compute_code_indent(); + int target_ind = compute_code_indent(); for (int i = 0; i < ps.p_l_follow; i++) { if (ps.paren_indents[i] >= 0) { int ind = ps.paren_indents[i]; - /* - * XXX: this mix of 'indent' and 'column' smells like - * an off-by-one error. - */ - ps.paren_indents[i] = (short)-(ind + target_col); + /* XXX: the '+ 1' smells like an off-by-one error. */ + ps.paren_indents[i] = (short)-(ind + target_ind + 1); debug_println( "setting pi[%d] from %d to %d for column %d", - i, ind, ps.paren_indents[i], target_col); + i, ind, ps.paren_indents[i], target_ind + 1); } } - cur_ind = output_indent(cur_ind, target_col - 1); + cur_ind = output_indent(cur_ind, target_ind); output_range(code.s, code.e); cur_ind = indentation_after(cur_ind, code.s); } Index: src/usr.bin/indent/pr_comment.c diff -u src/usr.bin/indent/pr_comment.c:1.58 src/usr.bin/indent/pr_comment.c:1.59 --- src/usr.bin/indent/pr_comment.c:1.58 Thu Oct 7 23:15:15 2021 +++ src/usr.bin/indent/pr_comment.c Fri Oct 8 17:12:08 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: pr_comment.c,v 1.58 2021/10/07 23:15:15 rillig Exp $ */ +/* $NetBSD: pr_comment.c,v 1.59 2021/10/08 17:12:08 rillig Exp $ */ /*- * SPDX-License-Identifier: BSD-4-Clause @@ -43,7 +43,7 @@ static char sccsid[] = "@(#)pr_comment.c #include <sys/cdefs.h> #if defined(__NetBSD__) -__RCSID("$NetBSD: pr_comment.c,v 1.58 2021/10/07 23:15:15 rillig Exp $"); +__RCSID("$NetBSD: pr_comment.c,v 1.59 2021/10/08 17:12:08 rillig Exp $"); #elif defined(__FreeBSD__) __FBSDID("$FreeBSD: head/usr.bin/indent/pr_comment.c 334927 2018-06-10 16:44:18Z pstef $"); #endif @@ -126,18 +126,18 @@ process_comment(void) } else { break_delim = false; - int target_col; + int target_ind; if (code.s != code.e) - target_col = 1 + indentation_after(compute_code_indent(), code.s); + target_ind = indentation_after(compute_code_indent(), code.s); else if (lab.s != lab.e) - target_col = 1 + indentation_after(compute_label_indent(), lab.s); + target_ind = indentation_after(compute_label_indent(), lab.s); else - target_col = 1; + target_ind = 0; ps.com_col = ps.decl_on_line || ps.ind_level == 0 ? opt.decl_comment_column : opt.comment_column; - if (ps.com_col <= target_col) - ps.com_col = opt.tabsize * (1 + (target_col - 1) / opt.tabsize) + 1; + if (ps.com_col <= target_ind + 1) + ps.com_col = opt.tabsize * (1 + target_ind / opt.tabsize) + 1; if (ps.com_col + 24 > adj_max_line_length) /* XXX: mismatch between column and length */ adj_max_line_length = ps.com_col + 24;