indent: make error message for missing command line arguments clearer

This commit is contained in:
rillig 2021-11-25 21:48:23 +00:00
parent 51ce682b28
commit c680087d06
2 changed files with 11 additions and 12 deletions

View File

@ -1,5 +1,5 @@
#! /bin/sh
# $NetBSD: t_errors.sh,v 1.21 2021/11/25 21:45:28 rillig Exp $
# $NetBSD: t_errors.sh,v 1.22 2021/11/25 21:48:23 rillig Exp $
#
# Copyright (c) 2021 The NetBSD Foundation, Inc.
# All rights reserved.
@ -182,17 +182,16 @@ option_buffer_overflow_body()
atf_test_case 'option_special_missing_param'
option_special_missing_param_body()
{
# TODO: Write '-cli' instead of only 'cli'.
expect_error \
'indent: Command line: ``cli'\'\'' requires an argument' \
'indent: Command line: ``-cli'\'\'' requires an argument' \
-cli
expect_error \
'indent: Command line: ``T'\'\'' requires an argument' \
'indent: Command line: ``-T'\'\'' requires an argument' \
-T
expect_error \
'indent: Command line: ``U'\'\'' requires an argument' \
'indent: Command line: ``-U'\'\'' requires an argument' \
-U
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: args.c,v 1.71 2021/11/19 20:23:17 rillig Exp $ */
/* $NetBSD: args.c,v 1.72 2021/11/25 21:48:23 rillig Exp $ */
/*-
* SPDX-License-Identifier: BSD-4-Clause
@ -43,7 +43,7 @@ static char sccsid[] = "@(#)args.c 8.1 (Berkeley) 6/6/93";
#include <sys/cdefs.h>
#if defined(__NetBSD__)
__RCSID("$NetBSD: args.c,v 1.71 2021/11/19 20:23:17 rillig Exp $");
__RCSID("$NetBSD: args.c,v 1.72 2021/11/25 21:48:23 rillig Exp $");
#elif defined(__FreeBSD__)
__FBSDID("$FreeBSD: head/usr.bin/indent/args.c 336318 2018-07-15 21:04:21Z pstef $");
#endif
@ -162,7 +162,7 @@ set_special_option(const char *arg, const char *option_source)
if (strncmp(arg, "cli", 3) == 0) {
arg_end = arg + 3;
if (arg_end[0] == '\0')
goto need_param;
goto need_arg;
char *end;
opt.case_indent = (float)strtod(arg_end, &end);
if (*end != '\0')
@ -182,7 +182,7 @@ set_special_option(const char *arg, const char *option_source)
if (arg[0] == 'T') {
arg_end = arg + 1;
if (arg_end[0] == '\0')
goto need_param;
goto need_arg;
register_typename(arg_end);
return true;
}
@ -190,15 +190,15 @@ set_special_option(const char *arg, const char *option_source)
if (arg[0] == 'U') {
arg_end = arg + 1;
if (arg_end[0] == '\0')
goto need_param;
goto need_arg;
add_typedefs_from_file(arg_end);
return true;
}
return false;
need_param:
errx(1, "%s: ``%.*s'' requires an argument",
need_arg:
errx(1, "%s: ``-%.*s'' requires an argument",
option_source, (int)(arg_end - arg), arg);
/* NOTREACHED */
}