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: miscellaneous cleanups
details: https://anonhg.NetBSD.org/src/rev/32273708ec2c
branches: trunk
changeset: 376433:32273708ec2c
user: rillig <rillig%NetBSD.org@localhost>
date: Sat Jun 17 22:28:49 2023 +0000
description:
indent: miscellaneous cleanups
No binary change.
diffstat:
usr.bin/indent/debug.c | 6 +-
usr.bin/indent/indent.c | 14 ++++----
usr.bin/indent/io.c | 54 +++++++++++++++++--------------
usr.bin/indent/lexi.c | 76 ++++++++++++++++++++++----------------------
usr.bin/indent/parse.c | 14 ++++----
usr.bin/indent/pr_comment.c | 62 ++++++++++++++++--------------------
6 files changed, 113 insertions(+), 113 deletions(-)
diffs (truncated from 650 to 300 lines):
diff -r d4fed12b795b -r 32273708ec2c usr.bin/indent/debug.c
--- a/usr.bin/indent/debug.c Sat Jun 17 22:09:24 2023 +0000
+++ b/usr.bin/indent/debug.c Sat Jun 17 22:28:49 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: debug.c,v 1.66 2023/06/16 23:51:32 rillig Exp $ */
+/* $NetBSD: debug.c,v 1.67 2023/06/17 22:28:49 rillig Exp $ */
/*-
* Copyright (c) 2023 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: debug.c,v 1.66 2023/06/16 23:51:32 rillig Exp $");
+__RCSID("$NetBSD: debug.c,v 1.67 2023/06/17 22:28:49 rillig Exp $");
#include <stdarg.h>
#include <string.h>
@@ -384,7 +384,7 @@ debug_psyms_stack(const char *situation)
{
debug_printf("parse stack %s:", situation);
const struct psym_stack *psyms = &ps.psyms;
- for (size_t i = 0; i < psyms->len; ++i)
+ for (size_t i = 0; i < psyms->len; i++)
debug_printf(" %d %s",
psyms->ind_level[i], psym_name[psyms->sym[i]]);
debug_println("");
diff -r d4fed12b795b -r 32273708ec2c usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c Sat Jun 17 22:09:24 2023 +0000
+++ b/usr.bin/indent/indent.c Sat Jun 17 22:28:49 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: indent.c,v 1.379 2023/06/16 23:51:32 rillig Exp $ */
+/* $NetBSD: indent.c,v 1.380 2023/06/17 22:28:49 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: indent.c,v 1.379 2023/06/16 23:51:32 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.380 2023/06/17 22:28:49 rillig Exp $");
#include <sys/param.h>
#include <err.h>
@@ -177,9 +177,9 @@ ind_add(int ind, const char *s, size_t l
else if (*p == '\t')
ind = next_tab(ind);
else if (*p == '\b')
- --ind;
+ ind--;
else
- ++ind;
+ ind++;
}
return ind;
}
@@ -201,7 +201,7 @@ load_profiles(int argc, char **argv)
{
const char *profile_name = NULL;
- for (int i = 1; i < argc; ++i) {
+ for (int i = 1; i < argc; i++) {
const char *arg = argv[i];
if (strcmp(arg, "-npro") == 0)
@@ -255,7 +255,7 @@ copy_to_bak_file(void)
static void
parse_command_line(int argc, char **argv)
{
- for (int i = 1; i < argc; ++i) {
+ for (int i = 1; i < argc; i++) {
const char *arg = argv[i];
if (arg[0] == '-') {
@@ -566,7 +566,7 @@ process_newline(void)
output_line();
stay_in_line:
- ++line_no;
+ line_no++;
}
static bool
diff -r d4fed12b795b -r 32273708ec2c usr.bin/indent/io.c
--- a/usr.bin/indent/io.c Sat Jun 17 22:09:24 2023 +0000
+++ b/usr.bin/indent/io.c Sat Jun 17 22:28:49 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: io.c,v 1.227 2023/06/16 11:48:32 rillig Exp $ */
+/* $NetBSD: io.c,v 1.228 2023/06/17 22:28:49 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: io.c,v 1.227 2023/06/16 11:48:32 rillig Exp $");
+__RCSID("$NetBSD: io.c,v 1.228 2023/06/17 22:28:49 rillig Exp $");
#include <stdio.h>
@@ -331,6 +331,10 @@ output_comment(void)
write_range(p, com.len - (size_t)(p - com.s));
}
+/*
+ * Write a line of formatted source to the output file. The line consists of
+ * the label, the code and the comment.
+ */
static void
output_indented_line(void)
{
@@ -382,29 +386,9 @@ is_stmt_cont(void)
&& ps.init_level == 0;
}
-/*
- * Write a line of formatted source to the output file. The line consists of
- * the label, the code and the comment.
- */
-void
-output_line(void)
+static void
+prepare_next_line(void)
{
- debug_blank_line();
- debug_printf("%s", __func__);
- debug_buffers();
-
- if (indent_enabled == indent_on)
- output_indented_line();
- else if (indent_enabled == indent_last_off_line) {
- indent_enabled = indent_on;
- write_range(out.indent_off_text.s, out.indent_off_text.len);
- buf_clear(&out.indent_off_text);
- }
-
- buf_clear(&lab);
- buf_clear(&code);
- buf_clear(&com);
-
ps.line_has_decl = ps.in_decl;
ps.line_has_func_def = false;
ps.line_is_stmt_cont = is_stmt_cont();
@@ -427,6 +411,28 @@ output_line(void)
}
void
+output_line(void)
+{
+ debug_blank_line();
+ debug_printf("%s", __func__);
+ debug_buffers();
+
+ if (indent_enabled == indent_on)
+ output_indented_line();
+ else if (indent_enabled == indent_last_off_line) {
+ indent_enabled = indent_on;
+ write_range(out.indent_off_text.s, out.indent_off_text.len);
+ buf_clear(&out.indent_off_text);
+ }
+
+ buf_clear(&lab);
+ buf_clear(&code);
+ buf_clear(&com);
+
+ prepare_next_line();
+}
+
+void
finish_output(void)
{
output_line();
diff -r d4fed12b795b -r 32273708ec2c usr.bin/indent/lexi.c
--- a/usr.bin/indent/lexi.c Sat Jun 17 22:09:24 2023 +0000
+++ b/usr.bin/indent/lexi.c Sat Jun 17 22:28:49 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lexi.c,v 1.230 2023/06/16 23:51:32 rillig Exp $ */
+/* $NetBSD: lexi.c,v 1.231 2023/06/17 22:28:49 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: lexi.c,v 1.230 2023/06/16 23:51:32 rillig Exp $");
+__RCSID("$NetBSD: lexi.c,v 1.231 2023/06/17 22:28:49 rillig Exp $");
#include <stdlib.h>
#include <string.h>
@@ -186,7 +186,7 @@ static void
lex_number(void)
{
for (unsigned char s = 'A'; s != 'f' && s != 'i' && s != 'u';) {
- unsigned char ch = (unsigned char)inp_p[0];
+ unsigned char ch = (unsigned char)*inp_p;
if (ch == '\\' && inp_p[1] == '\n') {
inp_p++;
inp_skip();
@@ -199,10 +199,8 @@ lex_number(void)
unsigned char row = lex_number_row[ch];
if (lex_number_state[row][s - 'A'] == ' ') {
- /*-
- * lex_number_state[0][s - 'A'] now indicates the type:
- * f = floating, i = integer, u = unknown
- */
+ // lex_number_state[0][s - 'A'] now indicates the type:
+ // f = floating, i = integer, u = unknown
return;
}
@@ -230,7 +228,7 @@ static void
lex_char_or_string(void)
{
for (char delim = token.s[token.len - 1];;) {
- if (inp_p[0] == '\n') {
+ if (*inp_p == '\n') {
diag(1, "Unterminated literal");
return;
}
@@ -240,8 +238,8 @@ lex_char_or_string(void)
return;
if (token.s[token.len - 1] == '\\') {
- if (inp_p[0] == '\n')
- ++line_no;
+ if (*inp_p == '\n')
+ line_no++;
token_add_char(inp_next());
}
}
@@ -325,8 +323,8 @@ cmp_keyword_by_name(const void *key, con
}
/*
- * Looking at something like 'function_name(...)' in a line, guess whether
- * this starts a function definition or a declaration.
+ * Looking at the '(', guess whether this starts a function definition or a
+ * function declaration.
*/
static bool
probably_function_definition(void)
@@ -359,13 +357,15 @@ probably_function_definition(void)
return false;
}
- /* To further reduce the cases where indent wrongly treats an
+ /*
+ * To further reduce the cases where indent wrongly treats an
* incomplete function declaration as a function definition, thus
* adding a newline before the function name, it may be worth looking
* for parameter names, as these are often omitted in function
* declarations and only included in function definitions. Or just
* increase the lookahead to more than just the current line of input,
- * until the next '{'. */
+ * until the next '{'.
+ */
return true;
}
@@ -388,7 +388,7 @@ lexi_alnum(void)
} else
return lsym_eof; /* just as a placeholder */
- while (ch_isblank(inp_p[0]))
+ while (ch_isblank(*inp_p))
inp_p++;
ps.next_unary = ps.prev_lsym == lsym_tag
@@ -397,7 +397,7 @@ lexi_alnum(void)
if (ps.prev_lsym == lsym_tag && ps.paren.len == 0)
return lsym_type;
- token_add_char('\0');
+ token_add_char('\0'); // Terminate in non-debug mode as well.
token.len--;
const struct keyword *kw = bsearch(token.s, keywords,
array_length(keywords), sizeof(keywords[0]), cmp_keyword_by_name);
@@ -432,7 +432,7 @@ found_typename:
}
}
- if (inp_p[0] == '(' && ps.psyms.len <= 2 && ps.ind_level == 0 &&
+ if (*inp_p == '(' && ps.psyms.len < 3 && ps.ind_level == 0 &&
!ps.in_func_def_params && !ps.in_init) {
if (ps.paren.len == 0 && probably_function_definition()) {
@@ -467,15 +467,15 @@ is_asterisk_pointer(void)
static bool
probably_in_function_definition(void)
{
- for (const char *tp = inp_p; *tp != '\n';) {
- if (ch_isspace(*tp))
- tp++;
- else if (is_identifier_start(*tp)) {
- tp++;
- while (is_identifier_part(*tp))
Home |
Main Index |
Thread Index |
Old Index