summaryrefslogtreecommitdiffstats
path: root/usr.sbin/bgpctl/parser.c
diff options
context:
space:
mode:
authorhenning <henning@openbsd.org>2004-10-26 13:12:22 +0000
committerhenning <henning@openbsd.org>2004-10-26 13:12:22 +0000
commit4e9d3417a510ff87fa2aa6a46427364a70bdaf8d (patch)
tree0a9fab5e0adf094d55d4d4c47294c7d94f43e005 /usr.sbin/bgpctl/parser.c
parentit is iwicontrol(8), not iwictl(8). ok deraadt fgsch (diff)
downloadwireguard-openbsd-4e9d3417a510ff87fa2aa6a46427364a70bdaf8d.tar.xz
wireguard-openbsd-4e9d3417a510ff87fa2aa6a46427364a70bdaf8d.zip
ease the parser a bit.
parse() now wants the first argv member to be the first argument it parses, i. e. it does not skip over argv[0] any more, caller has to account for that. the caller does the usual getopt followed by argv += optind; argc -= optind; dance so this is accounted for. in parse() don't use a seperate curarg counter, just in/decrease argv/argc claudio ok
Diffstat (limited to 'usr.sbin/bgpctl/parser.c')
-rw-r--r--usr.sbin/bgpctl/parser.c27
1 files changed, 8 insertions, 19 deletions
diff --git a/usr.sbin/bgpctl/parser.c b/usr.sbin/bgpctl/parser.c
index e4aa6e395c0..e8b587e33e6 100644
--- a/usr.sbin/bgpctl/parser.c
+++ b/usr.sbin/bgpctl/parser.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: parser.c,v 1.8 2004/08/20 15:49:35 henning Exp $ */
+/* $OpenBSD: parser.c,v 1.9 2004/10/26 13:12:22 henning Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -173,40 +173,29 @@ int parse_asnum(const char *, u_int16_t *);
struct parse_result *
parse(int argc, char *argv[])
{
- int curarg = 1;
const struct token *table = t_main;
const struct token *match;
- char *word;
bzero(&res, sizeof(res));
- if (argc == 1)
- return (&res);
- for (;;) {
- if (argc > curarg)
- word = argv[curarg];
- else
- word = NULL;
-
- if ((match = match_token(word, table)) == NULL) {
+ while (argc > 0) {
+ if ((match = match_token(argv[0], table)) == NULL) {
fprintf(stderr, "valid commands/args:\n");
show_valid_args(table);
return (NULL);
}
- curarg++;
-
- if (match->type == NOTOKEN)
- break;
+ argc--;
+ argv++;
- if (match->next == NULL)
+ if (match->type == NOTOKEN || match->next == NULL)
break;
table = match->next;
}
- if (curarg < argc) {
- fprintf(stderr, "superfluous argument: %s\n", argv[curarg]);
+ if (argc > 0) {
+ fprintf(stderr, "superfluous argument: %s\n", argv[0]);
return (NULL);
}