Sun Mar 14 00:22:16 2021 UTC ()
indent: fix lint warnings

No functional change.


(rillig)
diff -r1.10 -r1.11 src/usr.bin/indent/Makefile
diff -r1.21 -r1.22 src/usr.bin/indent/args.c
diff -r1.58 -r1.59 src/usr.bin/indent/indent.c
diff -r1.47 -r1.48 src/usr.bin/indent/io.c
diff -r1.40 -r1.41 src/usr.bin/indent/lexi.c
diff -r1.30 -r1.31 src/usr.bin/indent/pr_comment.c

cvs diff -r1.10 -r1.11 src/usr.bin/indent/Makefile (expand / switch to unified diff)

--- src/usr.bin/indent/Makefile 2021/03/12 19:11:29 1.10
+++ src/usr.bin/indent/Makefile 2021/03/14 00:22:16 1.11
@@ -1,10 +1,13 @@ @@ -1,10 +1,13 @@
1# $NetBSD: Makefile,v 1.10 2021/03/12 19:11:29 rillig Exp $ 1# $NetBSD: Makefile,v 1.11 2021/03/14 00:22:16 rillig Exp $
2# from: @(#)Makefile 8.1 (Berkeley) 6/6/93 2# from: @(#)Makefile 8.1 (Berkeley) 6/6/93
3 3
4PROG= indent 4PROG= indent
5SRCS= indent.c io.c lexi.c parse.c pr_comment.c args.c 5SRCS= indent.c io.c lexi.c parse.c pr_comment.c args.c
6 6
7CPPFLAGS+= ${DEBUG:D-Ddebug} 7CPPFLAGS+= ${DEBUG:D-Ddebug}
8LINTFLAGS+= -e 8LINTFLAGS+= -e -w
 9
 10# bug in lint; see tests/usr.bin/lint/lint1/msg_168.c
 11LINTFLAGS.lexi.c+= -X 168
9 12
10.include <bsd.prog.mk> 13.include <bsd.prog.mk>

cvs diff -r1.21 -r1.22 src/usr.bin/indent/args.c (expand / switch to unified diff)

--- src/usr.bin/indent/args.c 2021/03/13 13:51:08 1.21
+++ src/usr.bin/indent/args.c 2021/03/14 00:22:16 1.22
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: args.c,v 1.21 2021/03/13 13:51:08 rillig Exp $ */ 1/* $NetBSD: args.c,v 1.22 2021/03/14 00:22:16 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[] = "@(#)args.c 8.1 (Berkeley) 6/6/93"; 42static char sccsid[] = "@(#)args.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: args.c,v 1.21 2021/03/13 13:51:08 rillig Exp $"); 49__RCSID("$NetBSD: args.c,v 1.22 2021/03/14 00:22:16 rillig Exp $");
50#elif defined(__FreeBSD__) 50#elif defined(__FreeBSD__)
51__FBSDID("$FreeBSD: head/usr.bin/indent/args.c 336318 2018-07-15 21:04:21Z pstef $"); 51__FBSDID("$FreeBSD: head/usr.bin/indent/args.c 336318 2018-07-15 21:04:21Z pstef $");
52#endif 52#endif
53#endif 53#endif
54 54
55/* 55/*
56 * Argument scanning and profile reading code. Default parameters are set 56 * Argument scanning and profile reading code. Default parameters are set
57 * here as well. 57 * here as well.
58 */ 58 */
59 59
60#include <ctype.h> 60#include <ctype.h>
61#include <err.h> 61#include <err.h>
62#include <limits.h> 62#include <limits.h>
@@ -202,32 +202,32 @@ set_profile(const char *profile_name) @@ -202,32 +202,32 @@ set_profile(const char *profile_name)
202 scan_profile(f); 202 scan_profile(f);
203 (void) fclose(f); 203 (void) fclose(f);
204 } 204 }
205 option_source = "Command line"; 205 option_source = "Command line";
206} 206}
207 207
208static void 208static void
209scan_profile(FILE *f) 209scan_profile(FILE *f)
210{ 210{
211 int comment_index, i; 211 int comment_index, i;
212 char *p; 212 char *p;
213 char buf[BUFSIZ]; 213 char buf[BUFSIZ];
214 214
215 while (1) { 215 for (;;) {
216 p = buf; 216 p = buf;
217 comment_index = 0; 217 comment_index = 0;
218 while ((i = getc(f)) != EOF) { 218 while ((i = getc(f)) != EOF) {
219 if (i == '*' && !comment_index && p > buf && p[-1] == '/') { 219 if (i == '*' && !comment_index && p > buf && p[-1] == '/') {
220 comment_index = p - buf; 220 comment_index = (int)(p - buf);
221 *p++ = i; 221 *p++ = i;
222 } else if (i == '/' && comment_index && p > buf && p[-1] == '*') { 222 } else if (i == '/' && comment_index && p > buf && p[-1] == '*') {
223 p = buf + comment_index - 1; 223 p = buf + comment_index - 1;
224 comment_index = 0; 224 comment_index = 0;
225 } else if (isspace((unsigned char)i)) { 225 } else if (isspace((unsigned char)i)) {
226 if (p > buf && !comment_index) 226 if (p > buf && !comment_index)
227 break; 227 break;
228 } else { 228 } else {
229 *p++ = i; 229 *p++ = i;
230 } 230 }
231 } 231 }
232 if (p != buf) { 232 if (p != buf) {
233 *p++ = 0; 233 *p++ = 0;
@@ -304,26 +304,27 @@ found: @@ -304,26 +304,27 @@ found:
304 goto need_param; 304 goto need_param;
305 add_typename(param_start); 305 add_typename(param_start);
306 break; 306 break;
307 307
308 case KEY_FILE: 308 case KEY_FILE:
309 if (*param_start == 0) 309 if (*param_start == 0)
310 goto need_param; 310 goto need_param;
311 add_typedefs_from_file(param_start); 311 add_typedefs_from_file(param_start);
312 break; 312 break;
313 313
314 case VERSION: 314 case VERSION:
315 printf("FreeBSD indent %s\n", INDENT_VERSION); 315 printf("FreeBSD indent %s\n", INDENT_VERSION);
316 exit(0); 316 exit(0);
 317 /*NOTREACHED*/
317 318
318 default: 319 default:
319 errx(1, "set_option: internal error: p_special %d", p->p_special); 320 errx(1, "set_option: internal error: p_special %d", p->p_special);
320 } 321 }
321 break; 322 break;
322 323
323 case PRO_BOOL: 324 case PRO_BOOL:
324 if (p->p_special == OFF) 325 if (p->p_special == OFF)
325 *p->p_obj = false; 326 *p->p_obj = false;
326 else 327 else
327 *p->p_obj = true; 328 *p->p_obj = true;
328 break; 329 break;
329 330

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

--- src/usr.bin/indent/indent.c 2021/03/13 18:46:39 1.58
+++ src/usr.bin/indent/indent.c 2021/03/14 00:22:16 1.59
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: indent.c,v 1.58 2021/03/13 18:46:39 rillig Exp $ */ 1/* $NetBSD: indent.c,v 1.59 2021/03/14 00:22:16 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
@@ -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[] = "@(#)indent.c 5.17 (Berkeley) 6/7/93"; 42static char sccsid[] = "@(#)indent.c 5.17 (Berkeley) 6/7/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: indent.c,v 1.58 2021/03/13 18:46:39 rillig Exp $"); 49__RCSID("$NetBSD: indent.c,v 1.59 2021/03/14 00:22:16 rillig Exp $");
50#elif defined(__FreeBSD__) 50#elif defined(__FreeBSD__)
51__FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $"); 51__FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
52#endif 52#endif
53#endif 53#endif
54 54
55#include <sys/param.h> 55#include <sys/param.h>
56#if HAVE_CAPSICUM 56#if HAVE_CAPSICUM
57#include <sys/capsicum.h> 57#include <sys/capsicum.h>
58#include <capsicum_helpers.h> 58#include <capsicum_helpers.h>
59#endif 59#endif
60#include <err.h> 60#include <err.h>
61#include <errno.h> 61#include <errno.h>
62#include <fcntl.h> 62#include <fcntl.h>
@@ -196,36 +196,37 @@ search_brace(token_type *inout_type_code @@ -196,36 +196,37 @@ search_brace(token_type *inout_type_code
196 sc_end = &save_com[2]; 196 sc_end = &save_com[2];
197 } 197 }
198 *sc_end++ = '\n'; 198 *sc_end++ = '\n';
199 /* 199 /*
200 * We may have inherited a force_nl == true from the previous 200 * We may have inherited a force_nl == true from the previous
201 * token (like a semicolon). But once we know that a newline 201 * token (like a semicolon). But once we know that a newline
202 * has been scanned in this loop, force_nl should be false. 202 * has been scanned in this loop, force_nl should be false.
203 * 203 *
204 * However, the force_nl == true must be preserved if newline 204 * However, the force_nl == true must be preserved if newline
205 * is never scanned in this loop, so this assignment cannot be 205 * is never scanned in this loop, so this assignment cannot be
206 * done earlier. 206 * done earlier.
207 */ 207 */
208 *inout_force_nl = false; 208 *inout_force_nl = false;
 209 break;
209 case form_feed: 210 case form_feed:
210 break; 211 break;
211 case comment: 212 case comment:
212 if (sc_end == NULL) { 213 if (sc_end == NULL) {
213 /* 214 /*
214 * Copy everything from the start of the line, because 215 * Copy everything from the start of the line, because
215 * process_comment() will use that to calculate original 216 * process_comment() will use that to calculate original
216 * indentation of a boxed comment. 217 * indentation of a boxed comment.
217 */ 218 */
218 memcpy(sc_buf, in_buffer, buf_ptr - in_buffer - 4); 219 memcpy(sc_buf, in_buffer, (size_t)(buf_ptr - in_buffer) - 4);
219 save_com = sc_buf + (buf_ptr - in_buffer - 4); 220 save_com = sc_buf + (buf_ptr - in_buffer - 4);
220 save_com[0] = save_com[1] = ' '; 221 save_com[0] = save_com[1] = ' ';
221 sc_end = &save_com[2]; 222 sc_end = &save_com[2];
222 } 223 }
223 *inout_comment_buffered = true; 224 *inout_comment_buffered = true;
224 *sc_end++ = '/'; /* copy in start of comment */ 225 *sc_end++ = '/'; /* copy in start of comment */
225 *sc_end++ = '*'; 226 *sc_end++ = '*';
226 for (;;) { /* loop until the end of the comment */ 227 for (;;) { /* loop until the end of the comment */
227 *sc_end = *buf_ptr++; 228 *sc_end = *buf_ptr++;
228 if (buf_ptr >= buf_end) 229 if (buf_ptr >= buf_end)
229 fill_buffer(); 230 fill_buffer();
230 if (*sc_end++ == '*' && *buf_ptr == '/') 231 if (*sc_end++ == '*' && *buf_ptr == '/')
231 break; /* we are at end of comment */ 232 break; /* we are at end of comment */
@@ -522,27 +523,27 @@ main_parse_command_line(int argc, char * @@ -522,27 +523,27 @@ main_parse_command_line(int argc, char *
522 opt.continuation_indent = opt.indent_size; 523 opt.continuation_indent = opt.indent_size;
523} 524}
524 525
525static void 526static void
526main_prepare_parsing(void) 527main_prepare_parsing(void)
527{ 528{
528 fill_buffer(); /* get first batch of stuff into input buffer */ 529 fill_buffer(); /* get first batch of stuff into input buffer */
529 530
530 parse(semicolon); 531 parse(semicolon);
531 532
532 char *p = buf_ptr; 533 char *p = buf_ptr;
533 int col = 1; 534 int col = 1;
534 535
535 while (1) { 536 for (;;) {
536 if (*p == ' ') 537 if (*p == ' ')
537 col++; 538 col++;
538 else if (*p == '\t') 539 else if (*p == '\t')
539 col = opt.tabsize * (1 + (col - 1) / opt.tabsize) + 1; 540 col = opt.tabsize * (1 + (col - 1) / opt.tabsize) + 1;
540 else 541 else
541 break; 542 break;
542 p++; 543 p++;
543 } 544 }
544 if (col > opt.indent_size) 545 if (col > opt.indent_size)
545 ps.ind_level = ps.i_l_follow = col / opt.indent_size; 546 ps.ind_level = ps.i_l_follow = col / opt.indent_size;
546} 547}
547 548
548static void 549static void
@@ -575,27 +576,27 @@ process_comment_in_code(token_type type_ @@ -575,27 +576,27 @@ process_comment_in_code(token_type type_
575 /* we should force a broken line here */ 576 /* we should force a broken line here */
576 if (opt.verbose) 577 if (opt.verbose)
577 diag(0, "Line broken"); 578 diag(0, "Line broken");
578 dump_line(); 579 dump_line();
579 ps.want_blank = false; /* dont insert blank at line start */ 580 ps.want_blank = false; /* dont insert blank at line start */
580 *inout_force_nl = false; 581 *inout_force_nl = false;
581 } 582 }
582 583
583 ps.in_stmt = true; /* turn on flag which causes an extra level of 584 ps.in_stmt = true; /* turn on flag which causes an extra level of
584 * indentation. this is turned off by a ; or 585 * indentation. this is turned off by a ; or
585 * '}' */ 586 * '}' */
586 if (s_com != e_com) { /* the turkey has embedded a comment 587 if (s_com != e_com) { /* the turkey has embedded a comment
587 * in a line. fix it */ 588 * in a line. fix it */
588 int len = e_com - s_com; 589 size_t len = e_com - s_com;
589 590
590 check_size_code(len + 3); 591 check_size_code(len + 3);
591 *e_code++ = ' '; 592 *e_code++ = ' ';
592 memcpy(e_code, s_com, len); 593 memcpy(e_code, s_com, len);
593 e_code += len; 594 e_code += len;
594 *e_code++ = ' '; 595 *e_code++ = ' ';
595 *e_code = '\0'; /* null terminate code sect */ 596 *e_code = '\0'; /* null terminate code sect */
596 ps.want_blank = false; 597 ps.want_blank = false;
597 e_com = s_com; 598 e_com = s_com;
598 } 599 }
599} 600}
600 601
601static void 602static void
@@ -714,39 +715,39 @@ process_unary_op(int dec_ind, int tabs_t @@ -714,39 +715,39 @@ process_unary_op(int dec_ind, int tabs_t
714 /* 715 /*
715 * if this is a unary op in a declaration, we should indent 716 * if this is a unary op in a declaration, we should indent
716 * this token 717 * this token
717 */ 718 */
718 int i; 719 int i;
719 for (i = 0; token[i]; ++i) 720 for (i = 0; token[i]; ++i)
720 /* find length of token */; 721 /* find length of token */;
721 indent_declaration(dec_ind - i, tabs_to_var); 722 indent_declaration(dec_ind - i, tabs_to_var);
722 ps.dumped_decl_indent = true; 723 ps.dumped_decl_indent = true;
723 } else if (ps.want_blank) 724 } else if (ps.want_blank)
724 *e_code++ = ' '; 725 *e_code++ = ' ';
725 726
726 { 727 {
727 int len = e_token - s_token; 728 size_t len = e_token - s_token;
728 729
729 check_size_code(len); 730 check_size_code(len);
730 memcpy(e_code, token, len); 731 memcpy(e_code, token, len);
731 e_code += len; 732 e_code += len;
732 } 733 }
733 ps.want_blank = false; 734 ps.want_blank = false;
734} 735}
735 736
736static void 737static void
737process_binary_op(void) 738process_binary_op(void)
738{ 739{
739 int len = e_token - s_token; 740 size_t len = e_token - s_token;
740 741
741 check_size_code(len + 1); 742 check_size_code(len + 1);
742 if (ps.want_blank) 743 if (ps.want_blank)
743 *e_code++ = ' '; 744 *e_code++ = ' ';
744 memcpy(e_code, token, len); 745 memcpy(e_code, token, len);
745 e_code += len; 746 e_code += len;
746 747
747 ps.want_blank = true; 748 ps.want_blank = true;
748} 749}
749 750
750static void 751static void
751process_postfix_op(void) 752process_postfix_op(void)
752{ 753{
@@ -779,27 +780,27 @@ process_colon(int *inout_squest, int *in @@ -779,27 +780,27 @@ process_colon(int *inout_squest, int *in
779 return; 780 return;
780 } 781 }
781 if (ps.in_or_st) { 782 if (ps.in_or_st) {
782 *e_code++ = ':'; 783 *e_code++ = ':';
783 ps.want_blank = false; 784 ps.want_blank = false;
784 return; 785 return;
785 } 786 }
786 ps.in_stmt = false; /* seeing a label does not imply we are in a 787 ps.in_stmt = false; /* seeing a label does not imply we are in a
787 * stmt */ 788 * stmt */
788 /* 789 /*
789 * turn everything so far into a label 790 * turn everything so far into a label
790 */ 791 */
791 { 792 {
792 int len = e_code - s_code; 793 size_t len = e_code - s_code;
793 794
794 check_size_label(len + 3); 795 check_size_label(len + 3);
795 memcpy(e_lab, s_code, len); 796 memcpy(e_lab, s_code, len);
796 e_lab += len; 797 e_lab += len;
797 *e_lab++ = ':'; 798 *e_lab++ = ':';
798 *e_lab = '\0'; 799 *e_lab = '\0';
799 e_code = s_code; 800 e_code = s_code;
800 } 801 }
801 *inout_force_nl = ps.pcase = *inout_scase; /* ps.pcase will be used by 802 *inout_force_nl = ps.pcase = *inout_scase; /* ps.pcase will be used by
802 * dump_line to decide how to 803 * dump_line to decide how to
803 * indent the label. force_nl 804 * indent the label. force_nl
804 * will force a case n: to be 805 * will force a case n: to be
805 * on a line by itself */ 806 * on a line by itself */
@@ -1056,39 +1057,39 @@ process_ident(token_type type_code, int  @@ -1056,39 +1057,39 @@ process_ident(token_type type_code, int
1056 } 1057 }
1057 } else if (*inout_sp_sw && ps.p_l_follow == 0) { 1058 } else if (*inout_sp_sw && ps.p_l_follow == 0) {
1058 *inout_sp_sw = false; 1059 *inout_sp_sw = false;
1059 *inout_force_nl = true; 1060 *inout_force_nl = true;
1060 ps.last_u_d = true; 1061 ps.last_u_d = true;
1061 ps.in_stmt = false; 1062 ps.in_stmt = false;
1062 parse(hd_type); 1063 parse(hd_type);
1063 } 1064 }
1064} 1065}
1065 1066
1066static void 1067static void
1067copy_id(void) 1068copy_id(void)
1068{ 1069{
1069 int len = e_token - s_token; 1070 size_t len = e_token - s_token;
1070 1071
1071 check_size_code(len + 1); 1072 check_size_code(len + 1);
1072 if (ps.want_blank) 1073 if (ps.want_blank)
1073 *e_code++ = ' '; 1074 *e_code++ = ' ';
1074 memcpy(e_code, s_token, len); 1075 memcpy(e_code, s_token, len);
1075 e_code += len; 1076 e_code += len;
1076} 1077}
1077 1078
1078static void 1079static void
1079process_string_prefix(void) 1080process_string_prefix(void)
1080{ 1081{
1081 int len = e_token - s_token; 1082 size_t len = e_token - s_token;
1082 1083
1083 check_size_code(len + 1); 1084 check_size_code(len + 1);
1084 if (ps.want_blank) 1085 if (ps.want_blank)
1085 *e_code++ = ' '; 1086 *e_code++ = ' ';
1086 memcpy(e_code, token, len); 1087 memcpy(e_code, token, len);
1087 e_code += len; 1088 e_code += len;
1088 1089
1089 ps.want_blank = false; 1090 ps.want_blank = false;
1090} 1091}
1091 1092
1092static void 1093static void
1093process_period(void) 1094process_period(void)
1094{ 1095{
@@ -1145,46 +1146,46 @@ process_preprocessing(void) @@ -1145,46 +1146,46 @@ process_preprocessing(void)
1145 fill_buffer(); 1146 fill_buffer();
1146 switch (*e_lab++) { 1147 switch (*e_lab++) {
1147 case '\\': 1148 case '\\':
1148 if (!in_comment) { 1149 if (!in_comment) {
1149 *e_lab++ = *buf_ptr++; 1150 *e_lab++ = *buf_ptr++;
1150 if (buf_ptr >= buf_end) 1151 if (buf_ptr >= buf_end)
1151 fill_buffer(); 1152 fill_buffer();
1152 } 1153 }
1153 break; 1154 break;
1154 case '/': 1155 case '/':
1155 if (*buf_ptr == '*' && !in_comment && quote == '\0') { 1156 if (*buf_ptr == '*' && !in_comment && quote == '\0') {
1156 in_comment = 1; 1157 in_comment = 1;
1157 *e_lab++ = *buf_ptr++; 1158 *e_lab++ = *buf_ptr++;
1158 com_start = e_lab - s_lab - 2; 1159 com_start = (int)(e_lab - s_lab) - 2;
1159 } 1160 }
1160 break; 1161 break;
1161 case '"': 1162 case '"':
1162 if (quote == '"') 1163 if (quote == '"')
1163 quote = '\0'; 1164 quote = '\0';
1164 else if (quote == '\0') 1165 else if (quote == '\0')
1165 quote = '"'; 1166 quote = '"';
1166 break; 1167 break;
1167 case '\'': 1168 case '\'':
1168 if (quote == '\'') 1169 if (quote == '\'')
1169 quote = '\0'; 1170 quote = '\0';
1170 else if (quote == '\0') 1171 else if (quote == '\0')
1171 quote = '\''; 1172 quote = '\'';
1172 break; 1173 break;
1173 case '*': 1174 case '*':
1174 if (*buf_ptr == '/' && in_comment) { 1175 if (*buf_ptr == '/' && in_comment) {
1175 in_comment = 0; 1176 in_comment = 0;
1176 *e_lab++ = *buf_ptr++; 1177 *e_lab++ = *buf_ptr++;
1177 com_end = e_lab - s_lab; 1178 com_end = (int)(e_lab - s_lab);
1178 } 1179 }
1179 break; 1180 break;
1180 } 1181 }
1181 } 1182 }
1182 1183
1183 while (e_lab > s_lab && (e_lab[-1] == ' ' || e_lab[-1] == '\t')) 1184 while (e_lab > s_lab && (e_lab[-1] == ' ' || e_lab[-1] == '\t'))
1184 e_lab--; 1185 e_lab--;
1185 if (e_lab - s_lab == com_end && bp_save == NULL) { 1186 if (e_lab - s_lab == com_end && bp_save == NULL) {
1186 /* comment on preprocessor line */ 1187 /* comment on preprocessor line */
1187 if (sc_end == NULL) { /* if this is the first comment, 1188 if (sc_end == NULL) { /* if this is the first comment,
1188 * we must set up the buffer */ 1189 * we must set up the buffer */
1189 save_com = sc_buf; 1190 save_com = sc_buf;
1190 sc_end = &save_com[0]; 1191 sc_end = &save_com[0];
@@ -1284,27 +1285,27 @@ main_loop(void) @@ -1284,27 +1285,27 @@ main_loop(void)
1284 int squest; /* when this is positive, we have seen a ? 1285 int squest; /* when this is positive, we have seen a ?
1285 * without the matching : in a <c>?<s>:<s> 1286 * without the matching : in a <c>?<s>:<s>
1286 * construct */ 1287 * construct */
1287 int scase; /* set to true when we see a case, so we will 1288 int scase; /* set to true when we see a case, so we will
1288 * know what to do with the following colon */ 1289 * know what to do with the following colon */
1289 1290
1290 sp_sw = force_nl = false; 1291 sp_sw = force_nl = false;
1291 dec_ind = 0; 1292 dec_ind = 0;
1292 di_stack[ps.dec_nest = 0] = 0; 1293 di_stack[ps.dec_nest = 0] = 0;
1293 scase = false; 1294 scase = false;
1294 squest = 0; 1295 squest = 0;
1295 tabs_to_var = 0; 1296 tabs_to_var = 0;
1296 1297
1297 while (1) { /* this is the main loop. it will go until we 1298 for (;;) { /* this is the main loop. it will go until we
1298 * reach eof */ 1299 * reach eof */
1299 int comment_buffered = false; 1300 int comment_buffered = false;
1300 1301
1301 type_code = lexi(&ps); /* lexi reads one token. The actual 1302 type_code = lexi(&ps); /* lexi reads one token. The actual
1302 * characters read are stored in "token". lexi 1303 * characters read are stored in "token". lexi
1303 * returns a code indicating the type of token */ 1304 * returns a code indicating the type of token */
1304 1305
1305 /* 1306 /*
1306 * The following code moves newlines and comments following an if (), 1307 * The following code moves newlines and comments following an if (),
1307 * while (), else, etc. up to the start of the following stmt to 1308 * while (), else, etc. up to the start of the following stmt to
1308 * a buffer. This allows proper handling of both kinds of brace 1309 * a buffer. This allows proper handling of both kinds of brace
1309 * placement (-br, -bl) and cuddling "else" (-ce). 1310 * placement (-br, -bl) and cuddling "else" (-ce).
1310 */ 1311 */
@@ -1374,27 +1375,27 @@ main_loop(void) @@ -1374,27 +1375,27 @@ main_loop(void)
1374 goto copy_id; 1375 goto copy_id;
1375 1376
1376 case colon: /* got a ':' */ 1377 case colon: /* got a ':' */
1377 process_colon(&squest, &force_nl, &scase); 1378 process_colon(&squest, &force_nl, &scase);
1378 break; 1379 break;
1379 1380
1380 case semicolon: /* got a ';' */ 1381 case semicolon: /* got a ';' */
1381 process_semicolon(&scase, &squest, dec_ind, tabs_to_var, &sp_sw, 1382 process_semicolon(&scase, &squest, dec_ind, tabs_to_var, &sp_sw,
1382 hd_type, &force_nl); 1383 hd_type, &force_nl);
1383 break; 1384 break;
1384 1385
1385 case lbrace: /* got a '{' */ 1386 case lbrace: /* got a '{' */
1386 process_lbrace(&force_nl, &sp_sw, hd_type, di_stack, 1387 process_lbrace(&force_nl, &sp_sw, hd_type, di_stack,
1387 nitems(di_stack), &dec_ind); 1388 (int)nitems(di_stack), &dec_ind);
1388 break; 1389 break;
1389 1390
1390 case rbrace: /* got a '}' */ 1391 case rbrace: /* got a '}' */
1391 process_rbrace(&sp_sw, &dec_ind, di_stack); 1392 process_rbrace(&sp_sw, &dec_ind, di_stack);
1392 break; 1393 break;
1393 1394
1394 case switch_expr: /* got keyword "switch" */ 1395 case switch_expr: /* got keyword "switch" */
1395 sp_sw = true; 1396 sp_sw = true;
1396 hd_type = switch_expr; /* keep this for when we have seen the 1397 hd_type = switch_expr; /* keep this for when we have seen the
1397 * expression */ 1398 * expression */
1398 goto copy_id; /* go move the token into buffer */ 1399 goto copy_id; /* go move the token into buffer */
1399 1400
1400 case keyword_for_if_while: 1401 case keyword_for_if_while:
@@ -1474,67 +1475,67 @@ main(int argc, char **argv) @@ -1474,67 +1475,67 @@ main(int argc, char **argv)
1474#endif 1475#endif
1475 main_prepare_parsing(); 1476 main_prepare_parsing();
1476 main_loop(); 1477 main_loop();
1477} 1478}
1478 1479
1479/* 1480/*
1480 * copy input file to backup file if in_name is /blah/blah/blah/file, then 1481 * copy input file to backup file if in_name is /blah/blah/blah/file, then
1481 * backup file will be ".Bfile" then make the backup file the input and 1482 * backup file will be ".Bfile" then make the backup file the input and
1482 * original input file the output 1483 * original input file the output
1483 */ 1484 */
1484static void 1485static void
1485bakcopy(void) 1486bakcopy(void)
1486{ 1487{
1487 int n, 1488 ssize_t n;
1488 bakchn; 1489 int bakchn;
1489 char buff[8 * 1024]; 1490 char buff[8 * 1024];
1490 const char *p; 1491 const char *p;
1491 1492
1492 /* construct file name .Bfile */ 1493 /* construct file name .Bfile */
1493 for (p = in_name; *p; p++); /* skip to end of string */ 1494 for (p = in_name; *p; p++); /* skip to end of string */
1494 while (p > in_name && *p != '/') /* find last '/' */ 1495 while (p > in_name && *p != '/') /* find last '/' */
1495 p--; 1496 p--;
1496 if (*p == '/') 1497 if (*p == '/')
1497 p++; 1498 p++;
1498 sprintf(bakfile, "%s%s", p, simple_backup_suffix); 1499 sprintf(bakfile, "%s%s", p, simple_backup_suffix);
1499 1500
1500 /* copy in_name to backup file */ 1501 /* copy in_name to backup file */
1501 bakchn = creat(bakfile, 0600); 1502 bakchn = creat(bakfile, 0600);
1502 if (bakchn < 0) 1503 if (bakchn < 0)
1503 err(1, "%s", bakfile); 1504 err(1, "%s", bakfile);
1504 while ((n = read(fileno(input), buff, sizeof(buff))) > 0) 1505 while ((n = read(fileno(input), buff, sizeof(buff))) > 0)
1505 if (write(bakchn, buff, n) != n) 1506 if (write(bakchn, buff, (size_t)n) != n)
1506 err(1, "%s", bakfile); 1507 err(1, "%s", bakfile);
1507 if (n < 0) 1508 if (n < 0)
1508 err(1, "%s", in_name); 1509 err(1, "%s", in_name);
1509 close(bakchn); 1510 close(bakchn);
1510 fclose(input); 1511 fclose(input);
1511 1512
1512 /* re-open backup file as the input file */ 1513 /* re-open backup file as the input file */
1513 input = fopen(bakfile, "r"); 1514 input = fopen(bakfile, "r");
1514 if (input == NULL) 1515 if (input == NULL)
1515 err(1, "%s", bakfile); 1516 err(1, "%s", bakfile);
1516 /* now the original input file will be the output */ 1517 /* now the original input file will be the output */
1517 output = fopen(in_name, "w"); 1518 output = fopen(in_name, "w");
1518 if (output == NULL) { 1519 if (output == NULL) {
1519 unlink(bakfile); 1520 unlink(bakfile);
1520 err(1, "%s", in_name); 1521 err(1, "%s", in_name);
1521 } 1522 }
1522} 1523}
1523 1524
1524static void 1525static void
1525indent_declaration(int cur_dec_ind, int tabs_to_var) 1526indent_declaration(int cur_dec_ind, int tabs_to_var)
1526{ 1527{
1527 int pos = e_code - s_code; 1528 int pos = (int)(e_code - s_code);
1528 char *startpos = e_code; 1529 char *startpos = e_code;
1529 1530
1530 /* 1531 /*
1531 * get the tab math right for indentations that are not multiples of tabsize 1532 * get the tab math right for indentations that are not multiples of tabsize
1532 */ 1533 */
1533 if ((ps.ind_level * opt.indent_size) % opt.tabsize != 0) { 1534 if ((ps.ind_level * opt.indent_size) % opt.tabsize != 0) {
1534 pos += (ps.ind_level * opt.indent_size) % opt.tabsize; 1535 pos += (ps.ind_level * opt.indent_size) % opt.tabsize;
1535 cur_dec_ind += (ps.ind_level * opt.indent_size) % opt.tabsize; 1536 cur_dec_ind += (ps.ind_level * opt.indent_size) % opt.tabsize;
1536 } 1537 }
1537 if (tabs_to_var) { 1538 if (tabs_to_var) {
1538 int tpos; 1539 int tpos;
1539 1540
1540 check_size_code(cur_dec_ind / opt.tabsize); 1541 check_size_code(cur_dec_ind / opt.tabsize);

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

--- src/usr.bin/indent/io.c 2021/03/13 18:46:39 1.47
+++ src/usr.bin/indent/io.c 2021/03/14 00:22:16 1.48
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: io.c,v 1.47 2021/03/13 18:46:39 rillig Exp $ */ 1/* $NetBSD: io.c,v 1.48 2021/03/14 00:22:16 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.47 2021/03/13 18:46:39 rillig Exp $"); 49__RCSID("$NetBSD: io.c,v 1.48 2021/03/14 00:22:16 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"
@@ -343,28 +343,28 @@ fill_buffer(void) @@ -343,28 +343,28 @@ fill_buffer(void)
343 FILE *f = input; 343 FILE *f = input;
344 344
345 if (bp_save != NULL) { /* there is a partly filled input buffer left */ 345 if (bp_save != NULL) { /* there is a partly filled input buffer left */
346 buf_ptr = bp_save; /* do not read anything, just switch buffers */ 346 buf_ptr = bp_save; /* do not read anything, just switch buffers */
347 buf_end = be_save; 347 buf_end = be_save;
348 bp_save = be_save = NULL; 348 bp_save = be_save = NULL;
349 debug_println("switched buf_ptr back to bp_save"); 349 debug_println("switched buf_ptr back to bp_save");
350 if (buf_ptr < buf_end) 350 if (buf_ptr < buf_end)
351 return; /* only return if there is really something in 351 return; /* only return if there is really something in
352 * this buffer */ 352 * this buffer */
353 } 353 }
354 for (p = in_buffer;;) { 354 for (p = in_buffer;;) {
355 if (p >= in_buffer_limit) { 355 if (p >= in_buffer_limit) {
356 int size = (in_buffer_limit - in_buffer) * 2 + 10; 356 size_t size = (in_buffer_limit - in_buffer) * 2 + 10;
357 int offset = p - in_buffer; 357 size_t offset = p - in_buffer;
358 in_buffer = realloc(in_buffer, size); 358 in_buffer = realloc(in_buffer, size);
359 if (in_buffer == NULL) 359 if (in_buffer == NULL)
360 errx(1, "input line too long"); 360 errx(1, "input line too long");
361 p = in_buffer + offset; 361 p = in_buffer + offset;
362 in_buffer_limit = in_buffer + size - 2; 362 in_buffer_limit = in_buffer + size - 2;
363 } 363 }
364 if ((i = getc(f)) == EOF) { 364 if ((i = getc(f)) == EOF) {
365 *p++ = ' '; 365 *p++ = ' ';
366 *p++ = '\n'; 366 *p++ = '\n';
367 had_eof = true; 367 had_eof = true;
368 break; 368 break;
369 } 369 }
370 if (i != '\0') 370 if (i != '\0')

cvs diff -r1.40 -r1.41 src/usr.bin/indent/lexi.c (expand / switch to unified diff)

--- src/usr.bin/indent/lexi.c 2021/03/13 11:27:01 1.40
+++ src/usr.bin/indent/lexi.c 2021/03/14 00:22:16 1.41
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: lexi.c,v 1.40 2021/03/13 11:27:01 rillig Exp $ */ 1/* $NetBSD: lexi.c,v 1.41 2021/03/14 00:22:16 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[] = "@(#)lexi.c 8.1 (Berkeley) 6/6/93"; 42static char sccsid[] = "@(#)lexi.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: lexi.c,v 1.40 2021/03/13 11:27:01 rillig Exp $"); 49__RCSID("$NetBSD: lexi.c,v 1.41 2021/03/14 00:22:16 rillig Exp $");
50#elif defined(__FreeBSD__) 50#elif defined(__FreeBSD__)
51__FBSDID("$FreeBSD: head/usr.bin/indent/lexi.c 337862 2018-08-15 18:19:45Z pstef $"); 51__FBSDID("$FreeBSD: head/usr.bin/indent/lexi.c 337862 2018-08-15 18:19:45Z pstef $");
52#endif 52#endif
53#endif 53#endif
54 54
55/* 55/*
56 * Here we have the token scanner for indent. It scans off one token and puts 56 * Here we have the token scanner for indent. It scans off one token and puts
57 * it in the global variable "token". It returns a code, indicating the type 57 * it in the global variable "token". It returns a code, indicating the type
58 * of token scanned. 58 * of token scanned.
59 */ 59 */
60 60
61#include <assert.h> 61#include <assert.h>
62#include <err.h> 62#include <err.h>
@@ -471,27 +471,27 @@ lexi(struct parser_state *state) @@ -471,27 +471,27 @@ lexi(struct parser_state *state)
471 state->last_nl = true; /* remember that we just had a newline */ 471 state->last_nl = true; /* remember that we just had a newline */
472 code = (had_eof ? end_of_file : newline); 472 code = (had_eof ? end_of_file : newline);
473 473
474 /* 474 /*
475 * if data has been exhausted, the newline is a dummy, and we should 475 * if data has been exhausted, the newline is a dummy, and we should
476 * return code to stop 476 * return code to stop
477 */ 477 */
478 break; 478 break;
479 479
480 case '\'': /* start of quoted character */ 480 case '\'': /* start of quoted character */
481 case '"': /* start of string */ 481 case '"': /* start of string */
482 qchar = *token; 482 qchar = *token;
483 do { /* copy the string */ 483 do { /* copy the string */
484 while (1) { /* move one character or [/<char>]<char> */ 484 for (;;) { /* move one character or [/<char>]<char> */
485 if (*buf_ptr == '\n') { 485 if (*buf_ptr == '\n') {
486 diag(1, "Unterminated literal"); 486 diag(1, "Unterminated literal");
487 goto stop_lit; 487 goto stop_lit;
488 } 488 }
489 check_size_token(2); 489 check_size_token(2);
490 *e_token = inbuf_next(); 490 *e_token = inbuf_next();
491 if (*e_token == '\\') { /* if escape, copy extra char */ 491 if (*e_token == '\\') { /* if escape, copy extra char */
492 if (*buf_ptr == '\n') /* check for escaped newline */ 492 if (*buf_ptr == '\n') /* check for escaped newline */
493 ++line_no; 493 ++line_no;
494 *++e_token = inbuf_next(); 494 *++e_token = inbuf_next();
495 ++e_token; /* we must increment this again because we 495 ++e_token; /* we must increment this again because we
496 * copied two chars */ 496 * copied two chars */
497 } else 497 } else

cvs diff -r1.30 -r1.31 src/usr.bin/indent/pr_comment.c (expand / switch to unified diff)

--- src/usr.bin/indent/pr_comment.c 2021/03/13 18:11:31 1.30
+++ src/usr.bin/indent/pr_comment.c 2021/03/14 00:22:16 1.31
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: pr_comment.c,v 1.30 2021/03/13 18:11:31 rillig Exp $ */ 1/* $NetBSD: pr_comment.c,v 1.31 2021/03/14 00:22:16 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[] = "@(#)pr_comment.c 8.1 (Berkeley) 6/6/93"; 42static char sccsid[] = "@(#)pr_comment.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: pr_comment.c,v 1.30 2021/03/13 18:11:31 rillig Exp $"); 49__RCSID("$NetBSD: pr_comment.c,v 1.31 2021/03/14 00:22:16 rillig Exp $");
50#elif defined(__FreeBSD__) 50#elif defined(__FreeBSD__)
51__FBSDID("$FreeBSD: head/usr.bin/indent/pr_comment.c 334927 2018-06-10 16:44:18Z pstef $"); 51__FBSDID("$FreeBSD: head/usr.bin/indent/pr_comment.c 334927 2018-06-10 16:44:18Z pstef $");
52#endif 52#endif
53#endif 53#endif
54 54
55#include <err.h> 55#include <err.h>
56#include <stdio.h> 56#include <stdio.h>
57#include <stdlib.h> 57#include <stdlib.h>
58#include <string.h> 58#include <string.h>
59 59
60#include "indent.h" 60#include "indent.h"
61 61
62static void 62static void
@@ -212,27 +212,27 @@ process_comment(void) @@ -212,27 +212,27 @@ process_comment(void)
212 char *t = e_com; 212 char *t = e_com;
213 e_com = s_com + 2; 213 e_com = s_com + 2;
214 *e_com = 0; 214 *e_com = 0;
215 if (opt.blanklines_before_blockcomments && ps.last_token != lbrace) 215 if (opt.blanklines_before_blockcomments && ps.last_token != lbrace)
216 prefix_blankline_requested = 1; 216 prefix_blankline_requested = 1;
217 dump_line(); 217 dump_line();
218 e_com = s_com = t; 218 e_com = s_com = t;
219 if (!ps.box_com && opt.star_comment_cont) 219 if (!ps.box_com && opt.star_comment_cont)
220 *e_com++ = ' ', *e_com++ = '*', *e_com++ = ' '; 220 *e_com++ = ' ', *e_com++ = '*', *e_com++ = ' ';
221 } 221 }
222 222
223 /* Start to copy the comment */ 223 /* Start to copy the comment */
224 224
225 while (1) { /* this loop will go until the comment is 225 for (;;) { /* this loop will go until the comment is
226 * copied */ 226 * copied */
227 switch (*buf_ptr) { /* this checks for various special cases */ 227 switch (*buf_ptr) { /* this checks for various special cases */
228 case 014: /* check for a form feed */ 228 case 014: /* check for a form feed */
229 check_size_comment(3, &last_bl); 229 check_size_comment(3, &last_bl);
230 if (!ps.box_com) { /* in a text comment, break the line here */ 230 if (!ps.box_com) { /* in a text comment, break the line here */
231 ps.use_ff = true; 231 ps.use_ff = true;
232 /* fix so dump_line uses a form feed */ 232 /* fix so dump_line uses a form feed */
233 dump_line(); 233 dump_line();
234 last_bl = NULL; 234 last_bl = NULL;
235 if (!ps.box_com && opt.star_comment_cont) 235 if (!ps.box_com && opt.star_comment_cont)
236 *e_com++ = ' ', *e_com++ = '*', *e_com++ = ' '; 236 *e_com++ = ' ', *e_com++ = '*', *e_com++ = ' ';
237 while (*++buf_ptr == ' ' || *buf_ptr == '\t') 237 while (*++buf_ptr == ' ' || *buf_ptr == '\t')
238 ; 238 ;