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 the commen...
details: https://anonhg.NetBSD.org/src/rev/1111205c343f
branches: trunk
changeset: 1023727:1111205c343f
user: rillig <rillig%NetBSD.org@localhost>
date: Fri Sep 24 18:14:06 2021 +0000
description:
indent: group global variables for the comment buffer
No functional change.
diffstat:
usr.bin/indent/indent.c | 35 ++++++-------
usr.bin/indent/indent_globs.h | 12 ++-
usr.bin/indent/io.c | 22 ++++----
usr.bin/indent/lexi.c | 6 +-
usr.bin/indent/pr_comment.c | 106 +++++++++++++++++++++---------------------
5 files changed, 90 insertions(+), 91 deletions(-)
diffs (truncated from 473 to 300 lines):
diff -r bb2ce54df507 -r 1111205c343f usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c Fri Sep 24 18:00:13 2021 +0000
+++ b/usr.bin/indent/indent.c Fri Sep 24 18:14:06 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: indent.c,v 1.61 2021/08/25 22:26:30 rillig Exp $ */
+/* $NetBSD: indent.c,v 1.62 2021/09/24 18:14:06 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.61 2021/08/25 22:26:30 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.62 2021/09/24 18:14:06 rillig Exp $");
#elif defined(__FreeBSD__)
__FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
#endif
@@ -81,10 +81,7 @@
char *e_code;
char *l_code;
-char *combuf;
-char *s_com;
-char *e_com;
-char *l_com;
+struct comment_buffer com;
char *tokenbuf;
char *s_token;
@@ -377,8 +374,8 @@
ps.last_nl = true; /* this is true if the last thing scanned was
* a newline */
ps.last_token = semicolon;
- combuf = malloc(bufsize);
- if (combuf == NULL)
+ com.buf = malloc(bufsize);
+ if (com.buf == NULL)
err(1, NULL);
labbuf = malloc(bufsize);
if (labbuf == NULL)
@@ -391,17 +388,17 @@
err(1, NULL);
alloc_typenames();
init_constant_tt();
- l_com = combuf + bufsize - 5;
+ com.l = com.buf + bufsize - 5;
l_lab = labbuf + bufsize - 5;
l_code = codebuf + bufsize - 5;
l_token = tokenbuf + bufsize - 5;
- combuf[0] = codebuf[0] = labbuf[0] = ' '; /* set up code, label, and
+ com.buf[0] = codebuf[0] = labbuf[0] = ' '; /* set up code, label, and
* comment buffers */
- combuf[1] = codebuf[1] = labbuf[1] = tokenbuf[1] = '\0';
+ com.buf[1] = codebuf[1] = labbuf[1] = tokenbuf[1] = '\0';
opt.else_if = 1; /* Default else-if special processing to on */
s_lab = e_lab = labbuf + 1;
s_code = e_code = codebuf + 1;
- s_com = e_com = combuf + 1;
+ com.s = com.e = com.buf + 1;
s_token = e_token = tokenbuf + 1;
in_buffer = malloc(10);
@@ -549,7 +546,7 @@
static void __attribute__((__noreturn__))
process_end_of_file(void)
{
- if (s_lab != e_lab || s_code != e_code || s_com != e_com)
+ if (s_lab != e_lab || s_code != e_code || com.s != com.e)
dump_line();
if (ps.tos > 1) /* check for balanced braces */
@@ -584,18 +581,18 @@
ps.in_stmt = true; /* turn on flag which causes an extra level of
* indentation. this is turned off by a ; or
* '}' */
- if (s_com != e_com) { /* the turkey has embedded a comment
+ if (com.s != com.e) { /* the turkey has embedded a comment
* in a line. fix it */
- size_t len = e_com - s_com;
+ size_t len = com.e - com.s;
check_size_code(len + 3);
*e_code++ = ' ';
- memcpy(e_code, s_com, len);
+ memcpy(e_code, com.s, len);
e_code += len;
*e_code++ = ' ';
*e_code = '\0'; /* null terminate code sect */
ps.want_blank = false;
- e_com = s_com;
+ com.e = com.s;
}
}
@@ -611,7 +608,7 @@
process_newline(void)
{
if (ps.last_token != comma || ps.p_l_follow > 0
- || !opt.leave_comma || ps.block_init || !break_comma || s_com != e_com) {
+ || !opt.leave_comma || ps.block_init || !break_comma || com.s != com.e) {
dump_line();
ps.want_blank = false;
}
@@ -1123,7 +1120,7 @@
static void
process_preprocessing(void)
{
- if (s_com != e_com || s_lab != e_lab || s_code != e_code)
+ if (com.s != com.e || s_lab != e_lab || s_code != e_code)
dump_line();
check_size_label(1);
*e_lab++ = '#'; /* move whole line to 'label' buffer */
diff -r bb2ce54df507 -r 1111205c343f usr.bin/indent/indent_globs.h
--- a/usr.bin/indent/indent_globs.h Fri Sep 24 18:00:13 2021 +0000
+++ b/usr.bin/indent/indent_globs.h Fri Sep 24 18:14:06 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: indent_globs.h,v 1.21 2021/03/13 23:36:10 rillig Exp $ */
+/* $NetBSD: indent_globs.h,v 1.22 2021/09/24 18:14:06 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-4-Clause
@@ -63,10 +63,12 @@
extern char *e_code; /* .. and end of stored code */
extern char *l_code; /* limit of code section */
-extern char *combuf; /* buffer for comments */
-extern char *s_com; /* start ... */
-extern char *e_com; /* ... and end of stored comments */
-extern char *l_com; /* limit of comment buffer */
+extern struct comment_buffer {
+ char *buf; /* buffer for comments */
+ char *s; /* start ... */
+ char *e; /* ... and end of stored comments */
+ char *l; /* limit of comment buffer */
+} com;
#define token s_token
extern char *tokenbuf; /* the last token scanned */
diff -r bb2ce54df507 -r 1111205c343f usr.bin/indent/io.c
--- a/usr.bin/indent/io.c Fri Sep 24 18:00:13 2021 +0000
+++ b/usr.bin/indent/io.c Fri Sep 24 18:14:06 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: io.c,v 1.51 2021/09/24 18:00:13 rillig Exp $ */
+/* $NetBSD: io.c,v 1.52 2021/09/24 18:14:06 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-4-Clause
@@ -46,7 +46,7 @@
#include <sys/cdefs.h>
#ifndef lint
#if defined(__NetBSD__)
-__RCSID("$NetBSD: io.c,v 1.51 2021/09/24 18:00:13 rillig Exp $");
+__RCSID("$NetBSD: io.c,v 1.52 2021/09/24 18:14:06 rillig Exp $");
#elif defined(__FreeBSD__)
__FBSDID("$FreeBSD: head/usr.bin/indent/io.c 334927 2018-06-10 16:44:18Z pstef $");
#endif
@@ -123,7 +123,7 @@
ps.procname[0] = 0;
}
- if (s_code == e_code && s_lab == e_lab && s_com == e_com) {
+ if (s_code == e_code && s_lab == e_lab && com.s == com.e) {
if (suppress_blanklines > 0)
suppress_blanklines--;
else {
@@ -217,9 +217,9 @@
output_range(s_code, e_code);
cur_col = 1 + indentation_after(cur_col - 1, s_code);
}
- if (s_com != e_com) { /* print comment, if any */
+ if (com.s != com.e) { /* print comment, if any */
int target_col = ps.com_col;
- char *com_st = s_com;
+ char *com_st = com.s;
target_col += ps.comment_delta;
while (*com_st == '\t') /* consider original indentation in
@@ -239,10 +239,10 @@
cur_col = 1;
++ps.out_lines;
}
- while (e_com > com_st && isspace((unsigned char)e_com[-1]))
- e_com--;
+ while (com.e > com_st && isspace((unsigned char)com.e[-1]))
+ com.e--;
(void)output_indent(cur_col - 1, target_col - 1);
- output_range(com_st, e_com);
+ output_range(com_st, com.e);
ps.comment_delta = ps.n_comment_delta;
++ps.com_lines; /* count lines with comments */
}
@@ -260,7 +260,7 @@
}
/* keep blank lines after '//' comments */
- if (e_com - s_com > 1 && s_com[1] == '/'
+ if (com.e - com.s > 1 && com.s[1] == '/'
&& s_token < e_token && isspace((unsigned char)s_token[0]))
output_range(s_token, e_token);
@@ -274,7 +274,7 @@
ps.dumped_decl_indent = 0;
*(e_lab = s_lab) = '\0'; /* reset buffers */
*(e_code = s_code) = '\0';
- *(e_com = s_com = combuf + 1) = '\0';
+ *(com.e = com.s = com.buf + 1) = '\0';
ps.ind_level = ps.i_l_follow;
ps.paren_level = ps.p_l_follow;
if (ps.paren_level > 0) {
@@ -406,7 +406,7 @@
while (*p == ' ' || *p == '\t')
p++;
if (p[0] == '*' && p[1] == '/' && p[2] == '\n' && comena) {
- if (s_com != e_com || s_lab != e_lab || s_code != e_code)
+ if (com.s != com.e || s_lab != e_lab || s_code != e_code)
dump_line();
if (!(inhibit_formatting = comena - 1)) {
n_real_blanklines = 0;
diff -r bb2ce54df507 -r 1111205c343f usr.bin/indent/lexi.c
--- a/usr.bin/indent/lexi.c Fri Sep 24 18:00:13 2021 +0000
+++ b/usr.bin/indent/lexi.c Fri Sep 24 18:14:06 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lexi.c,v 1.44 2021/09/24 06:23:35 rillig Exp $ */
+/* $NetBSD: lexi.c,v 1.45 2021/09/24 18:14:06 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-4-Clause
@@ -46,7 +46,7 @@
#include <sys/cdefs.h>
#ifndef lint
#if defined(__NetBSD__)
-__RCSID("$NetBSD: lexi.c,v 1.44 2021/09/24 06:23:35 rillig Exp $");
+__RCSID("$NetBSD: lexi.c,v 1.45 2021/09/24 18:14:06 rillig Exp $");
#elif defined(__FreeBSD__)
__FBSDID("$FreeBSD: head/usr.bin/indent/lexi.c 337862 2018-08-15 18:19:45Z pstef $");
#endif
@@ -275,7 +275,7 @@
print_buf("token", s_token, e_token);
print_buf("label", s_lab, e_lab);
print_buf("code", s_code, e_code);
- print_buf("comment", s_com, e_com);
+ print_buf("comment", com.s, com.e);
debug_printf("\n");
return code;
diff -r bb2ce54df507 -r 1111205c343f usr.bin/indent/pr_comment.c
--- a/usr.bin/indent/pr_comment.c Fri Sep 24 18:00:13 2021 +0000
+++ b/usr.bin/indent/pr_comment.c Fri Sep 24 18:14:06 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: pr_comment.c,v 1.35 2021/03/14 05:26:42 rillig Exp $ */
+/* $NetBSD: pr_comment.c,v 1.36 2021/09/24 18:14:06 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-4-Clause
@@ -46,7 +46,7 @@
#include <sys/cdefs.h>
#ifndef lint
#if defined(__NetBSD__)
-__RCSID("$NetBSD: pr_comment.c,v 1.35 2021/03/14 05:26:42 rillig Exp $");
+__RCSID("$NetBSD: pr_comment.c,v 1.36 2021/09/24 18:14:06 rillig Exp $");
#elif defined(__FreeBSD__)
__FBSDID("$FreeBSD: head/usr.bin/indent/pr_comment.c 334927 2018-06-10 16:44:18Z pstef $");
#endif
@@ -62,17 +62,17 @@
static void
check_size_comment(size_t desired_size)
{
- if (e_com + (desired_size) < l_com)
+ if (com.e + (desired_size) < com.l)
return;
- size_t nsize = l_com - s_com + 400 + desired_size;
- size_t com_len = e_com - s_com;
- combuf = realloc(combuf, nsize);
- if (combuf == NULL)
+ size_t nsize = com.l - com.s + 400 + desired_size;
+ size_t com_len = com.e - com.s;
+ com.buf = realloc(com.buf, nsize);
+ if (com.buf == NULL)
err(1, NULL);
- s_com = combuf + 1;
- e_com = s_com + com_len;
- l_com = combuf + nsize - 5;
+ com.s = com.buf + 1;
+ com.e = com.s + com_len;
+ com.l = com.buf + nsize - 5;
}
/*
@@ -98,7 +98,7 @@
{
int adj_max_line_length; /* Adjusted max_line_length for comments
* that spill over the right margin */
- ssize_t last_blank; /* index of the last blank in combuf */
+ ssize_t last_blank; /* index of the last blank in com.buf */
char *t_ptr; /* used for moving string */
int break_delim = opt.comment_delimiter_on_blankline;
int l_just_saw_decl = ps.just_saw_decl;
@@ -184,10 +184,10 @@
Home |
Main Index |
Thread Index |
Old Index