Tue Mar 9 18:28:10 2021 UTC ()
indent: rename a few tokens to be more obvious

For casual readers it is not obvious whether the 'sp' meant 'special' or
'space' or something entirely different.


(rillig)
diff -r1.36 -r1.37 src/usr.bin/indent/indent.c
diff -r1.8 -r1.9 src/usr.bin/indent/indent_codes.h
diff -r1.28 -r1.29 src/usr.bin/indent/lexi.c

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

--- src/usr.bin/indent/indent.c 2021/03/09 16:48:28 1.36
+++ src/usr.bin/indent/indent.c 2021/03/09 18:28:10 1.37
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: indent.c,v 1.36 2021/03/09 16:48:28 rillig Exp $ */ 1/* $NetBSD: indent.c,v 1.37 2021/03/09 18:28:10 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.36 2021/03/09 16:48:28 rillig Exp $"); 49__RCSID("$NetBSD: indent.c,v 1.37 2021/03/09 18:28:10 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>
@@ -471,31 +471,31 @@ main(int argc, char **argv) @@ -471,31 +471,31 @@ main(int argc, char **argv)
471 fill_buffer(); 471 fill_buffer();
472 if (*buf_ptr == '\n') 472 if (*buf_ptr == '\n')
473 break; 473 break;
474 } 474 }
475 goto sw_buffer; 475 goto sw_buffer;
476 } 476 }
477 /* FALLTHROUGH */ 477 /* FALLTHROUGH */
478 default: /* it is the start of a normal statement */ 478 default: /* it is the start of a normal statement */
479 { 479 {
480 int remove_newlines; 480 int remove_newlines;
481 481
482 remove_newlines = 482 remove_newlines =
483 /* "} else" */ 483 /* "} else" */
484 (type_code == sp_nparen && *token == 'e' && 484 (type_code == keyword_do_else && *token == 'e' &&
485 e_code != s_code && e_code[-1] == '}') 485 e_code != s_code && e_code[-1] == '}')
486 /* "else if" */ 486 /* "else if" */
487 || (type_code == sp_paren && *token == 'i' && 487 || (type_code == keyword_for_if_while &&
488 last_else && opt.else_if); 488 *token == 'i' && last_else && opt.else_if);
489 if (remove_newlines) 489 if (remove_newlines)
490 force_nl = false; 490 force_nl = false;
491 if (sc_end == NULL) { /* ignore buffering if 491 if (sc_end == NULL) { /* ignore buffering if
492 * comment wasn't saved up */ 492 * comment wasn't saved up */
493 ps.search_brace = false; 493 ps.search_brace = false;
494 goto check_type; 494 goto check_type;
495 } 495 }
496 while (sc_end > save_com && isblank((unsigned char)sc_end[-1])) { 496 while (sc_end > save_com && isblank((unsigned char)sc_end[-1])) {
497 sc_end--; 497 sc_end--;
498 } 498 }
499 if (opt.swallow_optional_blanklines || 499 if (opt.swallow_optional_blanklines ||
500 (!comment_buffered && remove_newlines)) { 500 (!comment_buffered && remove_newlines)) {
501 force_nl = !remove_newlines; 501 force_nl = !remove_newlines;
@@ -983,38 +983,38 @@ check_type: @@ -983,38 +983,38 @@ check_type:
983 parse(rbrace); /* let parser know about this */ 983 parse(rbrace); /* let parser know about this */
984 ps.search_brace = opt.cuddle_else && ps.p_stack[ps.tos] == ifhead 984 ps.search_brace = opt.cuddle_else && ps.p_stack[ps.tos] == ifhead
985 && ps.il[ps.tos] >= ps.ind_level; 985 && ps.il[ps.tos] >= ps.ind_level;
986 if (ps.tos <= 1 && opt.blanklines_after_procs && ps.dec_nest <= 0) 986 if (ps.tos <= 1 && opt.blanklines_after_procs && ps.dec_nest <= 0)
987 postfix_blankline_requested = 1; 987 postfix_blankline_requested = 1;
988 break; 988 break;
989 989
990 case swstmt: /* got keyword "switch" */ 990 case swstmt: /* got keyword "switch" */
991 sp_sw = true; 991 sp_sw = true;
992 hd_type = swstmt; /* keep this for when we have seen the 992 hd_type = swstmt; /* keep this for when we have seen the
993 * expression */ 993 * expression */
994 goto copy_id; /* go move the token into buffer */ 994 goto copy_id; /* go move the token into buffer */
995 995
996 case sp_paren: /* token is if, while, for */ 996 case keyword_for_if_while:
997 sp_sw = true; /* the interesting stuff is done after the 997 sp_sw = true; /* the interesting stuff is done after the
998 * expression is scanned */ 998 * expression is scanned */
999 hd_type = (*token == 'i' ? ifstmt : 999 hd_type = (*token == 'i' ? ifstmt :
1000 (*token == 'w' ? whilestmt : forstmt)); 1000 (*token == 'w' ? whilestmt : forstmt));
1001 1001
1002 /* 1002 /*
1003 * remember the type of header for later use by parser 1003 * remember the type of header for later use by parser
1004 */ 1004 */
1005 goto copy_id; /* copy the token into line */ 1005 goto copy_id; /* copy the token into line */
1006 1006
1007 case sp_nparen: /* got else, do */ 1007 case keyword_do_else:
1008 ps.in_stmt = false; 1008 ps.in_stmt = false;
1009 if (*token == 'e') { 1009 if (*token == 'e') {
1010 if (e_code != s_code && (!opt.cuddle_else || e_code[-1] != '}')) { 1010 if (e_code != s_code && (!opt.cuddle_else || e_code[-1] != '}')) {
1011 if (opt.verbose) 1011 if (opt.verbose)
1012 diag(0, "Line broken"); 1012 diag(0, "Line broken");
1013 dump_line();/* make sure this starts a line */ 1013 dump_line();/* make sure this starts a line */
1014 ps.want_blank = false; 1014 ps.want_blank = false;
1015 } 1015 }
1016 force_nl = true;/* also, following stuff must go onto new line */ 1016 force_nl = true;/* also, following stuff must go onto new line */
1017 last_else = 1; 1017 last_else = 1;
1018 parse(elselit); 1018 parse(elselit);
1019 } 1019 }
1020 else { 1020 else {

cvs diff -r1.8 -r1.9 src/usr.bin/indent/Attic/indent_codes.h (expand / switch to unified diff)

--- src/usr.bin/indent/Attic/indent_codes.h 2021/03/07 20:30:48 1.8
+++ src/usr.bin/indent/Attic/indent_codes.h 2021/03/09 18:28:10 1.9
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: indent_codes.h,v 1.8 2021/03/07 20:30:48 rillig Exp $ */ 1/* $NetBSD: indent_codes.h,v 1.9 2021/03/09 18:28:10 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
@@ -51,28 +51,28 @@ typedef enum token_type { @@ -51,28 +51,28 @@ typedef enum token_type {
51 question, /* the '?' from a '?:' expression */ 51 question, /* the '?' from a '?:' expression */
52 casestmt, 52 casestmt,
53 colon, 53 colon,
54 semicolon, 54 semicolon,
55 lbrace, 55 lbrace,
56 rbrace, 56 rbrace,
57 ident, 57 ident,
58 comma, 58 comma,
59 comment, 59 comment,
60 swstmt, 60 swstmt,
61 preesc, 61 preesc,
62 form_feed, 62 form_feed,
63 decl, 63 decl,
64 sp_paren, 64 keyword_for_if_while,
65 sp_nparen, 65 keyword_do_else,
66 ifstmt, 66 ifstmt,
67 whilestmt, 67 whilestmt,
68 forstmt, 68 forstmt,
69 stmt, 69 stmt,
70 stmtl, 70 stmtl,
71 elselit, 71 elselit,
72 dolit, 72 dolit,
73 dohead, 73 dohead,
74 ifhead, 74 ifhead,
75 elsehead, 75 elsehead,
76 period, 76 period,
77 strpfx, 77 strpfx,
78 storage, 78 storage,

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

--- src/usr.bin/indent/lexi.c 2021/03/09 16:48:28 1.28
+++ src/usr.bin/indent/lexi.c 2021/03/09 18:28:10 1.29
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: lexi.c,v 1.28 2021/03/09 16:48:28 rillig Exp $ */ 1/* $NetBSD: lexi.c,v 1.29 2021/03/09 18:28:10 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.28 2021/03/09 16:48:28 rillig Exp $"); 49__RCSID("$NetBSD: lexi.c,v 1.29 2021/03/09 18:28:10 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>
@@ -197,27 +197,28 @@ compare_string_array(const void *key, co @@ -197,27 +197,28 @@ compare_string_array(const void *key, co
197{ 197{
198 return strcmp(key, *((const char *const *)elem)); 198 return strcmp(key, *((const char *const *)elem));
199} 199}
200 200
201#ifdef debug 201#ifdef debug
202const char * 202const char *
203token_type_name(token_type tk) 203token_type_name(token_type tk)
204{ 204{
205 static const char *const name[] = { 205 static const char *const name[] = {
206 "end_of_file", "newline", "lparen", "rparen", "unary_op", 206 "end_of_file", "newline", "lparen", "rparen", "unary_op",
207 "binary_op", "postop", "question", "casestmt", "colon", 207 "binary_op", "postop", "question", "casestmt", "colon",
208 "semicolon", "lbrace", "rbrace", "ident", "comma", 208 "semicolon", "lbrace", "rbrace", "ident", "comma",
209 "comment", "swstmt", "preesc", "form_feed", "decl", 209 "comment", "swstmt", "preesc", "form_feed", "decl",
210 "sp_paren", "sp_nparen", "ifstmt", "whilestmt", "forstmt", 210 "keyword_for_if_while", "keyword_do_else",
 211 "ifstmt", "whilestmt", "forstmt",
211 "stmt", "stmtl", "elselit", "dolit", "dohead", 212 "stmt", "stmtl", "elselit", "dolit", "dohead",
212 "ifhead", "elsehead", "period", "strpfx", "storage", 213 "ifhead", "elsehead", "period", "strpfx", "storage",
213 "funcname", "type_def", "structure" 214 "funcname", "type_def", "structure"
214 }; 215 };
215 216
216 assert(0 <= tk && tk < sizeof name / sizeof name[0]); 217 assert(0 <= tk && tk < sizeof name / sizeof name[0]);
217 218
218 return name[tk]; 219 return name[tk];
219} 220}
220 221
221static void 222static void
222print_buf(const char *name, const char *s, const char *e) 223print_buf(const char *name, const char *s, const char *e)
223{ 224{
@@ -377,30 +378,30 @@ lexi(struct parser_state *state) @@ -377,30 +378,30 @@ lexi(struct parser_state *state)
377 state->cast_mask |= (1 << state->p_l_follow) & ~state->not_cast_mask; 378 state->cast_mask |= (1 << state->p_l_follow) & ~state->not_cast_mask;
378 } 379 }
379 if (state->last_token == period || state->last_token == unary_op) { 380 if (state->last_token == period || state->last_token == unary_op) {
380 state->keyword = rw_0; 381 state->keyword = rw_0;
381 break; 382 break;
382 } 383 }
383 if (p != NULL && p->rwcode == rw_struct_or_union_or_enum) 384 if (p != NULL && p->rwcode == rw_struct_or_union_or_enum)
384 return lexi_end(structure); 385 return lexi_end(structure);
385 if (state->p_l_follow) 386 if (state->p_l_follow)
386 break; 387 break;
387 return lexi_end(decl); 388 return lexi_end(decl);
388 389
389 case rw_for_or_if_or_while: 390 case rw_for_or_if_or_while:
390 return lexi_end(sp_paren); 391 return lexi_end(keyword_for_if_while);
391 392
392 case rw_do_or_else: 393 case rw_do_or_else:
393 return lexi_end(sp_nparen); 394 return lexi_end(keyword_do_else);
394 395
395 case rw_storage_class: 396 case rw_storage_class:
396 return lexi_end(storage); 397 return lexi_end(storage);
397 398
398 case rw_typedef: 399 case rw_typedef:
399 return lexi_end(type_def); 400 return lexi_end(type_def);
400 401
401 default: /* all others are treated like any other 402 default: /* all others are treated like any other
402 * identifier */ 403 * identifier */
403 return lexi_end(ident); 404 return lexi_end(ident);
404 } /* end of switch */ 405 } /* end of switch */
405 } /* end of if (found_it) */ 406 } /* end of if (found_it) */
406 if (*buf_ptr == '(' && state->tos <= 1 && state->ind_level == 0 && 407 if (*buf_ptr == '(' && state->tos <= 1 && state->ind_level == 0 &&