aboutsummaryrefslogtreecommitdiff
path: root/cat/cmdline.c
diff options
context:
space:
mode:
Diffstat (limited to 'cat/cmdline.c')
-rw-r--r--cat/cmdline.c29
1 files changed, 17 insertions, 12 deletions
diff --git a/cat/cmdline.c b/cat/cmdline.c
index cae19beb7d4c..851b63de06e5 100644
--- a/cat/cmdline.c
+++ b/cat/cmdline.c
@@ -24,11 +24,10 @@
*/
/*
- * Command line parser for tar.
+ * Command line parser for bsdcat.
*/
#include "bsdcat_platform.h"
-__FBSDID("$FreeBSD$");
#ifdef HAVE_ERRNO_H
#include <errno.h>
@@ -44,12 +43,12 @@ __FBSDID("$FreeBSD$");
#include "err.h"
/*
- * Short options for tar. Please keep this sorted.
+ * Short options for bsdcat. Please keep this sorted.
*/
static const char *short_options = "h";
/*
- * Long options for tar. Please keep this list sorted.
+ * Long options for bsdcat. Please keep this list sorted.
*
* The symbolic names for options that lack a short equivalent are
* defined in bsdcat.h. Also note that so far I've found no need
@@ -61,7 +60,7 @@ static const struct bsdcat_option {
const char *name;
int required; /* 1 if this option requires an argument. */
int equivalent; /* Equivalent short option. */
-} tar_longopts[] = {
+} bsdcat_longopts[] = {
{ "help", 0, 'h' },
{ "version", 0, OPTION_VERSION },
{ NULL, 0, 0 }
@@ -90,7 +89,7 @@ static const struct bsdcat_option {
* -W long options: There's an obscure GNU convention (only rarely
* supported even there) that allows "-W option=argument" as an
* alternative way to support long options. This was supported in
- * early bsdcat as a way to access long options on platforms that did
+ * early bsdtar as a way to access long options on platforms that did
* not support getopt_long() and is preserved here for backwards
* compatibility. (Of course, if I'd started with a custom
* command-line parser from the beginning, I would have had normal
@@ -115,12 +114,18 @@ bsdcat_getopt(struct bsdcat *bsdcat)
enum { state_start = 0, state_old_tar, state_next_word,
state_short, state_long };
- const struct bsdcat_option *popt, *match = NULL, *match2 = NULL;
- const char *p, *long_prefix = "--";
+ const struct bsdcat_option *popt, *match, *match2;
+ const char *p, *long_prefix;
size_t optlength;
- int opt = '?';
- int required = 0;
+ int opt;
+ int required;
+again:
+ match = NULL;
+ match2 = NULL;
+ long_prefix = "--";
+ opt = '?';
+ required = 0;
bsdcat->argument = NULL;
/* First time through, initialize everything. */
@@ -173,7 +178,7 @@ bsdcat_getopt(struct bsdcat *bsdcat)
if (opt == '\0') {
/* End of this group; recurse to get next option. */
bsdcat->getopt_state = state_next_word;
- return bsdcat_getopt(bsdcat);
+ goto again;
}
/* Does this option take an argument? */
@@ -223,7 +228,7 @@ bsdcat_getopt(struct bsdcat *bsdcat)
}
/* Search the table for an unambiguous match. */
- for (popt = tar_longopts; popt->name != NULL; popt++) {
+ for (popt = bsdcat_longopts; popt->name != NULL; popt++) {
/* Short-circuit if first chars don't match. */
if (popt->name[0] != bsdcat->getopt_word[0])
continue;