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: manually wrap overly long lines
details: https://anonhg.NetBSD.org/src/rev/9043cd64385e
branches: trunk
changeset: 375874:9043cd64385e
user: rillig <rillig%NetBSD.org@localhost>
date: Thu May 18 05:33:27 2023 +0000
description:
indent: manually wrap overly long lines
No functional change.
diffstat:
tests/usr.bin/indent/opt_ci.c | 18 +++++++++-
usr.bin/indent/args.c | 34 ++++++++++++------
usr.bin/indent/debug.c | 13 ++++--
usr.bin/indent/indent.c | 41 +++++++++++++---------
usr.bin/indent/io.c | 10 +++--
usr.bin/indent/lexi.c | 76 ++++++++++++++++++++++--------------------
usr.bin/indent/parse.c | 18 ++++++---
usr.bin/indent/pr_comment.c | 44 ++++++++++++++----------
8 files changed, 154 insertions(+), 100 deletions(-)
diffs (truncated from 641 to 300 lines):
diff -r 51e1c3e0eb72 -r 9043cd64385e tests/usr.bin/indent/opt_ci.c
--- a/tests/usr.bin/indent/opt_ci.c Thu May 18 04:23:03 2023 +0000
+++ b/tests/usr.bin/indent/opt_ci.c Thu May 18 05:33:27 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: opt_ci.c,v 1.8 2022/04/24 09:04:12 rillig Exp $ */
+/* $NetBSD: opt_ci.c,v 1.9 2023/05/18 05:33:27 rillig Exp $ */
/*
* Tests for the option '-ci', which controls the indentation of continuation
@@ -234,3 +234,19 @@ function(void)
}
}
//indent end
+
+
+//indent input
+{
+ size_t last_word_len = com.len
+ - (size_t)(last_blank + 1);
+}
+//indent end
+
+//indent run -ldi0 -ci4
+{
+ size_t last_word_len = com.len
+/* $ FIXME: The '-' must be indented by 4 spaces. */
+ - (size_t)(last_blank + 1);
+}
+//indent end
diff -r 51e1c3e0eb72 -r 9043cd64385e usr.bin/indent/args.c
--- a/usr.bin/indent/args.c Thu May 18 04:23:03 2023 +0000
+++ b/usr.bin/indent/args.c Thu May 18 05:33:27 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: args.c,v 1.78 2023/05/18 04:23:03 rillig Exp $ */
+/* $NetBSD: args.c,v 1.79 2023/05/18 05:33:27 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: args.c,v 1.78 2023/05/18 04:23:03 rillig Exp $");
+__RCSID("$NetBSD: args.c,v 1.79 2023/05/18 05:33:27 rillig Exp $");
/* Read options from profile files and from the command line. */
@@ -159,7 +159,8 @@ set_special_option(const char *arg, cons
char *end;
opt.case_indent = (float)strtod(arg_end, &end);
if (*end != '\0')
- errx(1, "%s: argument \"%s\" to option \"-%.*s\" must be numeric",
+ errx(1, "%s: argument \"%s\" to option \"-%.*s\" "
+ "must be numeric",
option_source, arg_end, (int)(arg_end - arg), arg);
return true;
}
@@ -218,29 +219,35 @@ set_option(const char *arg, const char *
if (set_special_option(arg, option_source))
return;
- for (p = pro + array_length(pro); p-- != pro;)
- if ((arg_arg = skip_over(arg, p->p_may_negate, p->p_name)) != NULL)
+ for (p = pro + array_length(pro); p-- != pro;) {
+ arg_arg = skip_over(arg, p->p_may_negate, p->p_name);
+ if (arg_arg != NULL)
goto found;
+ }
errx(1, "%s: unknown option \"-%s\"", option_source, arg);
found:
if (p->p_is_bool) {
if (arg_arg[0] != '\0')
- errx(1, "%s: unknown option \"-%s\"", option_source, arg);
+ errx(1, "%s: unknown option \"-%s\"",
+ option_source, arg);
- *(bool *)p->p_var = p->p_may_negate ? arg[0] != 'n' : p->p_bool_value;
+ *(bool *)p->p_var =
+ p->p_may_negate ? arg[0] != 'n' : p->p_bool_value;
return;
}
char *end;
long num = strtol(arg_arg, &end, 10);
if (*end != '\0')
- errx(1, "%s: argument \"%s\" to option \"-%s\" must be an integer",
+ errx(1, "%s: argument \"%s\" to option \"-%s\" "
+ "must be an integer",
option_source, arg_arg, p->p_name);
if (!(ch_isdigit(*arg_arg) && p->i_min <= num && num <= p->i_max))
errx(1,
- "%s: argument \"%s\" to option \"-%s\" must be between %d and %d",
+ "%s: argument \"%s\" to option \"-%s\" "
+ "must be between %d and %d",
option_source, arg_arg, p->p_name, p->i_min, p->i_max);
*(int *)p->p_var = (int)num;
@@ -263,15 +270,18 @@ load_profile(const char *fname, bool mus
int ch, comment_ch = -1;
while ((ch = getc(f)) != EOF) {
- if (ch == '*' && comment_ch == -1 && n > 0 && buf[n - 1] == '/') {
+ if (ch == '*' && comment_ch == -1
+ && n > 0 && buf[n - 1] == '/') {
n--;
comment_ch = '*';
} else if (comment_ch != -1) {
- comment_ch = ch == '/' && comment_ch == '*' ? -1 : ch;
+ comment_ch = ch == '/' && comment_ch == '*'
+ ? -1 : ch;
} else if (ch_isspace((char)ch)) {
break;
} else if (n >= array_length(buf) - 2) {
- errx(1, "buffer overflow in %s, starting with '%.10s'",
+ errx(1, "buffer overflow in %s, "
+ "starting with '%.10s'",
fname, buf);
} else
buf[n++] = (char)ch;
diff -r 51e1c3e0eb72 -r 9043cd64385e usr.bin/indent/debug.c
--- a/usr.bin/indent/debug.c Thu May 18 04:23:03 2023 +0000
+++ b/usr.bin/indent/debug.c Thu May 18 05:33:27 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: debug.c,v 1.13 2023/05/18 04:23:03 rillig Exp $ */
+/* $NetBSD: debug.c,v 1.14 2023/05/18 05:33:27 rillig Exp $ */
/*-
* Copyright (c) 2023 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: debug.c,v 1.13 2023/05/18 04:23:03 rillig Exp $");
+__RCSID("$NetBSD: debug.c,v 1.14 2023/05/18 05:33:27 rillig Exp $");
#include <stdarg.h>
@@ -214,7 +214,8 @@ ps_paren_has_changed(const struct parser
return true;
for (int i = 0; i < ps.nparen; i++)
- if (curr[i].indent != prev[i].indent || curr[i].cast != prev[i].cast)
+ if (curr[i].indent != prev[i].indent
+ || curr[i].cast != prev[i].cast)
return true;
return false;
}
@@ -228,7 +229,8 @@ debug_ps_paren(const struct parser_state
debug_printf(" ps.paren:");
for (int i = 0; i < ps.nparen; i++) {
debug_printf(" %s%d",
- paren_level_cast_name[ps.paren[i].cast], ps.paren[i].indent);
+ paren_level_cast_name[ps.paren[i].cast],
+ ps.paren[i].indent);
}
if (ps.nparen == 0)
debug_printf(" none");
@@ -248,7 +250,8 @@ debug_parser_state(lexer_symbol lsym)
debug_print_buf("code", &code);
debug_print_buf("comment", &com);
- debug_println(" ps.prev_token = %s", lsym_name[ps.prev_token]);
+ debug_println(" ps.prev_token = %s",
+ lsym_name[ps.prev_token]);
debug_ps_bool(curr_col_1);
debug_ps_bool(next_col_1);
debug_ps_bool(next_unary);
diff -r 51e1c3e0eb72 -r 9043cd64385e usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c Thu May 18 04:23:03 2023 +0000
+++ b/usr.bin/indent/indent.c Thu May 18 05:33:27 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: indent.c,v 1.292 2023/05/18 04:23:03 rillig Exp $ */
+/* $NetBSD: indent.c,v 1.293 2023/05/18 05:33:27 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: indent.c,v 1.292 2023/05/18 04:23:03 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.293 2023/05/18 05:33:27 rillig Exp $");
#include <sys/param.h>
#include <err.h>
@@ -254,7 +254,8 @@ main_parse_command_line(int argc, char *
} else if (output == NULL) {
out_name = arg;
if (strcmp(in_name, out_name) == 0)
- errx(1, "input and output files must be different");
+ errx(1, "input and output files "
+ "must be different");
if ((output = fopen(out_name, "w")) == NULL)
err(1, "%s", out_name);
@@ -306,16 +307,16 @@ main_prepare_parsing(void)
static void
code_add_decl_indent(int decl_ind, bool tabs_to_var)
{
- int base_ind = ps.ind_level * opt.indent_size;
- int ind = base_ind + (int)code.len;
- int target_ind = base_ind + decl_ind;
+ int base = ps.ind_level * opt.indent_size;
+ int ind = base + (int)code.len;
+ int target = base + decl_ind;
size_t orig_code_len = code.len;
if (tabs_to_var)
- for (int next; (next = next_tab(ind)) <= target_ind; ind = next)
+ for (int next; (next = next_tab(ind)) <= target; ind = next)
buf_add_char(&code, '\t');
- for (; ind < target_ind; ind++)
+ for (; ind < target; ind++)
buf_add_char(&code, ' ');
if (code.len == orig_code_len && ps.want_blank) {
@@ -534,7 +535,8 @@ process_unary_op(void)
if (!ps.decl_indent_done && ps.in_decl && !ps.block_init &&
!ps.is_function_definition && ps.line_start_nparen == 0) {
/* pointer declarations */
- code_add_decl_indent(ps.decl_ind - (int)token.len, ps.tabs_to_var);
+ code_add_decl_indent(ps.decl_ind - (int)token.len,
+ ps.tabs_to_var);
ps.decl_indent_done = true;
} else if (want_blank_before_unary_op())
buf_add_char(&code, ' ');
@@ -772,7 +774,8 @@ process_else(void)
{
ps.in_stmt_or_decl = false;
- if (code.len > 0 && !(opt.cuddle_else && code.mem[code.len - 1] == '}')) {
+ if (code.len > 0
+ && !(opt.cuddle_else && code.mem[code.len - 1] == '}')) {
if (opt.verbose)
diag(0, "Line broken");
output_line();
@@ -827,7 +830,8 @@ process_ident(lexer_symbol lsym)
ps.line_start_nparen == 0) {
if (opt.decl_indent == 0
&& code.len > 0 && code.mem[code.len - 1] == '}')
- ps.decl_ind = ind_add(0, code.st, code.len) + 1;
+ ps.decl_ind =
+ ind_add(0, code.st, code.len) + 1;
code_add_decl_indent(ps.decl_ind, ps.tabs_to_var);
ps.decl_indent_done = true;
ps.want_blank = false;
@@ -975,7 +979,8 @@ process_preprocessing(void)
} else if (substring_starts_with(dir, "el")) { /* else, elif */
if (ifdef_level <= 0)
- diag(1, dir.s[2] == 'i' ? "Unmatched #elif" : "Unmatched #else");
+ diag(1, dir.s[2] == 'i'
+ ? "Unmatched #elif" : "Unmatched #else");
else
ps = state_stack[ifdef_level - 1];
@@ -1014,17 +1019,19 @@ main_loop(void)
if (lsym == lsym_eof)
return process_eof();
- if (lsym == lsym_if && ps.prev_token == lsym_else && opt.else_if)
+ if (lsym == lsym_if && ps.prev_token == lsym_else
+ && opt.else_if)
ps.force_nl = false;
if (lsym == lsym_newline || lsym == lsym_preprocessing)
ps.force_nl = false;
else if (lsym != lsym_comment) {
maybe_break_line(lsym);
- ps.in_stmt_or_decl = true; /* add an extra level of
- * indentation; turned
- * off again by a ';' or
- * '}' */
+ /*
+ * Add an extra level of indentation; turned off again
+ * by a ';' or '}'.
+ */
+ ps.in_stmt_or_decl = true;
if (com.len > 0)
move_com_to_code(lsym);
}
diff -r 51e1c3e0eb72 -r 9043cd64385e usr.bin/indent/io.c
--- a/usr.bin/indent/io.c Thu May 18 04:23:03 2023 +0000
+++ b/usr.bin/indent/io.c Thu May 18 05:33:27 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: io.c,v 1.177 2023/05/18 04:23:03 rillig Exp $ */
+/* $NetBSD: io.c,v 1.178 2023/05/18 05:33:27 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-4-Clause
@@ -38,7 +38,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: io.c,v 1.177 2023/05/18 04:23:03 rillig Exp $");
+__RCSID("$NetBSD: io.c,v 1.178 2023/05/18 05:33:27 rillig Exp $");
Home |
Main Index |
Thread Index |
Old Index