indent: rename misleading variable The name started with 'line_start', but the value is not always the value from the beginning of the line. No functional change.diff -r1.52 -r1.53 src/usr.bin/indent/debug.c
(rillig)
--- src/usr.bin/indent/debug.c 2023/06/10 20:37:12 1.52
+++ src/usr.bin/indent/debug.c 2023/06/10 21:36:38 1.53
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: debug.c,v 1.52 2023/06/10 20:37:12 rillig Exp $ */ | 1 | /* $NetBSD: debug.c,v 1.53 2023/06/10 21:36:38 rillig Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 2023 The NetBSD Foundation, Inc. | 4 | * Copyright (c) 2023 The NetBSD Foundation, Inc. | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * This code is derived from software contributed to The NetBSD Foundation | 7 | * This code is derived from software contributed to The NetBSD Foundation | |
8 | * by Roland Illig <rillig@NetBSD.org>. | 8 | * by Roland Illig <rillig@NetBSD.org>. | |
9 | * | 9 | * | |
10 | * Redistribution and use in source and binary forms, with or without | 10 | * Redistribution and use in source and binary forms, with or without | |
11 | * modification, are permitted provided that the following conditions | 11 | * modification, are permitted provided that the following conditions | |
12 | * are met: | 12 | * are met: | |
13 | * 1. Redistributions of source code must retain the above copyright | 13 | * 1. Redistributions of source code must retain the above copyright | |
14 | * notice, this list of conditions and the following disclaimer. | 14 | * notice, this list of conditions and the following disclaimer. | |
@@ -20,27 +20,27 @@ | @@ -20,27 +20,27 @@ | |||
20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | 20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | |
21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | |
23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
29 | * POSSIBILITY OF SUCH DAMAGE. | 29 | * POSSIBILITY OF SUCH DAMAGE. | |
30 | */ | 30 | */ | |
31 | 31 | |||
32 | #include <sys/cdefs.h> | 32 | #include <sys/cdefs.h> | |
33 | __RCSID("$NetBSD: debug.c,v 1.52 2023/06/10 20:37:12 rillig Exp $"); | 33 | __RCSID("$NetBSD: debug.c,v 1.53 2023/06/10 21:36:38 rillig Exp $"); | |
34 | 34 | |||
35 | #include <stdarg.h> | 35 | #include <stdarg.h> | |
36 | #include <string.h> | 36 | #include <string.h> | |
37 | 37 | |||
38 | #include "indent.h" | 38 | #include "indent.h" | |
39 | 39 | |||
40 | #ifdef debug | 40 | #ifdef debug | |
41 | 41 | |||
42 | static struct { | 42 | static struct { | |
43 | /*- | 43 | /*- | |
44 | * false show only the changes to the parser state | 44 | * false show only the changes to the parser state | |
45 | * true show unchanged parts of the parser state as well | 45 | * true show unchanged parts of the parser state as well | |
46 | */ | 46 | */ | |
@@ -350,27 +350,27 @@ debug_parser_state(void) | @@ -350,27 +350,27 @@ debug_parser_state(void) | |||
350 | debug_ps_bool(in_stmt_cont); | 350 | debug_ps_bool(in_stmt_cont); | |
351 | debug_ps_int(decl_level); | 351 | debug_ps_int(decl_level); | |
352 | debug_ps_di_stack(); | 352 | debug_ps_di_stack(); | |
353 | debug_ps_bool(decl_indent_done); | 353 | debug_ps_bool(decl_indent_done); | |
354 | debug_ps_int(decl_ind); | 354 | debug_ps_int(decl_ind); | |
355 | debug_ps_bool(tabs_to_var); | 355 | debug_ps_bool(tabs_to_var); | |
356 | debug_ps_enum(extra_expr_indent, extra_expr_indent_name); | 356 | debug_ps_enum(extra_expr_indent, extra_expr_indent_name); | |
357 | 357 | |||
358 | // The parser symbol stack is printed in debug_psyms_stack instead. | 358 | // The parser symbol stack is printed in debug_psyms_stack instead. | |
359 | 359 | |||
360 | state.heading = "spacing inside a statement or declaration"; | 360 | state.heading = "spacing inside a statement or declaration"; | |
361 | debug_ps_bool(next_unary); | 361 | debug_ps_bool(next_unary); | |
362 | debug_ps_bool(want_blank); | 362 | debug_ps_bool(want_blank); | |
363 | debug_ps_int(line_start_nparen); | 363 | debug_ps_int(ind_paren_level); | |
364 | debug_ps_int(nparen); | 364 | debug_ps_int(nparen); | |
365 | debug_ps_paren(); | 365 | debug_ps_paren(); | |
366 | 366 | |||
367 | state.heading = "horizontal spacing for comments"; | 367 | state.heading = "horizontal spacing for comments"; | |
368 | debug_ps_int(comment_delta); | 368 | debug_ps_int(comment_delta); | |
369 | debug_ps_int(n_comment_delta); | 369 | debug_ps_int(n_comment_delta); | |
370 | debug_ps_int(com_ind); | 370 | debug_ps_int(com_ind); | |
371 | 371 | |||
372 | state.heading = "vertical spacing"; | 372 | state.heading = "vertical spacing"; | |
373 | debug_ps_bool(break_after_comma); | 373 | debug_ps_bool(break_after_comma); | |
374 | debug_ps_bool(force_nl); | 374 | debug_ps_bool(force_nl); | |
375 | debug_ps_enum(declaration, declaration_name); | 375 | debug_ps_enum(declaration, declaration_name); | |
376 | debug_ps_bool(blank_line_after_decl); | 376 | debug_ps_bool(blank_line_after_decl); |
--- src/usr.bin/indent/indent.c 2023/06/10 20:37:12 1.356
+++ src/usr.bin/indent/indent.c 2023/06/10 21:36:38 1.357
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: indent.c,v 1.356 2023/06/10 20:37:12 rillig Exp $ */ | 1 | /* $NetBSD: indent.c,v 1.357 2023/06/10 21:36:38 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 | |
@@ -28,27 +28,27 @@ | @@ -28,27 +28,27 @@ | |||
28 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 28 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
29 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 29 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
30 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | 30 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
31 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 31 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
32 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 32 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
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 | #include <sys/cdefs.h> | 40 | #include <sys/cdefs.h> | |
41 | __RCSID("$NetBSD: indent.c,v 1.356 2023/06/10 20:37:12 rillig Exp $"); | 41 | __RCSID("$NetBSD: indent.c,v 1.357 2023/06/10 21:36:38 rillig Exp $"); | |
42 | 42 | |||
43 | #include <sys/param.h> | 43 | #include <sys/param.h> | |
44 | #include <err.h> | 44 | #include <err.h> | |
45 | #include <stdarg.h> | 45 | #include <stdarg.h> | |
46 | #include <stdio.h> | 46 | #include <stdio.h> | |
47 | #include <stdlib.h> | 47 | #include <stdlib.h> | |
48 | #include <string.h> | 48 | #include <string.h> | |
49 | 49 | |||
50 | #include "indent.h" | 50 | #include "indent.h" | |
51 | 51 | |||
52 | struct options opt = { | 52 | struct options opt = { | |
53 | .brace_same_line = true, | 53 | .brace_same_line = true, | |
54 | .comment_delimiter_on_blank_line = true, | 54 | .comment_delimiter_on_blank_line = true, | |
@@ -368,27 +368,27 @@ indent_declarator(int decl_ind, bool tab | @@ -368,27 +368,27 @@ indent_declarator(int decl_ind, bool tab | |||
368 | buf_add_char(&code, ' '); | 368 | buf_add_char(&code, ' '); | |
369 | ps.want_blank = false; | 369 | ps.want_blank = false; | |
370 | } | 370 | } | |
371 | ps.decl_indent_done = true; | 371 | ps.decl_indent_done = true; | |
372 | } | 372 | } | |
373 | 373 | |||
374 | static bool | 374 | static bool | |
375 | is_function_pointer_declaration(void) | 375 | is_function_pointer_declaration(void) | |
376 | { | 376 | { | |
377 | return ps.in_decl | 377 | return ps.in_decl | |
378 | && !ps.in_init | 378 | && !ps.in_init | |
379 | && !ps.decl_indent_done | 379 | && !ps.decl_indent_done | |
380 | && !ps.line_has_func_def | 380 | && !ps.line_has_func_def | |
381 | && ps.line_start_nparen == 0; | 381 | && ps.ind_paren_level == 0; | |
382 | } | 382 | } | |
383 | 383 | |||
384 | static int | 384 | static int | |
385 | process_eof(void) | 385 | process_eof(void) | |
386 | { | 386 | { | |
387 | finish_output(); | 387 | finish_output(); | |
388 | 388 | |||
389 | if (ps.psyms.top > 1) /* check for balanced braces */ | 389 | if (ps.psyms.top > 1) /* check for balanced braces */ | |
390 | diag(1, "Stuff missing from end of file"); | 390 | diag(1, "Stuff missing from end of file"); | |
391 | 391 | |||
392 | return found_err ? EXIT_FAILURE : EXIT_SUCCESS; | 392 | return found_err ? EXIT_FAILURE : EXIT_SUCCESS; | |
393 | } | 393 | } | |
394 | 394 | |||
@@ -570,27 +570,27 @@ process_rparen(void) | @@ -570,27 +570,27 @@ process_rparen(void) | |||
570 | 570 | |||
571 | enum paren_level_cast cast = ps.paren[--ps.nparen].cast; | 571 | enum paren_level_cast cast = ps.paren[--ps.nparen].cast; | |
572 | if (ps.in_func_def_params || (ps.line_has_decl && !ps.in_init)) | 572 | if (ps.in_func_def_params || (ps.line_has_decl && !ps.in_init)) | |
573 | cast = cast_no; | 573 | cast = cast_no; | |
574 | 574 | |||
575 | ps.prev_paren_was_cast = cast == cast_maybe; | 575 | ps.prev_paren_was_cast = cast == cast_maybe; | |
576 | if (cast == cast_maybe) { | 576 | if (cast == cast_maybe) { | |
577 | ps.next_unary = true; | 577 | ps.next_unary = true; | |
578 | ps.want_blank = opt.space_after_cast; | 578 | ps.want_blank = opt.space_after_cast; | |
579 | } else | 579 | } else | |
580 | ps.want_blank = true; | 580 | ps.want_blank = true; | |
581 | 581 | |||
582 | if (code.len == 0) | 582 | if (code.len == 0) | |
583 | ps.line_start_nparen = ps.nparen; | 583 | ps.ind_paren_level = ps.nparen; | |
584 | 584 | |||
585 | unbalanced: | 585 | unbalanced: | |
586 | buf_add_char(&code, token.s[0]); | 586 | buf_add_char(&code, token.s[0]); | |
587 | 587 | |||
588 | if (ps.spaced_expr_psym != psym_0 && ps.nparen == 0) { | 588 | if (ps.spaced_expr_psym != psym_0 && ps.nparen == 0) { | |
589 | if (ps.extra_expr_indent == eei_maybe) | 589 | if (ps.extra_expr_indent == eei_maybe) | |
590 | ps.extra_expr_indent = eei_last; | 590 | ps.extra_expr_indent = eei_last; | |
591 | ps.force_nl = true; | 591 | ps.force_nl = true; | |
592 | ps.next_unary = true; | 592 | ps.next_unary = true; | |
593 | ps.in_stmt_or_decl = false; | 593 | ps.in_stmt_or_decl = false; | |
594 | parse(ps.spaced_expr_psym); | 594 | parse(ps.spaced_expr_psym); | |
595 | ps.spaced_expr_psym = psym_0; | 595 | ps.spaced_expr_psym = psym_0; | |
596 | ps.want_blank = true; | 596 | ps.want_blank = true; | |
@@ -621,27 +621,27 @@ process_lbracket(void) | @@ -621,27 +621,27 @@ process_lbracket(void) | |||
621 | } | 621 | } | |
622 | 622 | |||
623 | static void | 623 | static void | |
624 | process_rbracket(void) | 624 | process_rbracket(void) | |
625 | { | 625 | { | |
626 | if (ps.nparen == 0) { | 626 | if (ps.nparen == 0) { | |
627 | diag(0, "Extra '%c'", *token.s); | 627 | diag(0, "Extra '%c'", *token.s); | |
628 | goto unbalanced; | 628 | goto unbalanced; | |
629 | } | 629 | } | |
630 | --ps.nparen; | 630 | --ps.nparen; | |
631 | 631 | |||
632 | ps.want_blank = true; | 632 | ps.want_blank = true; | |
633 | if (code.len == 0) | 633 | if (code.len == 0) | |
634 | ps.line_start_nparen = ps.nparen; | 634 | ps.ind_paren_level = ps.nparen; | |
635 | 635 | |||
636 | unbalanced: | 636 | unbalanced: | |
637 | buf_add_char(&code, token.s[0]); | 637 | buf_add_char(&code, token.s[0]); | |
638 | } | 638 | } | |
639 | 639 | |||
640 | static void | 640 | static void | |
641 | process_lbrace(void) | 641 | process_lbrace(void) | |
642 | { | 642 | { | |
643 | if (ps.prev_lsym == lsym_rparen && ps.prev_paren_was_cast) { | 643 | if (ps.prev_lsym == lsym_rparen && ps.prev_paren_was_cast) { | |
644 | ps.in_var_decl = true; // XXX: not really | 644 | ps.in_var_decl = true; // XXX: not really | |
645 | ps.in_init = true; | 645 | ps.in_init = true; | |
646 | } | 646 | } | |
647 | 647 | |||
@@ -778,27 +778,27 @@ static void | @@ -778,27 +778,27 @@ static void | |||
778 | process_postfix_op(void) | 778 | process_postfix_op(void) | |
779 | { | 779 | { | |
780 | buf_add_buf(&code, &token); | 780 | buf_add_buf(&code, &token); | |
781 | ps.want_blank = true; | 781 | ps.want_blank = true; | |
782 | } | 782 | } | |
783 | 783 | |||
784 | static void | 784 | static void | |
785 | process_comma(void) | 785 | process_comma(void) | |
786 | { | 786 | { | |
787 | ps.want_blank = code.len > 0; /* only put blank after comma if comma | 787 | ps.want_blank = code.len > 0; /* only put blank after comma if comma | |
788 | * does not start the line */ | 788 | * does not start the line */ | |
789 | 789 | |||
790 | if (ps.in_decl && !ps.line_has_func_def && !ps.in_init && | 790 | if (ps.in_decl && !ps.line_has_func_def && !ps.in_init && | |
791 | !ps.decl_indent_done && ps.line_start_nparen == 0) { | 791 | !ps.decl_indent_done && ps.ind_paren_level == 0) { | |
792 | /* indent leading commas and not the actual identifiers */ | 792 | /* indent leading commas and not the actual identifiers */ | |
793 | indent_declarator(ps.decl_ind - 1, ps.tabs_to_var); | 793 | indent_declarator(ps.decl_ind - 1, ps.tabs_to_var); | |
794 | } | 794 | } | |
795 | 795 | |||
796 | buf_add_char(&code, ','); | 796 | buf_add_char(&code, ','); | |
797 | 797 | |||
798 | if (ps.nparen == 0) { | 798 | if (ps.nparen == 0) { | |
799 | if (ps.init_level == 0) | 799 | if (ps.init_level == 0) | |
800 | ps.in_init = false; | 800 | ps.in_init = false; | |
801 | int typical_varname_length = 8; | 801 | int typical_varname_length = 8; | |
802 | if (ps.break_after_comma && (opt.break_after_comma || | 802 | if (ps.break_after_comma && (opt.break_after_comma || | |
803 | ind_add(compute_code_indent(), code.s, code.len) | 803 | ind_add(compute_code_indent(), code.s, code.len) | |
804 | >= opt.max_line_length - typical_varname_length)) | 804 | >= opt.max_line_length - typical_varname_length)) | |
@@ -834,27 +834,27 @@ process_semicolon(void) | @@ -834,27 +834,27 @@ process_semicolon(void) | |||
834 | if (out.line_kind == lk_stmt_head) | 834 | if (out.line_kind == lk_stmt_head) | |
835 | out.line_kind = lk_other; | 835 | out.line_kind = lk_other; | |
836 | if (ps.decl_level == 0) | 836 | if (ps.decl_level == 0) | |
837 | ps.in_var_decl = false; | 837 | ps.in_var_decl = false; | |
838 | ps.seen_case = false; /* only needs to be reset on error */ | 838 | ps.seen_case = false; /* only needs to be reset on error */ | |
839 | ps.quest_level = 0; /* only needs to be reset on error */ | 839 | ps.quest_level = 0; /* only needs to be reset on error */ | |
840 | if (ps.prev_lsym == lsym_rparen) | 840 | if (ps.prev_lsym == lsym_rparen) | |
841 | ps.in_func_def_params = false; | 841 | ps.in_func_def_params = false; | |
842 | ps.in_init = false; | 842 | ps.in_init = false; | |
843 | ps.init_level = 0; | 843 | ps.init_level = 0; | |
844 | ps.declaration = ps.declaration == decl_begin ? decl_end : decl_no; | 844 | ps.declaration = ps.declaration == decl_begin ? decl_end : decl_no; | |
845 | 845 | |||
846 | if (ps.in_decl && code.len == 0 && !ps.in_init && | 846 | if (ps.in_decl && code.len == 0 && !ps.in_init && | |
847 | !ps.decl_indent_done && ps.line_start_nparen == 0) { | 847 | !ps.decl_indent_done && ps.ind_paren_level == 0) { | |
848 | /* indent stray semicolons in declarations */ | 848 | /* indent stray semicolons in declarations */ | |
849 | indent_declarator(ps.decl_ind - 1, ps.tabs_to_var); | 849 | indent_declarator(ps.decl_ind - 1, ps.tabs_to_var); | |
850 | } | 850 | } | |
851 | 851 | |||
852 | ps.in_decl = ps.decl_level > 0; /* if we were in a first level | 852 | ps.in_decl = ps.decl_level > 0; /* if we were in a first level | |
853 | * structure declaration before, we | 853 | * structure declaration before, we | |
854 | * aren't anymore */ | 854 | * aren't anymore */ | |
855 | 855 | |||
856 | if (ps.nparen > 0 && ps.spaced_expr_psym != psym_for_exprs) { | 856 | if (ps.nparen > 0 && ps.spaced_expr_psym != psym_for_exprs) { | |
857 | /* There were unbalanced parentheses in the statement. It is a | 857 | /* There were unbalanced parentheses in the statement. It is a | |
858 | * bit complicated, because the semicolon might be in a for | 858 | * bit complicated, because the semicolon might be in a for | |
859 | * statement. */ | 859 | * statement. */ | |
860 | diag(1, "Unbalanced parentheses"); | 860 | diag(1, "Unbalanced parentheses"); | |
@@ -905,27 +905,27 @@ process_type_outside_parentheses(void) | @@ -905,27 +905,27 @@ process_type_outside_parentheses(void) | |||
905 | static void | 905 | static void | |
906 | process_word(lexer_symbol lsym) | 906 | process_word(lexer_symbol lsym) | |
907 | { | 907 | { | |
908 | if (ps.in_decl) { | 908 | if (ps.in_decl) { | |
909 | if (lsym == lsym_funcname) { | 909 | if (lsym == lsym_funcname) { | |
910 | ps.in_decl = false; | 910 | ps.in_decl = false; | |
911 | if (opt.procnames_start_line && code.len > 0) | 911 | if (opt.procnames_start_line && code.len > 0) | |
912 | output_line(); | 912 | output_line(); | |
913 | else if (ps.want_blank) | 913 | else if (ps.want_blank) | |
914 | buf_add_char(&code, ' '); | 914 | buf_add_char(&code, ' '); | |
915 | ps.want_blank = false; | 915 | ps.want_blank = false; | |
916 | 916 | |||
917 | } else if (!ps.in_init && !ps.decl_indent_done && | 917 | } else if (!ps.in_init && !ps.decl_indent_done && | |
918 | ps.line_start_nparen == 0) { | 918 | ps.ind_paren_level == 0) { | |
919 | if (opt.decl_indent == 0 | 919 | if (opt.decl_indent == 0 | |
920 | && code.len > 0 && code.s[code.len - 1] == '}') | 920 | && code.len > 0 && code.s[code.len - 1] == '}') | |
921 | ps.decl_ind = ind_add(0, code.s, code.len) + 1; | 921 | ps.decl_ind = ind_add(0, code.s, code.len) + 1; | |
922 | indent_declarator(ps.decl_ind, ps.tabs_to_var); | 922 | indent_declarator(ps.decl_ind, ps.tabs_to_var); | |
923 | ps.want_blank = false; | 923 | ps.want_blank = false; | |
924 | } | 924 | } | |
925 | 925 | |||
926 | } else if (ps.spaced_expr_psym != psym_0 && ps.nparen == 0) { | 926 | } else if (ps.spaced_expr_psym != psym_0 && ps.nparen == 0) { | |
927 | ps.force_nl = true; | 927 | ps.force_nl = true; | |
928 | ps.in_stmt_or_decl = false; | 928 | ps.in_stmt_or_decl = false; | |
929 | ps.next_unary = true; | 929 | ps.next_unary = true; | |
930 | parse(ps.spaced_expr_psym); | 930 | parse(ps.spaced_expr_psym); | |
931 | ps.spaced_expr_psym = psym_0; | 931 | ps.spaced_expr_psym = psym_0; |
--- src/usr.bin/indent/indent.h 2023/06/10 16:43:56 1.187
+++ src/usr.bin/indent/indent.h 2023/06/10 21:36:38 1.188
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: indent.h,v 1.187 2023/06/10 16:43:56 rillig Exp $ */ | 1 | /* $NetBSD: indent.h,v 1.188 2023/06/10 21:36:38 rillig Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * SPDX-License-Identifier: BSD-2-Clause-FreeBSD | 4 | * SPDX-License-Identifier: BSD-2-Clause-FreeBSD | |
5 | * | 5 | * | |
6 | * Copyright (c) 2001 Jens Schweikhardt | 6 | * Copyright (c) 2001 Jens Schweikhardt | |
7 | * All rights reserved. | 7 | * All rights reserved. | |
8 | * | 8 | * | |
9 | * Redistribution and use in source and binary forms, with or without | 9 | * Redistribution and use in source and binary forms, with or without | |
10 | * modification, are permitted provided that the following conditions | 10 | * modification, are permitted provided that the following conditions | |
11 | * are met: | 11 | * are met: | |
12 | * 1. Redistributions of source code must retain the above copyright | 12 | * 1. Redistributions of source code must retain the above copyright | |
13 | * notice, this list of conditions and the following disclaimer. | 13 | * notice, this list of conditions and the following disclaimer. | |
14 | * 2. Redistributions in binary form must reproduce the above copyright | 14 | * 2. Redistributions in binary form must reproduce the above copyright | |
@@ -358,30 +358,29 @@ extern struct parser_state { | @@ -358,30 +358,29 @@ extern struct parser_state { | |||
358 | eei_last | 358 | eei_last | |
359 | } extra_expr_indent; | 359 | } extra_expr_indent; | |
360 | 360 | |||
361 | struct psym_stack psyms; | 361 | struct psym_stack psyms; | |
362 | 362 | |||
363 | /* Spacing inside a statement or declaration */ | 363 | /* Spacing inside a statement or declaration */ | |
364 | 364 | |||
365 | bool next_unary; /* whether the following operator should be | 365 | bool next_unary; /* whether the following operator should be | |
366 | * unary; is used in declarations for '*', as | 366 | * unary; is used in declarations for '*', as | |
367 | * well as in expressions */ | 367 | * well as in expressions */ | |
368 | bool want_blank; /* whether the following token should be | 368 | bool want_blank; /* whether the following token should be | |
369 | * prefixed by a blank. (Said prefixing is | 369 | * prefixed by a blank. (Said prefixing is | |
370 | * ignored in some cases.) */ | 370 | * ignored in some cases.) */ | |
371 | int line_start_nparen; /* the number of parentheses or brackets that | 371 | int ind_paren_level; /* the number of parentheses or brackets that | |
372 | * were open at the beginning of the current | 372 | * is used for indenting a continuation line of | |
373 | * line; used to indent within statements, | 373 | * a declaration, initializer or statement */ | |
374 | * initializers and declarations */ | |||
375 | int nparen; /* the number of parentheses or brackets that | 374 | int nparen; /* the number of parentheses or brackets that | |
376 | * are currently open; used to indent the | 375 | * are currently open; used to indent the | |
377 | * remaining lines of the statement, | 376 | * remaining lines of the statement, | |
378 | * initializer or declaration */ | 377 | * initializer or declaration */ | |
379 | struct paren_level paren[20]; | 378 | struct paren_level paren[20]; | |
380 | 379 | |||
381 | /* Horizontal spacing for comments */ | 380 | /* Horizontal spacing for comments */ | |
382 | 381 | |||
383 | int comment_delta; /* used to set up indentation for all lines of | 382 | int comment_delta; /* used to set up indentation for all lines of | |
384 | * a boxed comment after the first one */ | 383 | * a boxed comment after the first one */ | |
385 | int n_comment_delta; /* remembers how many columns there were before | 384 | int n_comment_delta; /* remembers how many columns there were before | |
386 | * the start of a box comment so that | 385 | * the start of a box comment so that | |
387 | * forthcoming lines of the comment are | 386 | * forthcoming lines of the comment are |
--- src/usr.bin/indent/io.c 2023/06/10 16:43:56 1.216
+++ src/usr.bin/indent/io.c 2023/06/10 21:36:38 1.217
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: io.c,v 1.216 2023/06/10 16:43:56 rillig Exp $ */ | 1 | /* $NetBSD: io.c,v 1.217 2023/06/10 21:36:38 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) 1980, 1993 | 7 | * Copyright (c) 1980, 1993 | |
8 | * The Regents of the University of California. All rights reserved. | 8 | * The Regents of the University of California. All rights reserved. | |
9 | * All rights reserved. | 9 | * 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 | |
@@ -28,27 +28,27 @@ | @@ -28,27 +28,27 @@ | |||
28 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 28 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
29 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 29 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
30 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | 30 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
31 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 31 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
32 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 32 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
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 | #include <sys/cdefs.h> | 40 | #include <sys/cdefs.h> | |
41 | __RCSID("$NetBSD: io.c,v 1.216 2023/06/10 16:43:56 rillig Exp $"); | 41 | __RCSID("$NetBSD: io.c,v 1.217 2023/06/10 21:36:38 rillig Exp $"); | |
42 | 42 | |||
43 | #include <stdio.h> | 43 | #include <stdio.h> | |
44 | 44 | |||
45 | #include "indent.h" | 45 | #include "indent.h" | |
46 | 46 | |||
47 | struct buffer inp; | 47 | struct buffer inp; | |
48 | const char *inp_p; | 48 | const char *inp_p; | |
49 | 49 | |||
50 | struct output_state out; | 50 | struct output_state out; | |
51 | enum indent_enabled indent_enabled; | 51 | enum indent_enabled indent_enabled; | |
52 | static int out_ind; /* width of the line that is being written */ | 52 | static int out_ind; /* width of the line that is being written */ | |
53 | static unsigned newlines = 2; /* the total of written and buffered newlines; | 53 | static unsigned newlines = 2; /* the total of written and buffered newlines; | |
54 | * 0 in the middle of a line, 1 after a single | 54 | * 0 in the middle of a line, 1 after a single | |
@@ -239,42 +239,42 @@ compute_lined_up_code_indent(int base_in | @@ -239,42 +239,42 @@ compute_lined_up_code_indent(int base_in | |||
239 | } | 239 | } | |
240 | 240 | |||
241 | if (ps.extra_expr_indent != eei_no | 241 | if (ps.extra_expr_indent != eei_no | |
242 | && ind == base_ind + opt.indent_size) | 242 | && ind == base_ind + opt.indent_size) | |
243 | ind += opt.continuation_indent; | 243 | ind += opt.continuation_indent; | |
244 | return ind; | 244 | return ind; | |
245 | } | 245 | } | |
246 | 246 | |||
247 | int | 247 | int | |
248 | compute_code_indent(void) | 248 | compute_code_indent(void) | |
249 | { | 249 | { | |
250 | int base_ind = ps.ind_level * opt.indent_size; | 250 | int base_ind = ps.ind_level * opt.indent_size; | |
251 | 251 | |||
252 | if (ps.line_start_nparen == 0) { | 252 | if (ps.ind_paren_level == 0) { | |
253 | if (ps.psyms.top >= 1 | 253 | if (ps.psyms.top >= 1 | |
254 | && ps.psyms.sym[ps.psyms.top - 1] == psym_lbrace_enum) | 254 | && ps.psyms.sym[ps.psyms.top - 1] == psym_lbrace_enum) | |
255 | return base_ind; | 255 | return base_ind; | |
256 | if (ps.in_stmt_cont) | 256 | if (ps.in_stmt_cont) | |
257 | return base_ind + opt.continuation_indent; | 257 | return base_ind + opt.continuation_indent; | |
258 | return base_ind; | 258 | return base_ind; | |
259 | } | 259 | } | |
260 | 260 | |||
261 | if (opt.lineup_to_parens) { | 261 | if (opt.lineup_to_parens) { | |
262 | if (opt.lineup_to_parens_always) | 262 | if (opt.lineup_to_parens_always) | |
263 | return paren_indent; | 263 | return paren_indent; | |
264 | return compute_lined_up_code_indent(base_ind); | 264 | return compute_lined_up_code_indent(base_ind); | |
265 | } | 265 | } | |
266 | 266 | |||
267 | int rel_ind = opt.continuation_indent * ps.line_start_nparen; | 267 | int rel_ind = opt.continuation_indent * ps.ind_paren_level; | |
268 | if (ps.extra_expr_indent != eei_no && rel_ind == opt.indent_size) | 268 | if (ps.extra_expr_indent != eei_no && rel_ind == opt.indent_size) | |
269 | rel_ind += opt.continuation_indent; | 269 | rel_ind += opt.continuation_indent; | |
270 | return base_ind + rel_ind; | 270 | return base_ind + rel_ind; | |
271 | } | 271 | } | |
272 | 272 | |||
273 | static void | 273 | static void | |
274 | output_line_code(void) | 274 | output_line_code(void) | |
275 | { | 275 | { | |
276 | int target_ind = compute_code_indent(); | 276 | int target_ind = compute_code_indent(); | |
277 | for (int i = 0; i < ps.nparen; i++) { | 277 | for (int i = 0; i < ps.nparen; i++) { | |
278 | int paren_ind = ps.paren[i].indent; | 278 | int paren_ind = ps.paren[i].indent; | |
279 | if (paren_ind >= 0) { | 279 | if (paren_ind >= 0) { | |
280 | ps.paren[i].indent = -1 - (paren_ind + target_ind); | 280 | ps.paren[i].indent = -1 - (paren_ind + target_ind); | |
@@ -387,27 +387,27 @@ output_line(void) | @@ -387,27 +387,27 @@ output_line(void) | |||
387 | buf_clear(&com); | 387 | buf_clear(&com); | |
388 | 388 | |||
389 | ps.line_has_decl = ps.in_decl; | 389 | ps.line_has_decl = ps.in_decl; | |
390 | ps.line_has_func_def = false; | 390 | ps.line_has_func_def = false; | |
391 | ps.in_stmt_cont = ps.in_stmt_or_decl | 391 | ps.in_stmt_cont = ps.in_stmt_or_decl | |
392 | && (!ps.in_decl || ps.in_init) | 392 | && (!ps.in_decl || ps.in_init) | |
393 | && ps.init_level == 0; | 393 | && ps.init_level == 0; | |
394 | ps.decl_indent_done = false; | 394 | ps.decl_indent_done = false; | |
395 | if (ps.extra_expr_indent == eei_last) | 395 | if (ps.extra_expr_indent == eei_last) | |
396 | ps.extra_expr_indent = eei_no; | 396 | ps.extra_expr_indent = eei_no; | |
397 | if (!(ps.psyms.sym[ps.psyms.top] == psym_if_expr_stmt_else | 397 | if (!(ps.psyms.sym[ps.psyms.top] == psym_if_expr_stmt_else | |
398 | && ps.nparen > 0)) | 398 | && ps.nparen > 0)) | |
399 | ps.ind_level = ps.ind_level_follow; | 399 | ps.ind_level = ps.ind_level_follow; | |
400 | ps.line_start_nparen = ps.nparen; | 400 | ps.ind_paren_level = ps.nparen; | |
401 | ps.want_blank = false; | 401 | ps.want_blank = false; | |
402 | 402 | |||
403 | if (ps.nparen > 0) { | 403 | if (ps.nparen > 0) { | |
404 | /* TODO: explain what negative indentation means */ | 404 | /* TODO: explain what negative indentation means */ | |
405 | paren_indent = -1 - ps.paren[ps.nparen - 1].indent; | 405 | paren_indent = -1 - ps.paren[ps.nparen - 1].indent; | |
406 | debug_println("paren_indent is now %d", paren_indent); | 406 | debug_println("paren_indent is now %d", paren_indent); | |
407 | } | 407 | } | |
408 | 408 | |||
409 | out.line_kind = lk_other; | 409 | out.line_kind = lk_other; | |
410 | } | 410 | } | |
411 | 411 | |||
412 | void | 412 | void | |
413 | finish_output(void) | 413 | finish_output(void) |