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 --- internal.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'internal.h') diff --git a/internal.h b/internal.h index ba7d719..eb13db8 100644 --- a/internal.h +++ b/internal.h @@ -92,6 +92,8 @@ static inline int test_bit(unsigned int nr, const unsigned long *addr) struct cmd_context { int fd; /* socket suitable for ethtool ioctl */ struct ifreq ifr; /* ifreq suitable for ethtool ioctl */ + int argc; /* number of arguments to the sub-command */ + char **argp; /* arguments to the sub-command */ }; #ifdef TEST_ETHTOOL @@ -165,7 +167,7 @@ int st_mac100_dump_regs(struct ethtool_drvinfo *info, int st_gmac_dump_regs(struct ethtool_drvinfo *info, struct ethtool_regs *regs); /* Rx flow classification */ -int rxclass_parse_ruleopts(char **optstr, int opt_cnt, +int rxclass_parse_ruleopts(struct cmd_context *ctx, struct ethtool_rx_flow_spec *fsp); int rxclass_rule_getall(struct cmd_context *ctx); int rxclass_rule_get(struct cmd_context *ctx, __u32 loc); -- cgit v1.2.1