summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bootstrap.conf1
-rw-r--r--configure.ac6
-rw-r--r--src/main.c35
3 files changed, 28 insertions, 14 deletions
diff --git a/bootstrap.conf b/bootstrap.conf
index 682e578e..54d4775a 100644
--- a/bootstrap.conf
+++ b/bootstrap.conf
@@ -20,6 +20,7 @@
gnulib_modules='
alloca
announce-gen
+argmatch
atexit
binary-io
btowc
diff --git a/configure.ac b/configure.ac
index 56452e75..820b4590 100644
--- a/configure.ac
+++ b/configure.ac
@@ -128,6 +128,12 @@ if test "$gl_gcc_warnings" = yes; then
AC_SUBST([GNULIB_WARN_CFLAGS])
fi
+# By default, argmatch should fail calling usage (1).
+AC_DEFINE([ARGMATCH_DIE], [usage (1)],
+ [Define to the function xargmatch calls on failures.])
+AC_DEFINE([ARGMATCH_DIE_DECL], [void usage (int _e)],
+ [Define to the declaration of the xargmatch failure function.])
+
dnl Checks for header files.
AC_HEADER_STDC
AC_HEADER_DIRENT
diff --git a/src/main.c b/src/main.c
index 690c905b..ddb1413a 100644
--- a/src/main.c
+++ b/src/main.c
@@ -32,6 +32,7 @@
#include <stdio.h>
#include "system.h"
+#include "argmatch.h"
#include "c-ctype.h"
#include "closeout.h"
#include "error.h"
@@ -351,13 +352,25 @@ unsigned char eolbyte;
static char const *filename;
static int errseen;
-/* How to handle directories. */
-static enum
+enum directories_type
{
- READ_DIRECTORIES,
+ READ_DIRECTORIES = 2,
RECURSE_DIRECTORIES,
SKIP_DIRECTORIES
- } directories = READ_DIRECTORIES;
+ };
+
+/* How to handle directories. */
+static char const *const directories_args[] =
+{
+ "read", "recurse", "skip", NULL
+};
+static enum directories_type const directories_types[] =
+{
+ READ_DIRECTORIES, RECURSE_DIRECTORIES, SKIP_DIRECTORIES
+};
+ARGMATCH_VERIFY (directories_args, directories_types);
+
+static enum directories_type directories = READ_DIRECTORIES;
/* How to handle devices. */
static enum
@@ -1351,8 +1364,8 @@ grepdir (char const *dir, struct stats const *stats)
return status;
}
-static void usage (int status) __attribute__ ((noreturn));
-static void
+void usage (int status) __attribute__ ((noreturn));
+void
usage (int status)
{
if (status != 0)
@@ -1863,14 +1876,8 @@ main (int argc, char **argv)
break;
case 'd':
- if (STREQ (optarg, "read"))
- directories = READ_DIRECTORIES;
- else if (STREQ (optarg, "skip"))
- directories = SKIP_DIRECTORIES;
- else if (STREQ (optarg, "recurse"))
- directories = RECURSE_DIRECTORIES;
- else
- error (EXIT_TROUBLE, 0, _("unknown directories method"));
+ directories = XARGMATCH ("--directories", optarg,
+ directories_args, directories_types);
break;
case 'e':