| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: io.c,v 1.43 2021/03/13 13:51:08 rillig Exp $ */ | | 1 | /* $NetBSD: io.c,v 1.44 2021/03/13 13:54:01 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 |
| @@ -36,27 +36,27 @@ | | | @@ -36,27 +36,27 @@ |
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 |
41 | #ifndef lint | | 41 | #ifndef lint |
42 | static char sccsid[] = "@(#)io.c 8.1 (Berkeley) 6/6/93"; | | 42 | static char sccsid[] = "@(#)io.c 8.1 (Berkeley) 6/6/93"; |
43 | #endif /* not lint */ | | 43 | #endif /* not lint */ |
44 | #endif | | 44 | #endif |
45 | | | 45 | |
46 | #include <sys/cdefs.h> | | 46 | #include <sys/cdefs.h> |
47 | #ifndef lint | | 47 | #ifndef lint |
48 | #if defined(__NetBSD__) | | 48 | #if defined(__NetBSD__) |
49 | __RCSID("$NetBSD: io.c,v 1.43 2021/03/13 13:51:08 rillig Exp $"); | | 49 | __RCSID("$NetBSD: io.c,v 1.44 2021/03/13 13:54:01 rillig Exp $"); |
50 | #elif defined(__FreeBSD__) | | 50 | #elif defined(__FreeBSD__) |
51 | __FBSDID("$FreeBSD: head/usr.bin/indent/io.c 334927 2018-06-10 16:44:18Z pstef $"); | | 51 | __FBSDID("$FreeBSD: head/usr.bin/indent/io.c 334927 2018-06-10 16:44:18Z pstef $"); |
52 | #endif | | 52 | #endif |
53 | #endif | | 53 | #endif |
54 | | | 54 | |
55 | #include <ctype.h> | | 55 | #include <ctype.h> |
56 | #include <err.h> | | 56 | #include <err.h> |
57 | #include <stdio.h> | | 57 | #include <stdio.h> |
58 | #include <stdlib.h> | | 58 | #include <stdlib.h> |
59 | #include <string.h> | | 59 | #include <string.h> |
60 | #include <stdarg.h> | | 60 | #include <stdarg.h> |
61 | | | 61 | |
62 | #include "indent.h" | | 62 | #include "indent.h" |
| @@ -105,27 +105,27 @@ output_indent(int old_ind, int new_ind) | | | @@ -105,27 +105,27 @@ output_indent(int old_ind, int new_ind) |
105 | | | 105 | |
106 | debug_println("output_indent %d", ind); | | 106 | debug_println("output_indent %d", ind); |
107 | return ind; | | 107 | return ind; |
108 | } | | 108 | } |
109 | | | 109 | |
110 | /* | | 110 | /* |
111 | * dump_line is the routine that actually effects the printing of the new | | 111 | * dump_line is the routine that actually effects the printing of the new |
112 | * source. It prints the label section, followed by the code section with | | 112 | * source. It prints the label section, followed by the code section with |
113 | * the appropriate nesting level, followed by any comments. | | 113 | * the appropriate nesting level, followed by any comments. |
114 | */ | | 114 | */ |
115 | void | | 115 | void |
116 | dump_line(void) | | 116 | dump_line(void) |
117 | { | | 117 | { |
118 | int cur_col, target_col; | | 118 | int cur_col; |
119 | static int not_first_line; | | 119 | static int not_first_line; |
120 | | | 120 | |
121 | if (ps.procname[0]) { | | 121 | if (ps.procname[0]) { |
122 | ps.ind_level = 0; | | 122 | ps.ind_level = 0; |
123 | ps.procname[0] = 0; | | 123 | ps.procname[0] = 0; |
124 | } | | 124 | } |
125 | | | 125 | |
126 | if (s_code == e_code && s_lab == e_lab && s_com == e_com) { | | 126 | if (s_code == e_code && s_lab == e_lab && s_com == e_com) { |
127 | if (suppress_blanklines > 0) | | 127 | if (suppress_blanklines > 0) |
128 | suppress_blanklines--; | | 128 | suppress_blanklines--; |
129 | else { | | 129 | else { |
130 | ps.bl_line = true; | | 130 | ps.bl_line = true; |
131 | n_real_blanklines++; | | 131 | n_real_blanklines++; |
| @@ -185,27 +185,27 @@ dump_line(void) | | | @@ -185,27 +185,27 @@ dump_line(void) |
185 | } else | | 185 | } else |
186 | output_range(s_lab, e_lab); | | 186 | output_range(s_lab, e_lab); |
187 | cur_col = 1 + indentation_after(cur_col - 1, s_lab); | | 187 | cur_col = 1 + indentation_after(cur_col - 1, s_lab); |
188 | } else | | 188 | } else |
189 | cur_col = 1; /* there is no label section */ | | 189 | cur_col = 1; /* there is no label section */ |
190 | | | 190 | |
191 | ps.pcase = false; | | 191 | ps.pcase = false; |
192 | | | 192 | |
193 | if (s_code != e_code) { /* print code section, if any */ | | 193 | if (s_code != e_code) { /* print code section, if any */ |
194 | if (comment_open) { | | 194 | if (comment_open) { |
195 | comment_open = 0; | | 195 | comment_open = 0; |
196 | output_string(".*/\n"); | | 196 | output_string(".*/\n"); |
197 | } | | 197 | } |
198 | target_col = 1 + compute_code_indent(); | | 198 | int target_col = 1 + compute_code_indent(); |
199 | { | | 199 | { |
200 | int i; | | 200 | int i; |
201 | | | 201 | |
202 | for (i = 0; i < ps.p_l_follow; i++) { | | 202 | for (i = 0; i < ps.p_l_follow; i++) { |
203 | if (ps.paren_indents[i] >= 0) { | | 203 | if (ps.paren_indents[i] >= 0) { |
204 | int ind = ps.paren_indents[i]; | | 204 | int ind = ps.paren_indents[i]; |
205 | /* | | 205 | /* |
206 | * XXX: this mix of 'indent' and 'column' smells like | | 206 | * XXX: this mix of 'indent' and 'column' smells like |
207 | * an off-by-one error. | | 207 | * an off-by-one error. |
208 | */ | | 208 | */ |
209 | ps.paren_indents[i] = -(ind + target_col); | | 209 | ps.paren_indents[i] = -(ind + target_col); |
210 | debug_println( | | 210 | debug_println( |
211 | "setting pi[%d] from %d to %d for column %d", | | 211 | "setting pi[%d] from %d to %d for column %d", |