* src/system.h (x_timestyle_args): A new function refactored from ...
* src/ls.c (decode_switches): ... here.
* src/du.c: Use refactored x_timestyle_args() to output a custom error.
Addresses https://bugs.gnu.org/79113
#include <config.h>
#include <getopt.h>
#include <sys/types.h>
-#include "system.h"
#include "argmatch.h"
+#include "system.h"
#include "argv-iter.h"
#include "assure.h"
#include "di-set.h"
time_format = time_style + 1;
else
{
- switch (XARGMATCH ("time style", time_style,
- time_style_args, time_style_types))
+ switch (x_timestyle_match (time_style, /*allow_posix=*/ false,
+ time_style_args,
+ (char const *) time_style_types,
+ sizeof (*time_style_types), EXIT_FAILURE))
{
case full_iso_time_style:
time_format = "%Y-%m-%d %H:%M:%S.%N %z";
# define SA_RESTART 0
#endif
-#include "system.h"
#include <fnmatch.h>
#include "acl.h"
#include "argmatch.h"
+#include "system.h"
#include "assure.h"
#include "c-strcase.h"
#include "dev-ino.h"
}
else
{
- ptrdiff_t res = argmatch (style, time_style_args,
- (char const *) time_style_types,
- sizeof (*time_style_types));
- if (res < 0)
- {
- /* This whole block used to be a simple use of XARGMATCH.
- but that didn't print the "posix-"-prefixed variants or
- the "+"-prefixed format string option upon failure. */
- argmatch_invalid ("time style", style, res);
-
- /* The following is a manual expansion of argmatch_valid,
- but with the added "+ ..." description and the [posix-]
- prefixes prepended. Note that this simplification works
- only because all four existing time_style_types values
- are distinct. */
- fputs (_("Valid arguments are:\n"), stderr);
- char const *const *p = time_style_args;
- while (*p)
- fprintf (stderr, " - [posix-]%s\n", *p++);
- fputs (_(" - +FORMAT (e.g., +%H:%M) for a 'date'-style"
- " format\n"), stderr);
- usage (LS_FAILURE);
- }
- switch (res)
+ switch (x_timestyle_match (style, /*allow_posix=*/ true,
+ time_style_args,
+ (char const *) time_style_types,
+ sizeof (*time_style_types), LS_FAILURE))
{
case full_iso_time_style:
long_time_format[0] = long_time_format[1] =
quotearg_style (shell_escape_always_quoting_style, arg)
#define quoteaf_n(n, arg) \
quotearg_n_style (n, shell_escape_always_quoting_style, arg)
+
+/* Used instead of XARGMATCH() to provide a custom error message. */
+#ifdef XARGMATCH
+static inline ptrdiff_t
+x_timestyle_match (char const * style, bool allow_posix,
+ char const *const * timestyle_args,
+ char const * timestyle_types,
+ size_t timestyle_types_size,
+ int fail_status)
+{
+ ptrdiff_t res = argmatch (style, timestyle_args,
+ (char const *) timestyle_types,
+ timestyle_types_size);
+ if (res < 0)
+ {
+ /* This whole block used to be a simple use of XARGMATCH.
+ but that didn't print the "posix-"-prefixed variants or
+ the "+"-prefixed format string option upon failure. */
+ argmatch_invalid ("time style", style, res);
+
+ /* The following is a manual expansion of argmatch_valid,
+ but with the added "+ ..." description and the [posix-]
+ prefixes prepended. Note that this simplification works
+ only because all four existing time_style_types values
+ are distinct. */
+ fputs (_("Valid arguments are:\n"), stderr);
+ char const *const *p = timestyle_args;
+ char const *posix_prefix = allow_posix ? "[posix-]" : "";
+ while (*p)
+ fprintf (stderr, " - %s%s\n", posix_prefix, *p++);
+ fputs (_(" - +FORMAT (e.g., +%H:%M) for a 'date'-style"
+ " format\n"), stderr);
+ usage (fail_status);
+ }
+
+ return res;
+}
+#endif