Sat Mar 13 18:24:56 2021 UTC ()
indent: align comments in indent's own code

No functional change.


(rillig)
diff -r1.45 -r1.46 src/usr.bin/indent/io.c

cvs diff -r1.45 -r1.46 src/usr.bin/indent/io.c (expand / switch to unified diff)

--- src/usr.bin/indent/io.c 2021/03/13 13:55:42 1.45
+++ src/usr.bin/indent/io.c 2021/03/13 18:24:56 1.46
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: io.c,v 1.45 2021/03/13 13:55:42 rillig Exp $ */ 1/* $NetBSD: io.c,v 1.46 2021/03/13 18:24:56 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
42static char sccsid[] = "@(#)io.c 8.1 (Berkeley) 6/6/93"; 42static 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.45 2021/03/13 13:55:42 rillig Exp $"); 49__RCSID("$NetBSD: io.c,v 1.46 2021/03/13 18:24:56 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"
@@ -213,38 +213,38 @@ dump_line(void) @@ -213,38 +213,38 @@ dump_line(void)
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_col = 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_col += 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_col += opt.tabsize; 227 com_st++, target_col += opt.tabsize;
228 while (target_col <= 0) 228 while (target_col <= 0)
229 if (*com_st == ' ') 229 if (*com_st == ' ')
230 target_col++, com_st++; 230 target_col++, com_st++;
231 else if (*com_st == '\t') { 231 else if (*com_st == '\t') {
232 target_col = opt.tabsize * (1 + (target_col - 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_col = 1; 235 target_col = 1;
236 if (cur_col > target_col) { /* 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_col - 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');
@@ -253,34 +253,32 @@ dump_line(void) @@ -253,34 +253,32 @@ dump_line(void)
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
258 prefix_blankline_requested = postfix_blankline_requested; 258 prefix_blankline_requested = postfix_blankline_requested;
259 postfix_blankline_requested = 0; 259 postfix_blankline_requested = 0;
260 } 260 }
261 261
262 /* keep blank lines after '//' comments */ 262 /* keep blank lines after '//' comments */
263 if (e_com - s_com > 1 && s_com[1] == '/') 263 if (e_com - s_com > 1 && s_com[1] == '/')
264 output_range(s_token, e_token); 264 output_range(s_token, e_token);
265 265
266 ps.decl_on_line = ps.in_decl; /* if we are in the middle of a 266 ps.decl_on_line = ps.in_decl; /* if we are in the middle of a declaration,
267 * declaration, remember that fact for 267 * remember that fact for proper comment
268 * proper comment indentation */ 268 * indentation */
269 ps.ind_stmt = ps.in_stmt & ~ps.in_decl; /* next line should be 269 ps.ind_stmt = ps.in_stmt & ~ps.in_decl; /* next line should be indented if
270 * indented if we have not 270 * we have not completed this stmt and if we
271 * completed this stmt and if 271 * are not in the middle of a declaration */
272 * we are not in the middle of 
273 * a declaration */ 
274 ps.use_ff = false; 272 ps.use_ff = false;
275 ps.dumped_decl_indent = 0; 273 ps.dumped_decl_indent = 0;
276 *(e_lab = s_lab) = '\0'; /* reset buffers */ 274 *(e_lab = s_lab) = '\0'; /* reset buffers */
277 *(e_code = s_code) = '\0'; 275 *(e_code = s_code) = '\0';
278 *(e_com = s_com = combuf + 1) = '\0'; 276 *(e_com = s_com = combuf + 1) = '\0';
279 ps.ind_level = ps.i_l_follow; 277 ps.ind_level = ps.i_l_follow;
280 ps.paren_level = ps.p_l_follow; 278 ps.paren_level = ps.p_l_follow;
281 if (ps.paren_level > 0) { 279 if (ps.paren_level > 0) {
282 /* TODO: explain what negative indentation means */ 280 /* TODO: explain what negative indentation means */
283 paren_indent = -ps.paren_indents[ps.paren_level - 1]; 281 paren_indent = -ps.paren_indents[ps.paren_level - 1];
284 debug_println("paren_indent is now %d", paren_indent); 282 debug_println("paren_indent is now %d", paren_indent);
285 } 283 }
286 not_first_line = 1; 284 not_first_line = 1;