Sun Oct 24 16:51:44 2021 UTC ()
indent: fix line number counting at beginning of function body


(rillig)
diff -r1.6 -r1.7 src/tests/usr.bin/indent/t_misc.sh
diff -r1.146 -r1.147 src/usr.bin/indent/indent.c

cvs diff -r1.6 -r1.7 src/tests/usr.bin/indent/t_misc.sh (expand / switch to unified diff)

--- src/tests/usr.bin/indent/t_misc.sh 2021/10/24 16:46:12 1.6
+++ src/tests/usr.bin/indent/t_misc.sh 2021/10/24 16:51:44 1.7
@@ -1,15 +1,15 @@ @@ -1,15 +1,15 @@
1#! /bin/sh 1#! /bin/sh
2# $NetBSD: t_misc.sh,v 1.6 2021/10/24 16:46:12 rillig Exp $ 2# $NetBSD: t_misc.sh,v 1.7 2021/10/24 16:51:44 rillig Exp $
3# 3#
4# Copyright (c) 2021 The NetBSD Foundation, Inc. 4# Copyright (c) 2021 The NetBSD Foundation, Inc.
5# All rights reserved. 5# All rights reserved.
6# 6#
7# Redistribution and use in source and binary forms, with or without 7# Redistribution and use in source and binary forms, with or without
8# modification, are permitted provided that the following conditions 8# modification, are permitted provided that the following conditions
9# are met: 9# are met:
10# 1. Redistributions of source code must retain the above copyright 10# 1. Redistributions of source code must retain the above copyright
11# notice, this list of conditions and the following disclaimer. 11# notice, this list of conditions and the following disclaimer.
12# 2. Redistributions in binary form must reproduce the above copyright 12# 2. Redistributions in binary form must reproduce the above copyright
13# notice, this list of conditions and the following disclaimer in the 13# notice, this list of conditions and the following disclaimer in the
14# documentation and/or other materials provided with the distribution. 14# documentation and/or other materials provided with the distribution.
15# 15#
@@ -299,36 +299,38 @@ opt_U_body() @@ -299,36 +299,38 @@ opt_U_body()
299 cat <<-\EOF > code.exp 299 cat <<-\EOF > code.exp
300 int known_1 = (size_t)*arg; 300 int known_1 = (size_t)*arg;
301 int known_2 = (off_t)*arg; 301 int known_2 = (off_t)*arg;
302 int ignored = (ignored_t) * arg; 302 int ignored = (ignored_t) * arg;
303 EOF 303 EOF
304 304
305 atf_check -o 'file:code.exp' \ 305 atf_check -o 'file:code.exp' \
306 "$indent" -Ucode.types code.c -di0 -st 306 "$indent" -Ucode.types code.c -di0 -st
307} 307}
308 308
309atf_test_case 'line_no_counting' 309atf_test_case 'line_no_counting'
310line_no_counting_body() 310line_no_counting_body()
311{ 311{
 312 # Before NetBSD indent.c 1.147 from 2021-10-24, indent reported the
 313 # warning in line 2 instead of the correct line 3.
 314
312 cat <<-\EOF > code.c 315 cat <<-\EOF > code.c
313 void line_no_counting(void) 316 void line_no_counting(void)
314 { 317 {
315 ()) 318 ())
316 } 319 }
317 EOF 320 EOF
318 321
319 # FIXME: the wrong ')' is in line 3, not 2. 
320 cat <<-\EOF > code.err 322 cat <<-\EOF > code.err
321 /**INDENT** Warning@2: Extra ) */ 323 /**INDENT** Warning@3: Extra ) */
322 EOF 324 EOF
323 325
324 atf_check -o 'ignore' -e 'file:code.err' \ 326 atf_check -o 'ignore' -e 'file:code.err' \
325 "$indent" code.c -st 327 "$indent" code.c -st
326} 328}
327 329
328atf_init_test_cases() 330atf_init_test_cases()
329{ 331{
330 atf_add_test_case 'in_place' 332 atf_add_test_case 'in_place'
331 atf_add_test_case 'verbose_profile' 333 atf_add_test_case 'verbose_profile'
332 atf_add_test_case 'nested_struct_declarations' 334 atf_add_test_case 'nested_struct_declarations'
333 atf_add_test_case 'option_P_in_profile_file' 335 atf_add_test_case 'option_P_in_profile_file'
334 atf_add_test_case 'opt' 336 atf_add_test_case 'opt'

cvs diff -r1.146 -r1.147 src/usr.bin/indent/indent.c (expand / switch to unified diff)

--- src/usr.bin/indent/indent.c 2021/10/24 11:19:25 1.146
+++ src/usr.bin/indent/indent.c 2021/10/24 16:51:44 1.147
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: indent.c,v 1.146 2021/10/24 11:19:25 rillig Exp $ */ 1/* $NetBSD: indent.c,v 1.147 2021/10/24 16:51:44 rillig Exp $ */
2 2
3/*- 3/*-
4 * SPDX-License-Identifier: BSD-4-Clause 4 * SPDX-License-Identifier: BSD-4-Clause
5 * 5 *
6 * Copyright (c) 1985 Sun Microsystems, Inc. 6 * Copyright (c) 1985 Sun Microsystems, Inc.
7 * Copyright (c) 1976 Board of Trustees of the University of Illinois. 7 * Copyright (c) 1976 Board of Trustees of the University of Illinois.
8 * Copyright (c) 1980, 1993 8 * Copyright (c) 1980, 1993
9 * The Regents of the University of California. All rights reserved. 9 * The Regents of the University of California. All rights reserved.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions 12 * modification, are permitted provided that the following conditions
13 * are met: 13 * are met:
14 * 1. Redistributions of source code must retain the above copyright 14 * 1. Redistributions of source code must retain the above copyright
@@ -33,27 +33,27 @@ @@ -33,27 +33,27 @@
33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 * SUCH DAMAGE. 37 * SUCH DAMAGE.
38 */ 38 */
39 39
40#if 0 40#if 0
41static char sccsid[] = "@(#)indent.c 5.17 (Berkeley) 6/7/93"; 41static char sccsid[] = "@(#)indent.c 5.17 (Berkeley) 6/7/93";
42#endif 42#endif
43 43
44#include <sys/cdefs.h> 44#include <sys/cdefs.h>
45#if defined(__NetBSD__) 45#if defined(__NetBSD__)
46__RCSID("$NetBSD: indent.c,v 1.146 2021/10/24 11:19:25 rillig Exp $"); 46__RCSID("$NetBSD: indent.c,v 1.147 2021/10/24 16:51:44 rillig Exp $");
47#elif defined(__FreeBSD__) 47#elif defined(__FreeBSD__)
48__FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $"); 48__FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
49#endif 49#endif
50 50
51#include <sys/param.h> 51#include <sys/param.h>
52#if HAVE_CAPSICUM 52#if HAVE_CAPSICUM
53#include <sys/capsicum.h> 53#include <sys/capsicum.h>
54#include <capsicum_helpers.h> 54#include <capsicum_helpers.h>
55#endif 55#endif
56#include <ctype.h> 56#include <ctype.h>
57#include <err.h> 57#include <err.h>
58#include <errno.h> 58#include <errno.h>
59#include <fcntl.h> 59#include <fcntl.h>
@@ -140,26 +140,28 @@ init_capsicum(void) @@ -140,26 +140,28 @@ init_capsicum(void)
140} 140}
141#endif 141#endif
142 142
143static void 143static void
144search_brace_newline(bool *force_nl) 144search_brace_newline(bool *force_nl)
145{ 145{
146 if (sc_end == NULL) { 146 if (sc_end == NULL) {
147 save_com = sc_buf; 147 save_com = sc_buf;
148 save_com[0] = save_com[1] = ' '; 148 save_com[0] = save_com[1] = ' ';
149 sc_end = &save_com[2]; 149 sc_end = &save_com[2];
150 } 150 }
151 *sc_end++ = '\n'; 151 *sc_end++ = '\n';
152 152
 153 line_no++;
 154
153 /* 155 /*
154 * We may have inherited a force_nl == true from the previous token (like 156 * We may have inherited a force_nl == true from the previous token (like
155 * a semicolon). But once we know that a newline has been scanned in this 157 * a semicolon). But once we know that a newline has been scanned in this
156 * loop, force_nl should be false. 158 * loop, force_nl should be false.
157 * 159 *
158 * However, the force_nl == true must be preserved if newline is never 160 * However, the force_nl == true must be preserved if newline is never
159 * scanned in this loop, so this assignment cannot be done earlier. 161 * scanned in this loop, so this assignment cannot be done earlier.
160 */ 162 */
161 *force_nl = false; 163 *force_nl = false;
162} 164}
163 165
164static void 166static void
165search_brace_comment(bool *comment_buffered) 167search_brace_comment(bool *comment_buffered)