Richard Alpe | f043759 | 2015-05-07 15:07:36 +0200 | [diff] [blame] | 1 | /* |
| 2 | * cmdl.h Framework for handling command line options. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; either version |
| 7 | * 2 of the License, or (at your option) any later version. |
| 8 | * |
| 9 | * Authors: Richard Alpe <richard.alpe@ericsson.com> |
| 10 | */ |
| 11 | |
| 12 | #ifndef _TIPC_CMDL_H |
| 13 | #define _TIPC_CMDL_H |
| 14 | |
| 15 | #include <libmnl/libmnl.h> |
| 16 | |
| 17 | extern int help_flag; |
| 18 | |
Richard Alpe | ed81dea | 2016-08-30 10:37:00 +0200 | [diff] [blame] | 19 | enum { |
| 20 | OPT_KEY = (1 << 0), |
| 21 | OPT_KEYVAL = (1 << 1), |
| 22 | }; |
| 23 | |
Richard Alpe | f043759 | 2015-05-07 15:07:36 +0200 | [diff] [blame] | 24 | struct cmdl { |
| 25 | int optind; |
| 26 | int argc; |
| 27 | char **argv; |
| 28 | }; |
| 29 | |
Richard Alpe | 50afc4d | 2016-08-15 10:24:32 +0200 | [diff] [blame] | 30 | struct tipc_sup_media { |
| 31 | char *media; |
| 32 | char *identifier; |
| 33 | void (*help)(struct cmdl *cmdl, char *media); |
| 34 | }; |
| 35 | |
Richard Alpe | f043759 | 2015-05-07 15:07:36 +0200 | [diff] [blame] | 36 | struct cmd { |
| 37 | const char *cmd; |
| 38 | int (*func)(struct nlmsghdr *nlh, const struct cmd *cmd, |
| 39 | struct cmdl *cmdl, void *data); |
| 40 | void (*help)(struct cmdl *cmdl); |
| 41 | }; |
| 42 | |
| 43 | struct opt { |
| 44 | const char *key; |
Richard Alpe | ed81dea | 2016-08-30 10:37:00 +0200 | [diff] [blame] | 45 | uint16_t flag; |
Richard Alpe | f043759 | 2015-05-07 15:07:36 +0200 | [diff] [blame] | 46 | char *val; |
| 47 | }; |
| 48 | |
| 49 | struct opt *get_opt(struct opt *opts, char *key); |
Richard Alpe | ed81dea | 2016-08-30 10:37:00 +0200 | [diff] [blame] | 50 | bool has_opt(struct opt *opts, char *key); |
Richard Alpe | f043759 | 2015-05-07 15:07:36 +0200 | [diff] [blame] | 51 | int parse_opts(struct opt *opts, struct cmdl *cmdl); |
| 52 | char *shift_cmdl(struct cmdl *cmdl); |
| 53 | |
| 54 | int run_cmd(struct nlmsghdr *nlh, const struct cmd *caller, |
| 55 | const struct cmd *cmds, struct cmdl *cmdl, void *data); |
| 56 | |
| 57 | const struct cmd *find_cmd(const struct cmd *cmds, char *str); |
| 58 | |
| 59 | #endif |