From 127f80691f96b573db633c7dfe9fc36006dd6979 Mon Sep 17 00:00:00 2001 From: Ben Hutchings Date: Sat, 29 Oct 2011 01:15:34 +0100 Subject: Move argument parsing to sub-command functions Instead of doing most of the argument parsing in parse_cmdline(), find the sub-command and (if required) the device name in main() and do the rest in the sub-command handler function. Pass argc and argp around in struct cmd_context. This also tightens up argument parsing slightly: extraneous or missing arguments will now result in an error in a few cases where they were previously ignored. All test cases now pass. Replace sub-command dispatch in doit() with a function pointer in struct option. Signed-off-by: Ben Hutchings --- rxclass.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'rxclass.c') diff --git a/rxclass.c b/rxclass.c index dec9dd5..0c7b916 100644 --- a/rxclass.c +++ b/rxclass.c @@ -950,7 +950,7 @@ static int rxclass_get_mask(char *str, unsigned char *p, return 0; } -int rxclass_parse_ruleopts(char **argp, int argc, +int rxclass_parse_ruleopts(struct cmd_context *ctx, struct ethtool_rx_flow_spec *fsp) { const struct rule_opts *options; @@ -958,6 +958,8 @@ int rxclass_parse_ruleopts(char **argp, int argc, int i = 0, n_opts, err; u32 flags = 0; int flow_type; + int argc = ctx->argc; + char **argp = ctx->argp; if (argc < 1) goto syntax_err; -- cgit v1.2.1