diff options
author | Henning Brauer <henning@cvs.openbsd.org> | 2004-10-26 13:12:23 +0000 |
---|---|---|
committer | Henning Brauer <henning@cvs.openbsd.org> | 2004-10-26 13:12:23 +0000 |
commit | 840bb8c6a85292eea7022f2f7b74779e23ac0f0e (patch) | |
tree | db7645f652f4b422587fa43dfd00d14d1a313e3a /usr.sbin/bgpctl | |
parent | b3942c66ac6fdb7b9b4b3358c56d4c33107dd173 (diff) |
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')
-rw-r--r-- | usr.sbin/bgpctl/bgpctl.c | 6 | ||||
-rw-r--r-- | usr.sbin/bgpctl/parser.c | 27 |
2 files changed, 11 insertions, 22 deletions
diff --git a/usr.sbin/bgpctl/bgpctl.c b/usr.sbin/bgpctl/bgpctl.c index f365f6c09ad..45bb0813426 100644 --- a/usr.sbin/bgpctl/bgpctl.c +++ b/usr.sbin/bgpctl/bgpctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bgpctl.c,v 1.67 2004/10/26 11:46:08 henning Exp $ */ +/* $OpenBSD: bgpctl.c,v 1.68 2004/10/26 13:12:22 henning Exp $ */ /* * Copyright (c) 2003 Henning Brauer <henning@openbsd.org> @@ -99,8 +99,8 @@ main(int argc, char *argv[]) /* NOTREACHED */ } } - argc -= (optind - 1); - argv += (optind - 1); + argc -= optind; + argv += optind; if ((res = parse(argc, argv)) == NULL) exit(1); 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); } |