Thu Mar 11 22:15:44 2021 UTC ()
indent: use consistent array indexing

No functional change.


(rillig)
diff -r1.32 -r1.33 src/usr.bin/indent/lexi.c
diff -r1.15 -r1.16 src/usr.bin/indent/pr_comment.c

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

--- src/usr.bin/indent/lexi.c 2021/03/11 21:47:36 1.32
+++ src/usr.bin/indent/lexi.c 2021/03/11 22:15:44 1.33
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: lexi.c,v 1.32 2021/03/11 21:47:36 rillig Exp $ */ 1/* $NetBSD: lexi.c,v 1.33 2021/03/11 22:15:44 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.32 2021/03/11 21:47:36 rillig Exp $"); 49__RCSID("$NetBSD: lexi.c,v 1.33 2021/03/11 22:15:44 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>
@@ -321,27 +321,27 @@ lexi(struct parser_state *state) @@ -321,27 +321,27 @@ lexi(struct parser_state *state)
321 } 321 }
322 s = table[i][s - 'A']; 322 s = table[i][s - 'A'];
323 check_size_token(1); 323 check_size_token(1);
324 *e_token++ = inbuf_next(); 324 *e_token++ = inbuf_next();
325 } 325 }
326 /* s now indicates the type: f(loating), i(integer), u(nknown) */ 326 /* s now indicates the type: f(loating), i(integer), u(nknown) */
327 } 327 }
328 else 328 else
329 while (isalnum((unsigned char)*buf_ptr) || 329 while (isalnum((unsigned char)*buf_ptr) ||
330 *buf_ptr == '\\' || 330 *buf_ptr == '\\' ||
331 *buf_ptr == '_' || *buf_ptr == '$') { 331 *buf_ptr == '_' || *buf_ptr == '$') {
332 /* fill_buffer() terminates buffer with newline */ 332 /* fill_buffer() terminates buffer with newline */
333 if (*buf_ptr == '\\') { 333 if (*buf_ptr == '\\') {
334 if (*(buf_ptr + 1) == '\n') { 334 if (buf_ptr[1] == '\n') {
335 buf_ptr += 2; 335 buf_ptr += 2;
336 if (buf_ptr >= buf_end) 336 if (buf_ptr >= buf_end)
337 fill_buffer(); 337 fill_buffer();
338 } else 338 } else
339 break; 339 break;
340 } 340 }
341 check_size_token(1); 341 check_size_token(1);
342 *e_token++ = inbuf_next(); 342 *e_token++ = inbuf_next();
343 } 343 }
344 *e_token = '\0'; 344 *e_token = '\0';
345 345
346 if (s_token[0] == 'L' && s_token[1] == '\0' && 346 if (s_token[0] == 'L' && s_token[1] == '\0' &&
347 (*buf_ptr == '"' || *buf_ptr == '\'')) 347 (*buf_ptr == '"' || *buf_ptr == '\''))
@@ -640,27 +640,27 @@ stop_lit: @@ -640,27 +640,27 @@ stop_lit:
640 } 640 }
641 code = unary_op; 641 code = unary_op;
642 break; 642 break;
643 643
644 default: 644 default:
645 if (token[0] == '/' && (*buf_ptr == '*' || *buf_ptr == '/')) { 645 if (token[0] == '/' && (*buf_ptr == '*' || *buf_ptr == '/')) {
646 /* it is start of comment */ 646 /* it is start of comment */
647 *e_token++ = inbuf_next(); 647 *e_token++ = inbuf_next();
648 648
649 code = comment; 649 code = comment;
650 unary_delim = state->last_u_d; 650 unary_delim = state->last_u_d;
651 break; 651 break;
652 } 652 }
653 while (*(e_token - 1) == *buf_ptr || *buf_ptr == '=') { 653 while (e_token[-1] == *buf_ptr || *buf_ptr == '=') {
654 /* 654 /*
655 * handle ||, &&, etc, and also things as in int *****i 655 * handle ||, &&, etc, and also things as in int *****i
656 */ 656 */
657 check_size_token(1); 657 check_size_token(1);
658 *e_token++ = inbuf_next(); 658 *e_token++ = inbuf_next();
659 } 659 }
660 code = (state->last_u_d ? unary_op : binary_op); 660 code = (state->last_u_d ? unary_op : binary_op);
661 unary_delim = true; 661 unary_delim = true;
662 662
663 663
664 } /* end of switch */ 664 } /* end of switch */
665 if (buf_ptr >= buf_end) /* check for input buffer empty */ 665 if (buf_ptr >= buf_end) /* check for input buffer empty */
666 fill_buffer(); 666 fill_buffer();

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

--- src/usr.bin/indent/pr_comment.c 2021/03/09 16:48:28 1.15
+++ src/usr.bin/indent/pr_comment.c 2021/03/11 22:15:44 1.16
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: pr_comment.c,v 1.15 2021/03/09 16:48:28 rillig Exp $ */ 1/* $NetBSD: pr_comment.c,v 1.16 2021/03/11 22:15:44 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.15 2021/03/09 16:48:28 rillig Exp $"); 49__RCSID("$NetBSD: pr_comment.c,v 1.16 2021/03/11 22:15:44 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
@@ -273,27 +273,27 @@ pr_comment(void) @@ -273,27 +273,27 @@ pr_comment(void)
273 if (s_com == e_com) 273 if (s_com == e_com)
274 *e_com++ = ' '; 274 *e_com++ = ' ';
275 if (!ps.box_com && e_com - s_com > 3) { 275 if (!ps.box_com && e_com - s_com > 3) {
276 dump_line(); 276 dump_line();
277 if (opt.star_comment_cont) 277 if (opt.star_comment_cont)
278 *e_com++ = ' ', *e_com++ = '*', *e_com++ = ' '; 278 *e_com++ = ' ', *e_com++ = '*', *e_com++ = ' ';
279 } 279 }
280 dump_line(); 280 dump_line();
281 if (!ps.box_com && opt.star_comment_cont) 281 if (!ps.box_com && opt.star_comment_cont)
282 *e_com++ = ' ', *e_com++ = '*', *e_com++ = ' '; 282 *e_com++ = ' ', *e_com++ = '*', *e_com++ = ' ';
283 } 283 }
284 else { 284 else {
285 ps.last_nl = 1; 285 ps.last_nl = 1;
286 if (*(e_com - 1) == ' ' || *(e_com - 1) == '\t') 286 if (e_com[-1] == ' ' || e_com[-1] == '\t')
287 last_bl = e_com - 1; 287 last_bl = e_com - 1;
288 /* 288 /*
289 * if there was a space at the end of the last line, remember 289 * if there was a space at the end of the last line, remember
290 * where it was 290 * where it was
291 */ 291 */
292 else { /* otherwise, insert one */ 292 else { /* otherwise, insert one */
293 last_bl = e_com; 293 last_bl = e_com;
294 *e_com++ = ' '; 294 *e_com++ = ' ';
295 } 295 }
296 } 296 }
297 ++line_no; /* keep track of input line number */ 297 ++line_no; /* keep track of input line number */
298 if (!ps.box_com) { 298 if (!ps.box_com) {
299 int nstar = 1; 299 int nstar = 1;