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: use strlen instead of own implementation
details: https://anonhg.NetBSD.org/src/rev/499de106a59a
branches: trunk
changeset: 1023770:499de106a59a
user: rillig <rillig%NetBSD.org@localhost>
date: Sat Sep 25 22:24:35 2021 +0000
description:
indent: use strlen instead of own implementation
The two loops looks similar but differ in a crucial detail that makes up
for a '+ 1'.
No functional change.
diffstat:
usr.bin/indent/indent.c | 35 +++++++++++------------------------
1 files changed, 11 insertions(+), 24 deletions(-)
diffs (77 lines):
diff -r 208e9894b88d -r 499de106a59a usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c Sat Sep 25 22:16:58 2021 +0000
+++ b/usr.bin/indent/indent.c Sat Sep 25 22:24:35 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: indent.c,v 1.81 2021/09/25 22:14:21 rillig Exp $ */
+/* $NetBSD: indent.c,v 1.82 2021/09/25 22:24:35 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-4-Clause
@@ -43,7 +43,7 @@
#include <sys/cdefs.h>
#if defined(__NetBSD__)
-__RCSID("$NetBSD: indent.c,v 1.81 2021/09/25 22:14:21 rillig Exp $");
+__RCSID("$NetBSD: indent.c,v 1.82 2021/09/25 22:24:35 rillig Exp $");
#elif defined(__FreeBSD__)
__FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
#endif
@@ -53,14 +53,14 @@
#include <sys/capsicum.h>
#include <capsicum_helpers.h>
#endif
+#include <ctype.h>
#include <err.h>
#include <errno.h>
#include <fcntl.h>
-#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <ctype.h>
+#include <unistd.h>
#include "indent.h"
@@ -658,15 +658,7 @@
if (!ps.dumped_decl_indent && ps.in_decl && !ps.block_init &&
ps.procname[0] == '\0' && ps.paren_level == 0) {
/* pointer declarations */
-
- /*
- * if this is a unary op in a declaration, we should indent
- * this token
- */
- int i;
- for (i = 0; token.s[i] != '\0'; ++i)
- /* find length of token */;
- indent_declaration(dec_ind - i, tabs_to_var);
+ indent_declaration(dec_ind - (int)strlen(token.s), tabs_to_var);
ps.dumped_decl_indent = true;
} else if (ps.want_blank)
*code.e++ = ' ';
@@ -968,18 +960,13 @@
if ( /* !ps.in_or_st && */ ps.decl_nest <= 0)
ps.just_saw_decl = 2;
prefix_blankline_requested = false;
- int i;
- for (i = 0; token.s[i++] != '\0';); /* get length of token */
- if (ps.ind_level == 0 || ps.decl_nest > 0) {
- /* global variable or struct member in local variable */
- *out_dec_ind = opt.decl_indent > 0 ? opt.decl_indent : i;
- *out_tabs_to_var = opt.use_tabs ? opt.decl_indent > 0 : false;
- } else {
- /* local variable */
- *out_dec_ind = opt.local_decl_indent > 0 ? opt.local_decl_indent : i;
- *out_tabs_to_var = opt.use_tabs ? opt.local_decl_indent > 0 : false;
- }
+ int len = (int)strlen(token.s) + 1;
+ int ind = ps.ind_level == 0 || ps.decl_nest > 0
+ ? opt.decl_indent /* global variable or local member */
+ : opt.local_decl_indent; /* local variable */
+ *out_dec_ind = ind > 0 ? ind : len;
+ *out_tabs_to_var = opt.use_tabs ? ind > 0 : false;
}
static void
Home |
Main Index |
Thread Index |
Old Index