Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/indent indent: group global variables for code buffer
details: https://anonhg.NetBSD.org/src/rev/07a0b640635c
branches: trunk
changeset: 1023731:07a0b640635c
user: rillig <rillig%NetBSD.org@localhost>
date: Sat Sep 25 07:55:24 2021 +0000
description:
indent: group global variables for code buffer
No functional change.
diffstat:
usr.bin/indent/indent.c | 161 ++++++++++++++++++++---------------------
usr.bin/indent/indent_globs.h | 11 +--
usr.bin/indent/io.c | 22 ++--
usr.bin/indent/lexi.c | 6 +-
usr.bin/indent/parse.c | 4 +-
usr.bin/indent/pr_comment.c | 10 +-
6 files changed, 102 insertions(+), 112 deletions(-)
diffs (truncated from 657 to 300 lines):
diff -r ecdaa466bd71 -r 07a0b640635c usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c Sat Sep 25 07:46:41 2021 +0000
+++ b/usr.bin/indent/indent.c Sat Sep 25 07:55:24 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: indent.c,v 1.64 2021/09/25 07:46:41 rillig Exp $ */
+/* $NetBSD: indent.c,v 1.65 2021/09/25 07:55:24 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-4-Clause
@@ -46,7 +46,7 @@
#include <sys/cdefs.h>
#ifndef lint
#if defined(__NetBSD__)
-__RCSID("$NetBSD: indent.c,v 1.64 2021/09/25 07:46:41 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.65 2021/09/25 07:55:24 rillig Exp $");
#elif defined(__FreeBSD__)
__FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
#endif
@@ -72,12 +72,7 @@
struct parser_state ps;
struct buffer lab;
-
-char *codebuf;
-char *s_code;
-char *e_code;
-char *l_code;
-
+struct buffer code;
struct buffer com;
char *tokenbuf;
@@ -130,17 +125,17 @@
static void
check_size_code(size_t desired_size)
{
- if (e_code + (desired_size) < l_code)
+ if (code.e + desired_size < code.l)
return;
- size_t nsize = l_code - s_code + 400 + desired_size;
- size_t code_len = e_code - s_code;
- codebuf = realloc(codebuf, nsize);
- if (codebuf == NULL)
+ size_t nsize = code.l - code.s + 400 + desired_size;
+ size_t code_len = code.e - code.s;
+ code.buf = realloc(code.buf, nsize);
+ if (code.buf == NULL)
err(1, NULL);
- e_code = codebuf + code_len + 1;
- l_code = codebuf + nsize - 5;
- s_code = codebuf + 1;
+ code.e = code.buf + code_len + 1;
+ code.l = code.buf + nsize - 5;
+ code.s = code.buf + 1;
}
static void
@@ -265,7 +260,7 @@
remove_newlines =
/* "} else" */
(*inout_ttype == keyword_do_else && *token == 'e' &&
- e_code != s_code && e_code[-1] == '}')
+ code.e != code.s && code.e[-1] == '}')
/* "else if" */
|| (*inout_ttype == keyword_for_if_while &&
*token == 'i' && *inout_last_else && opt.else_if);
@@ -377,8 +372,8 @@
lab.buf = malloc(bufsize);
if (lab.buf == NULL)
err(1, NULL);
- codebuf = malloc(bufsize);
- if (codebuf == NULL)
+ code.buf = malloc(bufsize);
+ if (code.buf == NULL)
err(1, NULL);
tokenbuf = malloc(bufsize);
if (tokenbuf == NULL)
@@ -387,14 +382,14 @@
init_constant_tt();
com.l = com.buf + bufsize - 5;
lab.l = lab.buf + bufsize - 5;
- l_code = codebuf + bufsize - 5;
+ code.l = code.buf + bufsize - 5;
l_token = tokenbuf + bufsize - 5;
- com.buf[0] = codebuf[0] = lab.buf[0] = ' '; /* set up code, label, and
+ com.buf[0] = code.buf[0] = lab.buf[0] = ' '; /* set up code, label, and
* comment buffers */
- com.buf[1] = codebuf[1] = lab.buf[1] = tokenbuf[1] = '\0';
+ com.buf[1] = code.buf[1] = lab.buf[1] = tokenbuf[1] = '\0';
opt.else_if = 1; /* Default else-if special processing to on */
lab.s = lab.e = lab.buf + 1;
- s_code = e_code = codebuf + 1;
+ code.s = code.e = code.buf + 1;
com.s = com.e = com.buf + 1;
s_token = e_token = tokenbuf + 1;
@@ -543,7 +538,7 @@
static void __attribute__((__noreturn__))
process_end_of_file(void)
{
- if (lab.s != lab.e || s_code != e_code || com.s != com.e)
+ if (lab.s != lab.e || code.s != code.e || com.s != com.e)
dump_line();
if (ps.tos > 1) /* check for balanced braces */
@@ -583,11 +578,11 @@
size_t len = com.e - com.s;
check_size_code(len + 3);
- *e_code++ = ' ';
- memcpy(e_code, com.s, len);
- e_code += len;
- *e_code++ = ' ';
- *e_code = '\0';
+ *code.e++ = ' ';
+ memcpy(code.e, com.s, len);
+ code.e += len;
+ *code.e++ = ' ';
+ *code.e = '\0';
ps.want_blank = false;
com.e = com.s;
}
@@ -633,12 +628,12 @@
opt.proc_calls_space ||
(ps.keyword == rw_sizeof ? opt.Bill_Shannon :
ps.keyword != rw_0 && ps.keyword != rw_offsetof)))
- *e_code++ = ' ';
+ *code.e++ = ' ';
ps.want_blank = false;
- *e_code++ = token[0];
+ *code.e++ = token[0];
ps.paren_indents[ps.p_l_follow - 1] =
- indentation_after_range(0, s_code, e_code);
+ indentation_after_range(0, code.s, code.e);
debug_println("paren_indent[%d] is now %d",
ps.p_l_follow - 1, ps.paren_indents[ps.p_l_follow - 1]);
@@ -679,10 +674,10 @@
diag(0, "Extra %c", *token);
}
- if (e_code == s_code) /* if the paren starts the line */
+ if (code.e == code.s) /* if the paren starts the line */
ps.paren_level = ps.p_l_follow; /* then indent it */
- *e_code++ = token[0];
+ *code.e++ = token[0];
if (*inout_sp_sw && (ps.p_l_follow == 0)) { /* check for end of if
* (...), or some such */
@@ -716,14 +711,14 @@
indent_declaration(dec_ind - i, tabs_to_var);
ps.dumped_decl_indent = true;
} else if (ps.want_blank)
- *e_code++ = ' ';
+ *code.e++ = ' ';
{
size_t len = e_token - s_token;
check_size_code(len);
- memcpy(e_code, token, len);
- e_code += len;
+ memcpy(code.e, token, len);
+ code.e += len;
}
ps.want_blank = false;
}
@@ -735,9 +730,9 @@
check_size_code(len + 1);
if (ps.want_blank)
- *e_code++ = ' ';
- memcpy(e_code, token, len);
- e_code += len;
+ *code.e++ = ' ';
+ memcpy(code.e, token, len);
+ code.e += len;
ps.want_blank = true;
}
@@ -745,8 +740,8 @@
static void
process_postfix_op(void)
{
- *e_code++ = token[0];
- *e_code++ = token[1];
+ *code.e++ = token[0];
+ *code.e++ = token[1];
ps.want_blank = true;
}
@@ -757,8 +752,8 @@
* appears so we can distinguish the
* <c>?<n>:<n> construct */
if (ps.want_blank)
- *e_code++ = ' ';
- *e_code++ = '?';
+ *code.e++ = ' ';
+ *code.e++ = '?';
ps.want_blank = true;
}
@@ -768,13 +763,13 @@
if (*inout_squest > 0) { /* it is part of the <c>?<n>: <n> construct */
--*inout_squest;
if (ps.want_blank)
- *e_code++ = ' ';
- *e_code++ = ':';
+ *code.e++ = ' ';
+ *code.e++ = ':';
ps.want_blank = true;
return;
}
if (ps.in_or_st) {
- *e_code++ = ':';
+ *code.e++ = ':';
ps.want_blank = false;
return;
}
@@ -784,14 +779,14 @@
* turn everything so far into a label
*/
{
- size_t len = e_code - s_code;
+ size_t len = code.e - code.s;
check_size_label(len + 3);
- memcpy(lab.e, s_code, len);
+ memcpy(lab.e, code.s, len);
lab.e += len;
*lab.e++ = ':';
*lab.e = '\0';
- e_code = s_code;
+ code.e = code.s;
}
*inout_force_nl = ps.pcase = *inout_scase; /* ps.pcase will be used by
* dump_line to decide how to
@@ -821,7 +816,7 @@
ps.block_init_level = 0;
ps.just_saw_decl--;
- if (ps.in_decl && s_code == e_code && !ps.block_init &&
+ if (ps.in_decl && code.s == code.e && !ps.block_init &&
!ps.dumped_decl_indent && ps.paren_level == 0) {
/* indent stray semicolons in declarations */
indent_declaration(dec_ind - 1, tabs_to_var);
@@ -847,7 +842,7 @@
parse(hd_type); /* dont lose the if, or whatever */
}
}
- *e_code++ = ';';
+ *code.e++ = ';';
ps.want_blank = true;
ps.in_stmt = (ps.p_l_follow > 0); /* we are no longer in the
* middle of a stmt */
@@ -871,7 +866,7 @@
else
ps.block_init_level++;
- if (s_code != e_code && !ps.block_init) {
+ if (code.s != code.e && !ps.block_init) {
if (!opt.btype_2) {
dump_line();
ps.want_blank = false;
@@ -898,7 +893,7 @@
ps.ind_level = ps.i_l_follow;
}
}
- if (s_code == e_code)
+ if (code.s == code.e)
ps.ind_stmt = false; /* dont put extra indentation on line
* with '{' */
if (ps.in_decl && ps.in_or_st) { /* this is either a structure
@@ -925,9 +920,9 @@
parse(lbrace); /* let parser know about this */
if (ps.want_blank) /* put a blank before '{' if '{' is not at
* start of line */
- *e_code++ = ' ';
+ *code.e++ = ' ';
ps.want_blank = false;
- *e_code++ = '{';
+ *code.e++ = '{';
ps.just_saw_decl = 0;
}
@@ -944,12 +939,12 @@
}
ps.just_saw_decl = 0;
ps.block_init_level--;
- if (s_code != e_code && !ps.block_init) { /* '}' must be first on line */
+ if (code.s != code.e && !ps.block_init) { /* '}' must be first on line */
if (opt.verbose)
diag(0, "Line broken");
dump_line();
}
- *e_code++ = '}';
+ *code.e++ = '}';
Home |
Main Index |
Thread Index |
Old Index