| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: io.c,v 1.44 2021/03/13 13:54:01 rillig Exp $ */ | | 1 | /* $NetBSD: io.c,v 1.45 2021/03/13 13:55:42 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.44 2021/03/13 13:54:01 rillig Exp $"); | | 49 | __RCSID("$NetBSD: io.c,v 1.45 2021/03/13 13:55:42 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" |
| @@ -208,50 +208,50 @@ dump_line(void) | | | @@ -208,50 +208,50 @@ dump_line(void) |
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", |
212 | i, ind, ps.paren_indents[i], target_col); | | 212 | i, ind, ps.paren_indents[i], target_col); |
213 | } | | 213 | } |
214 | } | | 214 | } |
215 | } | | 215 | } |
216 | cur_col = 1 + output_indent(cur_col - 1, target_col - 1); | | 216 | cur_col = 1 + output_indent(cur_col - 1, target_col - 1); |
217 | output_range(s_code, e_code); | | 217 | output_range(s_code, e_code); |
218 | cur_col = 1 + indentation_after(cur_col - 1, s_code); | | 218 | cur_col = 1 + indentation_after(cur_col - 1, s_code); |
219 | } | | 219 | } |
220 | if (s_com != e_com) { /* print comment, if any */ | | 220 | if (s_com != e_com) { /* print comment, if any */ |
221 | int target = ps.com_col; | | 221 | int target_col = ps.com_col; |
222 | char *com_st = s_com; | | 222 | char *com_st = s_com; |
223 | | | 223 | |
224 | target += ps.comment_delta; | | 224 | target_col += ps.comment_delta; |
225 | while (*com_st == '\t') /* consider original indentation in | | 225 | while (*com_st == '\t') /* consider original indentation in |
226 | * case this is a box comment */ | | 226 | * case this is a box comment */ |
227 | com_st++, target += opt.tabsize; | | 227 | com_st++, target_col += opt.tabsize; |
228 | while (target <= 0) | | 228 | while (target_col <= 0) |
229 | if (*com_st == ' ') | | 229 | if (*com_st == ' ') |
230 | target++, com_st++; | | 230 | target_col++, com_st++; |
231 | else if (*com_st == '\t') { | | 231 | else if (*com_st == '\t') { |
232 | target = opt.tabsize * (1 + (target - 1) / opt.tabsize) + 1; | | 232 | target_col = opt.tabsize * (1 + (target_col - 1) / opt.tabsize) + 1; |
233 | com_st++; | | 233 | com_st++; |
234 | } else | | 234 | } else |
235 | target = 1; | | 235 | target_col = 1; |
236 | if (cur_col > target) { /* if comment can't fit on this line, | | 236 | if (cur_col > target_col) { /* if comment can't fit on this line, |
237 | * put it on next line */ | | 237 | * put it on next line */ |
238 | output_char('\n'); | | 238 | output_char('\n'); |
239 | cur_col = 1; | | 239 | cur_col = 1; |
240 | ++ps.out_lines; | | 240 | ++ps.out_lines; |
241 | } | | 241 | } |
242 | while (e_com > com_st && isspace((unsigned char)e_com[-1])) | | 242 | while (e_com > com_st && isspace((unsigned char)e_com[-1])) |
243 | e_com--; | | 243 | e_com--; |
244 | (void)output_indent(cur_col - 1, target - 1); | | 244 | (void)output_indent(cur_col - 1, target_col - 1); |
245 | output_range(com_st, e_com); | | 245 | output_range(com_st, e_com); |
246 | ps.comment_delta = ps.n_comment_delta; | | 246 | ps.comment_delta = ps.n_comment_delta; |
247 | ++ps.com_lines; /* count lines with comments */ | | 247 | ++ps.com_lines; /* count lines with comments */ |
248 | } | | 248 | } |
249 | if (ps.use_ff) | | 249 | if (ps.use_ff) |
250 | output_char('\014'); | | 250 | output_char('\014'); |
251 | else | | 251 | else |
252 | output_char('\n'); | | 252 | output_char('\n'); |
253 | ++ps.out_lines; | | 253 | ++ps.out_lines; |
254 | if (ps.just_saw_decl == 1 && opt.blanklines_after_declarations) { | | 254 | if (ps.just_saw_decl == 1 && opt.blanklines_after_declarations) { |
255 | prefix_blankline_requested = 1; | | 255 | prefix_blankline_requested = 1; |
256 | ps.just_saw_decl = 0; | | 256 | ps.just_saw_decl = 0; |
257 | } else | | 257 | } else |