Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/indent use stdarg, annotate function as __printflike...
details: https://anonhg.NetBSD.org/src/rev/79262c673135
branches: trunk
changeset: 1004262:79262c673135
user: christos <christos%NetBSD.org@localhost>
date: Sat Oct 19 15:44:31 2019 +0000
description:
use stdarg, annotate function as __printflike and fix broken formats.
diffstat:
usr.bin/indent/indent.c | 38 +++++++++++++++---------------
usr.bin/indent/indent.h | 14 +++++++++--
usr.bin/indent/io.c | 59 +++++++++++++-----------------------------------
usr.bin/indent/lexi.c | 6 ++--
usr.bin/indent/parse.c | 8 +++---
5 files changed, 53 insertions(+), 72 deletions(-)
diffs (truncated from 359 to 300 lines):
diff -r 08c9c4f8b016 -r 79262c673135 usr.bin/indent/indent.c
--- a/usr.bin/indent/indent.c Sat Oct 19 14:42:30 2019 +0000
+++ b/usr.bin/indent/indent.c Sat Oct 19 15:44:31 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: indent.c,v 1.25 2019/04/04 15:22:13 kamil Exp $ */
+/* $NetBSD: indent.c,v 1.26 2019/10/19 15:44:31 christos 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.25 2019/04/04 15:22:13 kamil Exp $");
+__RCSID("$NetBSD: indent.c,v 1.26 2019/10/19 15:44:31 christos Exp $");
#elif defined(__FreeBSD__)
__FBSDID("$FreeBSD: head/usr.bin/indent/indent.c 340138 2018-11-04 19:24:49Z oshogbo $");
#endif
@@ -360,7 +360,7 @@
break; /* we are at end of comment */
if (sc_end >= &save_com[sc_size]) { /* check for temp buffer
* overflow */
- diag2(1, "Internal buffer overflow - Move big comment from right after if, while, or whatever");
+ diag(1, "Internal buffer overflow - Move big comment from right after if, while, or whatever");
fflush(output);
exit(1);
}
@@ -429,7 +429,7 @@
*sc_end++ = ' ';
if (opt.verbose) /* print error msg if the line was
* not already broken */
- diag2(0, "Line broken");
+ diag(0, "Line broken");
}
for (t_ptr = token; *t_ptr; ++t_ptr)
*sc_end++ = *t_ptr;
@@ -498,7 +498,7 @@
|| s_com != e_com) /* must dump end of line */
dump_line();
if (ps.tos > 1) /* check for balanced braces */
- diag2(1, "Stuff missing from end of file");
+ diag(1, "Stuff missing from end of file");
if (opt.verbose) {
printf("There were %d output lines and %d comments\n",
@@ -519,7 +519,7 @@
(type_code != lbrace || !opt.btype_2)) {
/* we should force a broken line here */
if (opt.verbose)
- diag2(0, "Line broken");
+ diag(0, "Line broken");
dump_line();
ps.want_blank = false; /* dont insert blank at line start */
force_nl = false;
@@ -574,7 +574,7 @@
case lparen: /* got a '(' or '[' */
/* count parens to make Healy happy */
if (++ps.p_l_follow == nitems(ps.paren_indents)) {
- diag3(0, "Reached internal limit of %d unclosed parens",
+ diag(0, "Reached internal limit of %zu unclosed parens",
nitems(ps.paren_indents));
ps.p_l_follow--;
}
@@ -625,7 +625,7 @@
ps.not_cast_mask &= (1 << ps.p_l_follow) - 1;
if (--ps.p_l_follow < 0) {
ps.p_l_follow = 0;
- diag3(0, "Extra %c", *token);
+ diag(0, "Extra %c", *token);
}
if (e_code == s_code) /* if the paren starts the line */
ps.paren_level = ps.p_l_follow; /* then indent it */
@@ -779,7 +779,7 @@
* stmt. It is a bit complicated, because the semicolon might
* be in a for stmt
*/
- diag2(1, "Unbalanced parens");
+ diag(1, "Unbalanced parens");
ps.p_l_follow = 0;
if (sp_sw) { /* this is a check for an if, while, etc. with
* unbalanced parens */
@@ -828,7 +828,7 @@
if (ps.p_l_follow > 0) { /* check for preceding unbalanced
* parens */
- diag2(1, "Unbalanced parens");
+ diag(1, "Unbalanced parens");
ps.p_l_follow = 0;
if (sp_sw) { /* check for unclosed if, for, etc. */
sp_sw = false;
@@ -843,7 +843,7 @@
* declaration or an init */
di_stack[ps.dec_nest] = dec_ind;
if (++ps.dec_nest == nitems(di_stack)) {
- diag3(0, "Reached internal limit of %d struct levels",
+ diag(0, "Reached internal limit of %zu struct levels",
nitems(di_stack));
ps.dec_nest--;
}
@@ -876,7 +876,7 @@
* declarations */
parse(semicolon);
if (ps.p_l_follow) {/* check for unclosed if, for, else. */
- diag2(1, "Unbalanced parens");
+ diag(1, "Unbalanced parens");
ps.p_l_follow = 0;
sp_sw = false;
}
@@ -885,7 +885,7 @@
if (s_code != e_code && !ps.block_init) { /* '}' must be first on
* line */
if (opt.verbose)
- diag2(0, "Line broken");
+ diag(0, "Line broken");
dump_line();
}
*e_code++ = '}';
@@ -928,7 +928,7 @@
if (*token == 'e') {
if (e_code != s_code && (!opt.cuddle_else || e_code[-1] != '}')) {
if (opt.verbose)
- diag2(0, "Line broken");
+ diag(0, "Line broken");
dump_line();/* make sure this starts a line */
ps.want_blank = false;
}
@@ -939,7 +939,7 @@
else {
if (e_code != s_code) { /* make sure this starts a line */
if (opt.verbose)
- diag2(0, "Line broken");
+ diag(0, "Line broken");
dump_line();
ps.want_blank = false;
}
@@ -1170,11 +1170,11 @@
state_stack[ifdef_level++] = ps;
}
else
- diag2(1, "#if stack overflow");
+ diag(1, "#if stack overflow");
}
else if (strncmp(s_lab, "#el", 3) == 0) { /* else, elif */
if (ifdef_level <= 0)
- diag2(1, s_lab[3] == 'i' ? "Unmatched #elif" : "Unmatched #else");
+ diag(1, s_lab[3] == 'i' ? "Unmatched #elif" : "Unmatched #else");
else {
match_state[ifdef_level - 1] = ps;
ps = state_stack[ifdef_level - 1];
@@ -1182,7 +1182,7 @@
}
else if (strncmp(s_lab, "#endif", 6) == 0) {
if (ifdef_level <= 0)
- diag2(1, "Unmatched #endif");
+ diag(1, "Unmatched #endif");
else
ifdef_level--;
} else {
@@ -1203,7 +1203,7 @@
if (strncmp(s_lab + 1, recognized[d].string, recognized[d].size) == 0)
break;
if (d < 0) {
- diag2(1, "Unrecognized cpp directive");
+ diag(1, "Unrecognized cpp directive");
break;
}
}
diff -r 08c9c4f8b016 -r 79262c673135 usr.bin/indent/indent.h
--- a/usr.bin/indent/indent.h Sat Oct 19 14:42:30 2019 +0000
+++ b/usr.bin/indent/indent.h Sat Oct 19 15:44:31 2019 +0000
@@ -1,3 +1,5 @@
+/* $NetBSD: indent.h,v 1.2 2019/10/19 15:44:31 christos Exp $ */
+
/*-
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
*
@@ -27,8 +29,16 @@
*/
#if 0
+#if defined(__NetBSD__)
+__RCSID("$NetBSD: indent.h,v 1.2 2019/10/19 15:44:31 christos Exp $");
+#elif defined(__FreeBSD__)
__FBSDID("$FreeBSD: head/usr.bin/indent/indent.h 336333 2018-07-16 05:46:50Z pstef $");
#endif
+#endif
+
+#ifndef nitems
+#define nitems(array) (sizeof (array) / sizeof (array[0]))
+#endif
void add_typename(const char *);
void alloc_typenames(void);
@@ -38,9 +48,7 @@
int count_spaces_until(int, char *, char *);
void init_constant_tt(void);
int lexi(struct parser_state *);
-void diag2(int, const char *);
-void diag3(int, const char *, int);
-void diag4(int, const char *, int, int);
+void diag(int, const char *, ...) __printflike(2, 3);
void dump_line(void);
void fill_buffer(void);
void parse(int);
diff -r 08c9c4f8b016 -r 79262c673135 usr.bin/indent/io.c
--- a/usr.bin/indent/io.c Sat Oct 19 14:42:30 2019 +0000
+++ b/usr.bin/indent/io.c Sat Oct 19 15:44:31 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: io.c,v 1.19 2019/04/04 15:22:13 kamil Exp $ */
+/* $NetBSD: io.c,v 1.20 2019/10/19 15:44:31 christos 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.19 2019/04/04 15:22:13 kamil Exp $");
+__RCSID("$NetBSD: io.c,v 1.20 2019/10/19 15:44:31 christos Exp $");
#elif defined(__FreeBSD__)
__FBSDID("$FreeBSD: head/usr.bin/indent/io.c 334927 2018-06-10 16:44:18Z pstef $");
#endif
@@ -57,6 +57,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <stdarg.h>
#include "indent_globs.h"
#include "indent.h"
@@ -484,52 +485,24 @@
}
void
-diag4(int level, const char *msg, int a, int b)
+diag(int level, const char *msg, ...)
{
- if (level)
- found_err = 1;
- if (output == stdout) {
- fprintf(stdout, "/**INDENT** %s@%d: ", level == 0 ? "Warning" : "Error", line_no);
- fprintf(stdout, msg, a, b);
- fprintf(stdout, " */\n");
- }
- else {
- fprintf(stderr, "%s@%d: ", level == 0 ? "Warning" : "Error", line_no);
- fprintf(stderr, msg, a, b);
- fprintf(stderr, "\n");
- }
-}
+ va_list ap;
+ const char *s, *e;
-void
-diag3(int level, const char *msg, int a)
-{
if (level)
found_err = 1;
- if (output == stdout) {
- fprintf(stdout, "/**INDENT** %s@%d: ", level == 0 ? "Warning" : "Error", line_no);
- fprintf(stdout, msg, a);
- fprintf(stdout, " */\n");
- }
- else {
- fprintf(stderr, "%s@%d: ", level == 0 ? "Warning" : "Error", line_no);
- fprintf(stderr, msg, a);
- fprintf(stderr, "\n");
- }
-}
-void
-diag2(int level, const char *msg)
-{
- if (level)
- found_err = 1;
if (output == stdout) {
- fprintf(stdout, "/**INDENT** %s@%d: ", level == 0 ? "Warning" : "Error", line_no);
- fprintf(stdout, "%s", msg);
- fprintf(stdout, " */\n");
+ s = "/**INDENT** ";
+ e = " */";
+ } else {
+ s = e = "";
}
- else {
- fprintf(stderr, "%s@%d: ", level == 0 ? "Warning" : "Error", line_no);
- fprintf(stderr, "%s", msg);
- fprintf(stderr, "\n");
- }
+
+ va_start(ap, msg);
+ fprintf(stderr, "%s%s@%d: ", s, level == 0 ? "Warning" : "Error", line_no);
+ vfprintf(stderr, msg, ap);
+ fprintf(stderr, "%s\n", e);
+ va_end(ap);
}
diff -r 08c9c4f8b016 -r 79262c673135 usr.bin/indent/lexi.c
--- a/usr.bin/indent/lexi.c Sat Oct 19 14:42:30 2019 +0000
+++ b/usr.bin/indent/lexi.c Sat Oct 19 15:44:31 2019 +0000
@@ -1,4 +1,4 @@
Home |
Main Index |
Thread Index |
Old Index