Module Name: src Committed By: rillig Date: Fri Oct 8 17:07:36 UTC 2021
Modified Files: src/usr.bin/indent: io.c Log Message: indent: replace column calculations with indent, part 2 No functional change. To generate a diff of this commit: cvs rdiff -u -r1.82 -r1.83 src/usr.bin/indent/io.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.82 src/usr.bin/indent/io.c:1.83 --- src/usr.bin/indent/io.c:1.82 Fri Oct 8 17:04:13 2021 +++ src/usr.bin/indent/io.c Fri Oct 8 17:07:36 2021 @@ -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 @@ static char sccsid[] = "@(#)io.c 8.1 (Be #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 @@ dump_line(void) } 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 @@ dump_line(void) } 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++;