From ba1e16863bdedc5f52b077932aa7301ed14a0f06 Mon Sep 17 00:00:00 2001 From: darkcoven Date: Fri, 20 Sep 2013 19:51:17 +0200 Subject: [PATCH] Let commands handle themselves absence of arguments --- cli/admin.c | 44 ++++++----- cli/com_bitrate.c | 36 +++++---- cli/com_cabletest.c | 11 ++- cli/com_defaults.c | 8 +- cli/com_firmware.c | 16 ++-- cli/com_help.c | 10 ++- cli/com_igmp.c | 24 +++--- cli/com_list.c | 8 +- cli/com_login.c | 8 +- cli/com_mirror.c | 30 +++++--- cli/com_name.c | 22 ++++-- cli/com_netconf.c | 26 +++---- cli/com_password.c | 18 ++--- cli/com_ports.c | 24 +++++- cli/com_qos.c | 42 +++++++---- cli/com_quit.c | 9 ++- cli/com_restart.c | 8 +- cli/com_scan.c | 11 ++- cli/com_stormfilter.c | 48 ++++++++---- cli/com_tree.c | 9 ++- cli/com_vlan.c | 79 +++++++++++--------- cli/commands.c | 170 +++++++++++++++++++++--------------------- cli/commands.h | 13 ++-- cli/common.h | 2 +- 24 files changed, 403 insertions(+), 273 deletions(-) diff --git a/cli/admin.c b/cli/admin.c index e3fbec6..14ad11c 100644 --- a/cli/admin.c +++ b/cli/admin.c @@ -14,7 +14,7 @@ #define MAXCOM 32 -int cont = 1; +int main_loop_continue = 1; static const struct TreeNode* getSubCom (char **com, int n, int *t) @@ -23,7 +23,7 @@ static const struct TreeNode* getSubCom (char **com, int n, int *t) const struct TreeNode *cur, *next; - cur = &coms; + cur = &commands; for (i = 0; i < n; i++) { /* we have reached a terminal command, exit */ if (cur->sub == NULL) @@ -180,7 +180,7 @@ int main (int argc, char **argv) break; case 'h': - printf("Usage: %s [-b] [-f] [-g] [-i ]\n", argv[0]); + printf("usage: %s [-b] [-f] [-g] [-i ]\n", argv[0]); goto end; case 't': @@ -235,7 +235,7 @@ int main (int argc, char **argv) sigsetjmp(jmpbuf, 1); - while (cont) { + while (main_loop_continue) { line = readline("> "); if (line == NULL) goto end; @@ -252,29 +252,27 @@ int main (int argc, char **argv) cur = getSubCom(com, n, &i); - if (i < n) { /* commands left unchecked */ - if (i == 0) { /* root command */ - printf("unknown command\n"); - } else if (cur->sub != NULL) { /* intermediate command */ - printf("unknown %s subcommand\n", com[i - 1]); - } else if (!cur->hasArgs) { /* terminal command without arguments */ - printf("%s as no subcommand and takes no parameter\n", com[i - 1]); - } else if (cur->comfunc == NULL) { /* erroneous terminal command without function */ - printf("terminal command without function\n"); - } else { /* terminal command with arguments, left "commands" are in fact parameters */ - cur->comfunc(n - i, (const char**)&com[i], nga); - } - } else { /* no command left */ - if (cur->sub != NULL) { /* intermediate command */ + if (cur->sub != NULL) { + /* not terminal command */ + if (i == 0) { + /* root command */ + printf("unknown command: %s\n", com[i]); + } else if (i < n) { + /* intermediate command, remaining string */ + printf("unknown %s subcommand: %s\n", com[i - 1], com[i]); + } else { + /* intermediate command, no remaining string */ /* print available subcommands */ for (next = cur->sub; next->name != NULL; next++) printf("%s ", next->name); - printf("\n"); - } else if (cur->comfunc == NULL) { /* erroneous terminal command without function */ - printf("terminal command without function\n"); - } else { /* terminal command without arguments */ - cur->comfunc(0, NULL, nga); + putchar('\n'); } + } else if (cur->comfunc == NULL) { + /* erroneous terminal command without function */ + printf("terminal command without function\n"); + } else { + /* execute terminal command */ + cur->comfunc(n - i, (const char**)&com[i], nga); } for (i = 0; com[i] != NULL; i++) { diff --git a/cli/com_bitrate.c b/cli/com_bitrate.c index 2f7a5a9..6041582 100644 --- a/cli/com_bitrate.c +++ b/cli/com_bitrate.c @@ -3,19 +3,19 @@ /* helper function to analyse bitrate speed specifications */ -static int bitrate_analyse (int nb, const char **com, int *ports) +static int bitrate_analyse (int argc, const char **argv, int *ports) { int i = 0, s; - while (i < nb - 1) { - s = parseBitrate(com[i + 1]); - if (strcmp(com[i], "inout") == 0) { + while (i < argc - 1) { + s = parseBitrate(argv[i + 1]); + if (strcmp(argv[i], "inout") == 0) { ports[0] = s; ports[1] = s; - } else if (strcmp(com[i], "in") == 0) { + } else if (strcmp(argv[i], "in") == 0) { ports[0] = s; - } else if (strcmp(com[i], "out") == 0) { + } else if (strcmp(argv[i], "out") == 0) { ports[1] = s; } else { break; @@ -28,15 +28,15 @@ static int bitrate_analyse (int nb, const char **com, int *ports) } -bool do_bitrate_set (int nb, const char **com, struct ngadmin *nga) +bool do_bitrate_set (int argc, const char **argv, struct ngadmin *nga) { int i, k = 0, defs[] = {12, 12}, p, *ports = NULL; const struct swi_attr *sa; bool ret = true; - if (nb < 2) { + if (argc < 2) { printf( - "Usage: bitrate set [all SPEEDSPEC] SPEEDSPEC [ SPEEDSPEC ...]\n" + "usage: bitrate set [all SPEEDSPEC] SPEEDSPEC [ SPEEDSPEC ...]\n" "SPEEDSPEC: [inout ] [in ] [out ]\n" ); ret = false; @@ -53,9 +53,9 @@ bool do_bitrate_set (int nb, const char **com, struct ngadmin *nga) ports = malloc(2 * sa->ports * sizeof(int)); /* get defaults if present */ - if (strcmp(com[k], "all") == 0) { + if (strcmp(argv[k], "all") == 0) { k++; - k += bitrate_analyse(nb-k, &com[k], defs); + k += bitrate_analyse(argc - k, &argv[k], defs); } /* apply defaults */ @@ -63,10 +63,10 @@ bool do_bitrate_set (int nb, const char **com, struct ngadmin *nga) memcpy(&ports[2 * i], defs, sizeof(defs)); /* get ports specifics */ - while (k < nb) { - p = strtol(com[k++], NULL, 0) - 1; + while (k < argc) { + p = strtol(argv[k++], NULL, 0) - 1; if (p >= 0 && p ports) - k += bitrate_analyse(nb - k, &com[k], &ports[2 * p]); + k += bitrate_analyse(argc - k, &argv[k], &ports[2 * p]); } /* send it to the switch */ @@ -80,12 +80,18 @@ end: } -bool do_bitrate_show (int nb UNUSED, const char **com UNUSED, struct ngadmin *nga) +bool do_bitrate_show (int argc, const char **argv UNUSED, struct ngadmin *nga) { int i, ret = true, *ports = NULL; const struct swi_attr *sa; + if (argc > 0) { + printf("this command takes no argument\n"); + ret = false; + goto end; + } + sa = ngadmin_getCurrentSwitch(nga); if (sa == NULL) { printf("must be logged\n"); diff --git a/cli/com_cabletest.c b/cli/com_cabletest.c index f23763f..370d1cd 100644 --- a/cli/com_cabletest.c +++ b/cli/com_cabletest.c @@ -2,7 +2,7 @@ #include "commands.h" -bool do_cabletest (int nb, const char **com, struct ngadmin *nga) +bool do_cabletest (int argc, const char **argv, struct ngadmin *nga) { bool ret = true; const struct swi_attr *sa; @@ -10,12 +10,11 @@ bool do_cabletest (int nb, const char **com, struct ngadmin *nga) int i, j=0, k=0; - if (nb < 1) { - printf("Usage: cabletest [ ...]\n"); + if (argc < 1) { + printf("usage: cabletest [ ...]\n"); goto end; } - sa = ngadmin_getCurrentSwitch(nga); if (sa == NULL) { printf("must be logged\n"); @@ -26,8 +25,8 @@ bool do_cabletest (int nb, const char **com, struct ngadmin *nga) ct = malloc(sa->ports * sizeof(struct cabletest)); memset(ct, 0, sa->ports * sizeof(struct cabletest)); - while (k < nb) { - ct[j].port = strtol(com[k++], NULL, 0); + while (k < argc) { + ct[j].port = strtol(argv[k++], NULL, 0); if (ct[j].port >= 1 && ct[j].port <= sa->ports) j++; } diff --git a/cli/com_defaults.c b/cli/com_defaults.c index a1c7107..3574e4b 100644 --- a/cli/com_defaults.c +++ b/cli/com_defaults.c @@ -2,13 +2,19 @@ #include "commands.h" -bool do_defaults (int nb UNUSED, const char **com UNUSED, struct ngadmin *nga) +bool do_defaults (int argc, const char **argv UNUSED, struct ngadmin *nga) { int i, ret = true; const struct swi_attr *sa; char line[16]; + if (argc > 0) { + printf("this command takes no argument\n"); + ret = false; + goto end; + } + sa = ngadmin_getCurrentSwitch(nga); if (sa == NULL) { printf("must be logged\n"); diff --git a/cli/com_firmware.c b/cli/com_firmware.c index cc931fe..d3e9d0d 100644 --- a/cli/com_firmware.c +++ b/cli/com_firmware.c @@ -2,12 +2,18 @@ #include "commands.h" -bool do_firmware_show (int nb UNUSED, const char **com UNUSED, struct ngadmin *nga) +bool do_firmware_show (int argc, const char **argv UNUSED, struct ngadmin *nga) { const struct swi_attr *sa; bool ret = true; + if (argc > 0) { + printf("this command takes no argument\n"); + ret = false; + goto end; + } + sa = ngadmin_getCurrentSwitch(nga); if (sa == NULL) { printf("must be logged\n"); @@ -23,15 +29,15 @@ end: } -bool do_firmware_upgrade (int nb, const char **com, struct ngadmin *nga) +bool do_firmware_upgrade (int argc, const char **argv, struct ngadmin *nga) { const struct swi_attr *sa; bool ret = true; int i; - if (nb != 1) { - printf("Usage: firmware upgrade \n"); + if (argc != 1) { + printf("usage: firmware upgrade \n"); ret = false; goto end; } @@ -43,7 +49,7 @@ bool do_firmware_upgrade (int nb, const char **com, struct ngadmin *nga) goto end; } - i = ngadmin_upgradeFirmware(nga, com[0]); + i = ngadmin_upgradeFirmware(nga, argv[0]); printErrCode(i); end: diff --git a/cli/com_help.c b/cli/com_help.c index e1bad0e..a857cc1 100644 --- a/cli/com_help.c +++ b/cli/com_help.c @@ -2,13 +2,19 @@ #include "commands.h" -bool do_help (int nb UNUSED, const char **com UNUSED, struct ngadmin *nga UNUSED) +bool do_help (int argc, const char **argv UNUSED, struct ngadmin *nga UNUSED) { const struct TreeNode *s; + + if (argc > 0) { + printf("this command takes no argument\n"); + return false; + } + printf("Available commands: \n"); - for (s = coms.sub; s->name != NULL; s++) + for (s = commands.sub; s->name != NULL; s++) printf("%s ", s->name); putchar('\n'); diff --git a/cli/com_igmp.c b/cli/com_igmp.c index 3d57a03..22647ff 100644 --- a/cli/com_igmp.c +++ b/cli/com_igmp.c @@ -2,14 +2,14 @@ #include "commands.h" -bool do_igmp_set (int nb, const char **com, struct ngadmin *nga) +bool do_igmp_set (int argc, const char **argv, struct ngadmin *nga) { int i; struct igmp_conf ic; - if (nb != 4) { - printf("Usage: igmp set \n"); + if (argc != 4) { + printf("usage: igmp set \n"); return false; } @@ -18,10 +18,10 @@ bool do_igmp_set (int nb, const char **com, struct ngadmin *nga) return false; } - ic.enable = strtol(com[0], NULL, 0); - ic.vlan = strtol(com[1], NULL, 0); - ic.validate = strtol(com[2], NULL, 0); - ic.block = strtol(com[3], NULL, 0); + ic.enable = strtol(argv[0], NULL, 0); + ic.vlan = strtol(argv[1], NULL, 0); + ic.validate = strtol(argv[2], NULL, 0); + ic.block = strtol(argv[3], NULL, 0); i = ngadmin_setIGMPConf(nga, &ic); printErrCode(i); @@ -31,7 +31,7 @@ bool do_igmp_set (int nb, const char **com, struct ngadmin *nga) } -bool do_igmp_show (int nb UNUSED, const char **com UNUSED, struct ngadmin *nga) +bool do_igmp_show (int argc, const char **argv UNUSED, struct ngadmin *nga) { int i; const struct swi_attr *sa; @@ -39,7 +39,13 @@ bool do_igmp_show (int nb UNUSED, const char **com UNUSED, struct ngadmin *nga) bool ret = true; - sa=ngadmin_getCurrentSwitch(nga); + if (argc > 0) { + printf("this command takes no argument\n"); + ret = false; + goto end; + } + + sa = ngadmin_getCurrentSwitch(nga); if (sa == NULL) { printf("must be logged\n"); ret = false; diff --git a/cli/com_list.c b/cli/com_list.c index 820d698..064690c 100644 --- a/cli/com_list.c +++ b/cli/com_list.c @@ -2,11 +2,17 @@ #include "commands.h" -bool do_list (int nb UNUSED, const char **com UNUSED, struct ngadmin *nga) +bool do_list (int argc, const char **argv UNUSED, struct ngadmin *nga) { int n; const struct swi_attr *sa; + + if (argc > 0) { + printf("this command takes no argument\n"); + return false; + } + sa = ngadmin_getSwitchTab(nga, &n); displaySwitchTab(sa, n); diff --git a/cli/com_login.c b/cli/com_login.c index 61b4f07..ed4154e 100644 --- a/cli/com_login.c +++ b/cli/com_login.c @@ -2,17 +2,17 @@ #include "commands.h" -bool do_login (int nb, const char **com, struct ngadmin *nga) +bool do_login (int argc, const char **argv, struct ngadmin *nga) { int i; - if (nb != 1) { - printf("Usage: login \n"); + if (argc != 1) { + printf("usage: login \n"); return false; } - i = strtol(com[0], NULL, 0); + i = strtol(argv[0], NULL, 0); i = ngadmin_login(nga, i); printErrCode(i); diff --git a/cli/com_mirror.c b/cli/com_mirror.c index 75ca75c..507ee1f 100644 --- a/cli/com_mirror.c +++ b/cli/com_mirror.c @@ -2,17 +2,21 @@ #include "commands.h" -bool do_mirror_disable (int nb UNUSED, const char **com UNUSED, struct ngadmin *nga) +bool do_mirror_disable (int argc, const char **argv UNUSED, struct ngadmin *nga) { int i; + if (argc > 0) { + printf("this command takes no argument\n"); + return false; + } + if (ngadmin_getCurrentSwitch(nga) == NULL) { printf("must be logged\n"); return false; } - i = ngadmin_setMirror(nga, NULL); printErrCode(i); @@ -21,7 +25,7 @@ bool do_mirror_disable (int nb UNUSED, const char **com UNUSED, struct ngadmin * } -bool do_mirror_set (int nb, const char **com, struct ngadmin *nga) +bool do_mirror_set (int argc, const char **argv, struct ngadmin *nga) { const struct swi_attr *sa; char *ports = NULL; @@ -29,8 +33,8 @@ bool do_mirror_set (int nb, const char **com, struct ngadmin *nga) int i, k = 0; - if (nb < 3) { - printf("Usage: mirror set clone [ ...]\n"); + if (argc < 3) { + printf("usage: mirror set clone [ ...]\n"); goto end; } @@ -44,15 +48,15 @@ bool do_mirror_set (int nb, const char **com, struct ngadmin *nga) ports = malloc((sa->ports + 1) * sizeof(char)); memset(ports, 0, sa->ports + 1); - ports[0] = strtol(com[k++], NULL, 0); - if (ports[0] < 1 || ports[0] > sa->ports || strcasecmp(com[k++], "clone") != 0) { + ports[0] = strtol(argv[k++], NULL, 0); + if (ports[0] < 1 || ports[0] > sa->ports || strcasecmp(argv[k++], "clone") != 0) { printf("syntax error\n"); ret = false; goto end; } - while (k < nb) { - i = strtol(com[k++], NULL, 0); + while (k < argc) { + i = strtol(argv[k++], NULL, 0); if (i < 1 || i > sa->ports) { printf("port out of range\n"); ret = false; @@ -75,20 +79,24 @@ end: } -bool do_mirror_show (int nb UNUSED, const char **com UNUSED, struct ngadmin *nga) +bool do_mirror_show (int argc, const char **argv UNUSED, struct ngadmin *nga) { const struct swi_attr *sa; char *ports = NULL; int i; + if (argc > 0) { + printf("this command takes no argument\n"); + return false; + } + sa = ngadmin_getCurrentSwitch(nga); if (sa == NULL) { printf("must be logged\n"); return false; } - ports = malloc((sa->ports + 1) * sizeof(char)); i = ngadmin_getMirror(nga, ports); if (i != ERR_OK) { diff --git a/cli/com_name.c b/cli/com_name.c index 0e2524a..8e47878 100644 --- a/cli/com_name.c +++ b/cli/com_name.c @@ -2,11 +2,16 @@ #include "commands.h" -bool do_name_show (int nb UNUSED, const char **com UNUSED, struct ngadmin *nga) +bool do_name_show (int argc, const char **argv UNUSED, struct ngadmin *nga) { const struct swi_attr *sa; + if (argc > 0) { + printf("this command takes no argument\n"); + return false; + } + sa = ngadmin_getCurrentSwitch(nga); if (sa == NULL) { printf("must be logged\n"); @@ -20,14 +25,14 @@ bool do_name_show (int nb UNUSED, const char **com UNUSED, struct ngadmin *nga) } -bool do_name_set (int nb, const char **com, struct ngadmin *nga) +bool do_name_set (int argc, const char **argv, struct ngadmin *nga) { int i; const struct swi_attr *sa; - if (nb != 1) { - printf("Usage: name set \n"); + if (argc != 1) { + printf("usage: name set \n"); return false; } @@ -37,7 +42,7 @@ bool do_name_set (int nb, const char **com, struct ngadmin *nga) return false; } - i = ngadmin_setName(nga, com[0]); + i = ngadmin_setName(nga, argv[0]); printErrCode(i); @@ -45,12 +50,17 @@ bool do_name_set (int nb, const char **com, struct ngadmin *nga) } -bool do_name_clear (int nb UNUSED, const char **com UNUSED, struct ngadmin *nga) +bool do_name_clear (int argc, const char **argv UNUSED, struct ngadmin *nga) { int i; const struct swi_attr *sa; + if (argc > 0) { + printf("this command takes no argument\n"); + return false; + } + sa = ngadmin_getCurrentSwitch(nga); if (sa == NULL) { printf("must be logged\n"); diff --git a/cli/com_netconf.c b/cli/com_netconf.c index 5c165ae..99cd6ba 100644 --- a/cli/com_netconf.c +++ b/cli/com_netconf.c @@ -2,7 +2,7 @@ #include "commands.h" -bool do_netconf_set (int nb, const char **com, struct ngadmin *nga) +bool do_netconf_set (int argc, const char **argv, struct ngadmin *nga) { int i, k; const struct swi_attr *sa; @@ -10,8 +10,8 @@ bool do_netconf_set (int nb, const char **com, struct ngadmin *nga) bool ret = true; - if (nb == 0) { - printf("Usage: netconf set [dhcp yes|no] [ip ] [mask ] [gw ]\n"); + if (argc == 0) { + printf("usage: netconf set [dhcp yes|no] [ip ] [mask ] [gw ]\n"); return false; } @@ -23,32 +23,32 @@ bool do_netconf_set (int nb, const char **com, struct ngadmin *nga) memset(&nc, 0, sizeof(struct net_conf)); - for (k = 0; k < nb; k += 2) { - if (strcasecmp(com[k], "dhcp") == 0) { - if (strcasecmp(com[k+1], "yes") == 0) { + for (k = 0; k < argc; k += 2) { + if (strcasecmp(argv[k], "dhcp") == 0) { + if (strcasecmp(argv[k + 1], "yes") == 0) { nc.dhcp = true; - } else if (strcasecmp(com[k+1], "no") == 0) { + } else if (strcasecmp(argv[k + 1], "no") == 0) { nc.dhcp = false; } else { printf("Incorrect DHCP value\n"); ret = false; goto end; } - } else if (strcasecmp(com[k], "ip") == 0) { - if (inet_aton(com[k+1], &nc.ip) == 0) { + } else if (strcasecmp(argv[k], "ip") == 0) { + if (inet_aton(argv[k + 1], &nc.ip) == 0) { printf("Incorrect IP value\n"); ret = false; goto end; } - } else if (strcasecmp(com[k], "mask") == 0) { + } else if (strcasecmp(argv[k], "mask") == 0) { /* TODO: check if it is a correct mask */ - if (inet_aton(com[k+1], &nc.netmask) == 0) { + if (inet_aton(argv[k + 1], &nc.netmask) == 0) { printf("Incorrect mask value\n"); ret = false; goto end; } - } else if (strcasecmp(com[k], "gw") == 0) { - if (inet_aton(com[k+1], &nc.gw) == 0) { + } else if (strcasecmp(argv[k], "gw") == 0) { + if (inet_aton(argv[k + 1], &nc.gw) == 0) { printf("Incorrect gateway value\n"); ret = false; goto end; diff --git a/cli/com_password.c b/cli/com_password.c index 9264bb9..f67ccc0 100644 --- a/cli/com_password.c +++ b/cli/com_password.c @@ -2,14 +2,14 @@ #include "commands.h" -bool do_password_change (int nb, const char **com, struct ngadmin *nga) +bool do_password_change (int argc, const char **argv, struct ngadmin *nga) { int i; const struct swi_attr *sa; - if (nb != 1) { - printf("Usage: password change \n"); + if (argc != 1) { + printf("usage: password change \n"); return false; } @@ -19,7 +19,7 @@ bool do_password_change (int nb, const char **com, struct ngadmin *nga) return false; } - i = ngadmin_changePassword(nga, com[0]); + i = ngadmin_changePassword(nga, argv[0]); printErrCode(i); @@ -27,19 +27,19 @@ bool do_password_change (int nb, const char **com, struct ngadmin *nga) } -bool do_password_set (int nb, const char **com, struct ngadmin *nga) +bool do_password_set (int argc, const char **argv, struct ngadmin *nga) { int i; char buf[64]; const char *pass; - if (nb > 1) { - printf("Usage: password set []\n"); + if (argc > 1) { + printf("usage: password set []\n"); return false; } - if (nb == 0) { + if (argc == 0) { printf("Enter password: "); fflush(stdout); current_term.c_lflag &= ~ECHO; @@ -50,7 +50,7 @@ bool do_password_set (int nb, const char **com, struct ngadmin *nga) tcsetattr(STDIN_FILENO, TCSANOW, ¤t_term); putchar('\n'); } else { - pass = com[0]; + pass = argv[0]; } if (pass != NULL) { diff --git a/cli/com_ports.c b/cli/com_ports.c index 7c3fbb2..866a84b 100644 --- a/cli/com_ports.c +++ b/cli/com_ports.c @@ -2,7 +2,7 @@ #include "commands.h" -bool do_ports_state (int nb UNUSED, const char **com UNUSED, struct ngadmin *nga) +bool do_ports_state (int argc, const char **argv UNUSED, struct ngadmin *nga) { int i; const struct swi_attr *sa; @@ -10,6 +10,12 @@ bool do_ports_state (int nb UNUSED, const char **com UNUSED, struct ngadmin *nga bool ret = true; + if (argc > 0) { + printf("this command takes no argument\n"); + ret = false; + goto end; + } + sa = ngadmin_getCurrentSwitch(nga); if (sa == NULL) { printf("must be logged\n"); @@ -59,10 +65,16 @@ end: } -bool do_ports_statistics_reset (int nb UNUSED, const char **com UNUSED, struct ngadmin *nga) +bool do_ports_statistics_reset (int argc, const char **argv UNUSED, struct ngadmin *nga) { int i; + + if (argc > 0) { + printf("this command takes no argument\n"); + return false; + } + if (ngadmin_getCurrentSwitch(nga) == NULL) { printf("must be logged\n"); return false; @@ -75,7 +87,7 @@ bool do_ports_statistics_reset (int nb UNUSED, const char **com UNUSED, struct n } -bool do_ports_statistics_show (int nb UNUSED, const char **com UNUSED, struct ngadmin *nga) +bool do_ports_statistics_show (int argc, const char **argv UNUSED, struct ngadmin *nga) { int i; const struct swi_attr *sa; @@ -83,6 +95,12 @@ bool do_ports_statistics_show (int nb UNUSED, const char **com UNUSED, struct ng struct port_stats *ps = NULL; + if (argc > 0) { + printf("this command takes no argument\n"); + ret = false; + goto end; + } + sa = ngadmin_getCurrentSwitch(nga); if (sa == NULL) { printf("must be logged\n"); diff --git a/cli/com_qos.c b/cli/com_qos.c index 4adf9b6..ac2ea81 100644 --- a/cli/com_qos.c +++ b/cli/com_qos.c @@ -2,14 +2,14 @@ #include "commands.h" -bool do_qos_mode (int nb, const char **com, struct ngadmin *nga) +bool do_qos_mode (int argc, const char **argv, struct ngadmin *nga) { int i, s, ret = true; const struct swi_attr *sa; - if (nb == 0) { - printf("Usage: qos mode port|802.1p\n"); + if (argc == 0) { + printf("usage: qos mode port|802.1p\n"); goto end; } @@ -20,9 +20,9 @@ bool do_qos_mode (int nb, const char **com, struct ngadmin *nga) goto end; } - if (strcasecmp(com[0], "port") == 0) { + if (strcasecmp(argv[0], "port") == 0) { s = QOS_PORT; - } else if (strcasecmp(com[0], "802.1p") == 0) { + } else if (strcasecmp(argv[0], "802.1p") == 0) { s = QOS_DOT; } else { printf("Unknown QOS mode\n"); @@ -39,7 +39,7 @@ end: } -bool do_qos_set (int nb, const char **com, struct ngadmin *nga) +bool do_qos_set (int argc, const char **argv, struct ngadmin *nga) { int i, p; const struct swi_attr *sa; @@ -47,8 +47,8 @@ bool do_qos_set (int nb, const char **com, struct ngadmin *nga) char d = PRIO_UNSPEC, *ports = NULL; - if (nb < 2) { - printf("Usage: qos set (all )|( [ ...])\n"); + if (argc < 2) { + printf("usage: qos set (all )|( [ ...])\n"); ret = false; goto end; } @@ -62,22 +62,26 @@ bool do_qos_set (int nb, const char **com, struct ngadmin *nga) ports = malloc(sa->ports * sizeof(char)); - if (strcmp(com[0], "all") == 0) { - d = parsePrio(com[1]); - com += 2; - nb -= 2; + /* read defaults */ + if (strcmp(argv[0], "all") == 0) { + d = parsePrio(argv[1]); + argv += 2; + argc -= 2; } + /* apply defaults */ for (i = 0; i < sa->ports; i++) ports[i] = d; - for (i = 0; i < nb; i += 2) { - p = strtol(com[i], NULL, 0); + /* read and apply port specifics */ + for (i = 0; i < argc; i += 2) { + p = strtol(argv[i], NULL, 0); if (p < 1 || p > sa->ports) continue; - ports[p - 1] = parsePrio(com[i + 1]); + ports[p - 1] = parsePrio(argv[i + 1]); } + /* send the new configuration to the switch */ i = ngadmin_setQOSValues(nga, ports); printErrCode(i); @@ -88,13 +92,19 @@ end: } -bool do_qos_show (int nb UNUSED, const char **com UNUSED, struct ngadmin *nga) +bool do_qos_show (int argc, const char **argv UNUSED, struct ngadmin *nga) { int i, s = 0, ret = true; const struct swi_attr *sa; char *ports = NULL; + if (argc > 0) { + printf("this command takes no argument\n"); + ret = false; + goto end; + } + sa = ngadmin_getCurrentSwitch(nga); if (sa == NULL) { printf("must be logged\n"); diff --git a/cli/com_quit.c b/cli/com_quit.c index 96cb069..8a78fe1 100644 --- a/cli/com_quit.c +++ b/cli/com_quit.c @@ -2,9 +2,14 @@ #include "commands.h" -bool do_quit (int nb UNUSED, const char **com UNUSED, struct ngadmin *nga UNUSED) +bool do_quit (int argc, const char **argv UNUSED, struct ngadmin *nga UNUSED) { - cont = 0; + if (argc > 0) { + printf("this command takes no argument\n"); + return false; + } + + main_loop_continue = 0; return true; } diff --git a/cli/com_restart.c b/cli/com_restart.c index 9c001d1..590ac6b 100644 --- a/cli/com_restart.c +++ b/cli/com_restart.c @@ -2,13 +2,19 @@ #include "commands.h" -bool do_restart (int nb UNUSED, const char **com UNUSED, struct ngadmin *nga UNUSED) +bool do_restart (int argc, const char **argv UNUSED, struct ngadmin *nga UNUSED) { int i, ret = true; const struct swi_attr *sa; char line[16]; + if (argc > 0) { + printf("this command takes no argument\n"); + ret = false; + goto end; + } + sa = ngadmin_getCurrentSwitch(nga); if (sa == NULL) { printf("must be logged\n"); diff --git a/cli/com_scan.c b/cli/com_scan.c index 9d9bb13..7b96e5e 100644 --- a/cli/com_scan.c +++ b/cli/com_scan.c @@ -2,20 +2,25 @@ #include "commands.h" -bool do_scan (int nb UNUSED, const char **com UNUSED, struct ngadmin *nga) +bool do_scan (int argc, const char **argv UNUSED, struct ngadmin *nga) { int i; const struct swi_attr *sa; + if (argc > 0) { + printf("this command takes no argument\n"); + return false; + } + i = ngadmin_scan(nga); if (i < 0) { printErrCode(i); return false; } - sa = ngadmin_getSwitchTab(nga, &nb); - displaySwitchTab(sa, nb); + sa = ngadmin_getSwitchTab(nga, &i); + displaySwitchTab(sa, i); return true; diff --git a/cli/com_stormfilter.c b/cli/com_stormfilter.c index 76076bf..6f2f516 100644 --- a/cli/com_stormfilter.c +++ b/cli/com_stormfilter.c @@ -2,12 +2,17 @@ #include "commands.h" -bool do_stormfilter_enable (int nb UNUSED, const char **com UNUSED, struct ngadmin *nga) +bool do_stormfilter_enable (int argc, const char **argv UNUSED, struct ngadmin *nga) { int i; const struct swi_attr *sa; + if (argc > 0) { + printf("this command takes no argument\n"); + return false; + } + sa = ngadmin_getCurrentSwitch(nga); if (sa == NULL) { printf("must be logged\n"); @@ -22,12 +27,17 @@ bool do_stormfilter_enable (int nb UNUSED, const char **com UNUSED, struct ngadm } -bool do_stormfilter_disable (int nb UNUSED, const char **com UNUSED, struct ngadmin *nga) +bool do_stormfilter_disable (int argc, const char **argv UNUSED, struct ngadmin *nga) { int i; const struct swi_attr *sa; + if (argc > 0) { + printf("this command takes no argument\n"); + return false; + } + sa = ngadmin_getCurrentSwitch(nga); if (sa == NULL) { printf("must be logged\n"); @@ -42,15 +52,15 @@ bool do_stormfilter_disable (int nb UNUSED, const char **com UNUSED, struct ngad } -bool do_stormfilter_set (int nb, const char **com, struct ngadmin *nga) +bool do_stormfilter_set (int argc, const char **argv, struct ngadmin *nga) { int i, d = BITRATE_UNSPEC, p, *ports = NULL; const struct swi_attr *sa; bool ret = true; - if (nb < 2) { - printf("Usage: stormfilt set (all )|( [ ...])\n"); + if (argc < 2) { + printf("usage: stormfilt set (all )|( [ ...])\n"); ret = false; goto end; } @@ -62,24 +72,28 @@ bool do_stormfilter_set (int nb, const char **com, struct ngadmin *nga) goto end; } - ports=malloc(sa->ports * sizeof(int)); + ports = malloc(sa->ports * sizeof(int)); - if (strcmp(com[0], "all") == 0) { - d = parseBitrate(com[1]); - com += 2; - nb -= 2; + /* read defaults */ + if (strcmp(argv[0], "all") == 0) { + d = parseBitrate(argv[1]); + argv += 2; + argc -= 2; } + /* apply defaults */ for (i = 0; i < sa->ports; i++) ports[i] = d; - for (i = 0; i < nb; i += 2) { - p = strtol(com[i], NULL, 0); + /* read and apply port specifics */ + for (i = 0; i < argc - 1; i += 2) { + p = strtol(argv[i], NULL, 0); if (p < 1 || p > sa->ports) continue; - ports[p - 1] = parseBitrate(com[i + 1]); + ports[p - 1] = parseBitrate(argv[i + 1]); } + /* send the new configuration to the switch */ i = ngadmin_setStormFilterValues(nga, ports); printErrCode(i); @@ -90,12 +104,18 @@ end: } -bool do_stormfilter_show (int nb UNUSED, const char **com UNUSED, struct ngadmin *nga) +bool do_stormfilter_show (int argc, const char **argv UNUSED, struct ngadmin *nga) { int i, s, ret = true, *ports = NULL; const struct swi_attr *sa; + if (argc > 0) { + printf("this command takes no argument\n"); + ret = false; + goto end; + } + sa = ngadmin_getCurrentSwitch(nga); if (sa == NULL) { printf("must be logged\n"); diff --git a/cli/com_tree.c b/cli/com_tree.c index cad5d57..4b4384b 100644 --- a/cli/com_tree.c +++ b/cli/com_tree.c @@ -20,9 +20,14 @@ static void display_node (const struct TreeNode *tn, int depth) } -bool do_tree (int nb UNUSED, const char **com UNUSED, struct ngadmin *nga UNUSED) +bool do_tree (int argc, const char **argv UNUSED, struct ngadmin *nga UNUSED) { - display_node(&coms, 0); + if (argc > 0) { + printf("this command takes no argument\n"); + return false; + } + + display_node(&commands, 0); return true; } diff --git a/cli/com_vlan.c b/cli/com_vlan.c index 0f7014e..f70a6c9 100644 --- a/cli/com_vlan.c +++ b/cli/com_vlan.c @@ -22,26 +22,25 @@ static char vlan_char (int t) } -bool do_vlan_8021q_del (int nb, const char **com, struct ngadmin *nga) +bool do_vlan_8021q_del (int argc, const char **argv, struct ngadmin *nga) { const struct swi_attr *sa; unsigned short vlan; int i; - if (nb != 1) { - printf("Usage: vlan 8021q del \n"); + if (argc != 1) { + printf("usage: vlan 8021q del \n"); return false; } - sa = ngadmin_getCurrentSwitch(nga); if (sa == NULL) { printf("must be logged\n"); return false; } - vlan=strtoul(com[0], NULL, 0); + vlan=strtoul(argv[0], NULL, 0); if (vlan < 1 || vlan > VLAN_MAX) { printf("vlan out of range\n"); return false; @@ -55,7 +54,7 @@ bool do_vlan_8021q_del (int nb, const char **com, struct ngadmin *nga) } -bool do_vlan_8021q_set (int nb, const char **com, struct ngadmin *nga) +bool do_vlan_8021q_set (int argc, const char **argv, struct ngadmin *nga) { unsigned char *ports = NULL, p, def = VLAN_UNSPEC; const struct swi_attr *sa; @@ -64,8 +63,8 @@ bool do_vlan_8021q_set (int nb, const char **com, struct ngadmin *nga) int i, k = 0; - if (nb == 0) { - printf("Usage: vlan 802.1q set [all unspec|no|untagged|tagged] [ unspec|no|untagged|tagged ...]\n"); + if (argc == 0) { + printf("usage: vlan 802.1q set [all unspec|no|untagged|tagged] [ unspec|no|untagged|tagged ...]\n"); ret = false; goto end; } @@ -78,7 +77,7 @@ bool do_vlan_8021q_set (int nb, const char **com, struct ngadmin *nga) } /* read vlan */ - vlan = strtoul(com[k++], NULL, 0); + vlan = strtoul(argv[k++], NULL, 0); if (vlan < 1 || vlan > VLAN_MAX) { printf("vlan out of range\n"); @@ -87,15 +86,15 @@ bool do_vlan_8021q_set (int nb, const char **com, struct ngadmin *nga) } /* read defaults */ - if (k < nb - 1 && strcasecmp(com[k], "all") == 0) { + if (k < argc - 1 && strcasecmp(argv[k], "all") == 0) { k++; - if (strcasecmp(com[k], "tagged") == 0) { + if (strcasecmp(argv[k], "tagged") == 0) { def = VLAN_TAGGED; - } else if (strcasecmp(com[k], "untagged") == 0) { + } else if (strcasecmp(argv[k], "untagged") == 0) { def = VLAN_UNTAGGED; - } else if (strcasecmp(com[k], "no") == 0) { + } else if (strcasecmp(argv[k], "no") == 0) { def = VLAN_NO; - } else if (strcasecmp(com[k], "unspec") == 0) { + } else if (strcasecmp(argv[k], "unspec") == 0) { def = VLAN_UNSPEC; } else { printf("incorrect type\n"); @@ -111,20 +110,20 @@ bool do_vlan_8021q_set (int nb, const char **com, struct ngadmin *nga) memset(ports, def, sa->ports); /* apply port specifics */ - while (k < nb - 1) { - p = strtoul(com[k++], NULL, 0) - 1; + while (k < argc - 1) { + p = strtoul(argv[k++], NULL, 0) - 1; if (p >= sa->ports) { printf("port out of range\n"); ret = false; goto end; } - if (strcasecmp(com[k], "tagged") ==0) { + if (strcasecmp(argv[k], "tagged") ==0) { ports[p] = VLAN_TAGGED; - } else if (strcasecmp(com[k], "untagged") == 0) { + } else if (strcasecmp(argv[k], "untagged") == 0) { ports[p] = VLAN_UNTAGGED; - } else if (strcasecmp(com[k], "no") == 0) { + } else if (strcasecmp(argv[k], "no") == 0) { ports[p] = VLAN_NO; - } else if (strcasecmp(com[k], "unspec") == 0) { + } else if (strcasecmp(argv[k], "unspec") == 0) { ports[p] = VLAN_UNSPEC; } else { printf("incorrect type\n"); @@ -145,7 +144,7 @@ end: } -bool do_vlan_8021q_show (int nb, const char **com, struct ngadmin *nga) +bool do_vlan_8021q_show (int argc, const char **argv, struct ngadmin *nga) { unsigned short vl = 0, *vlans = NULL; unsigned char *ports = NULL; @@ -161,8 +160,8 @@ bool do_vlan_8021q_show (int nb, const char **com, struct ngadmin *nga) goto end; } - if (nb > 0) - vl = strtoul(com[0], NULL, 0); + if (argc > 0) + vl = strtoul(argv[0], NULL, 0); ports = malloc(sa->ports * n * sizeof(unsigned char)); @@ -213,14 +212,14 @@ end: } -bool do_vlan_mode_set (int nb, const char **com, struct ngadmin *nga) +bool do_vlan_mode_set (int argc, const char **argv, struct ngadmin *nga) { int mode, i; - if (nb == 0) { + if (argc == 0) { printf( - "Usage: vlan mode set \n" + "usage: vlan mode set \n" "1 - basic port based\n" "2 - advanced port based\n" "3 - basic 802.1Q\n" @@ -234,7 +233,7 @@ bool do_vlan_mode_set (int nb, const char **com, struct ngadmin *nga) return false; } - mode = strtoul(com[0], NULL, 0); + mode = strtoul(argv[0], NULL, 0); if (mode < 1 || mode > 4) { printf("mode out of range\n"); return false; @@ -248,11 +247,17 @@ bool do_vlan_mode_set (int nb, const char **com, struct ngadmin *nga) } -bool do_vlan_mode_show (int nb UNUSED, const char **com UNUSED, struct ngadmin *nga) +bool do_vlan_mode_show (int argc, const char **argv UNUSED, struct ngadmin *nga) { int i, t, ret = true; + if (argc > 0) { + printf("this command takes no argument\n"); + ret = false; + goto end; + } + if (ngadmin_getCurrentSwitch(nga) == NULL) { printf("must be logged\n"); ret = false; @@ -299,7 +304,7 @@ end: } -bool do_vlan_pvid_set (int nb, const char **com, struct ngadmin *nga) +bool do_vlan_pvid_set (int argc, const char **argv, struct ngadmin *nga) { const struct swi_attr *sa; unsigned char port; @@ -307,8 +312,8 @@ bool do_vlan_pvid_set (int nb, const char **com, struct ngadmin *nga) int i; - if (nb != 2) { - printf("Usage: vlan pvid set \n"); + if (argc != 2) { + printf("usage: vlan pvid set \n"); return false; } @@ -318,8 +323,8 @@ bool do_vlan_pvid_set (int nb, const char **com, struct ngadmin *nga) return false; } - port = strtoul(com[0], NULL, 0); - vlan = strtoul(com[1], NULL, 0); + port = strtoul(argv[0], NULL, 0); + vlan = strtoul(argv[1], NULL, 0); if (port < 1 || port > sa->ports) { printf("port out of range\n"); @@ -339,7 +344,7 @@ bool do_vlan_pvid_set (int nb, const char **com, struct ngadmin *nga) } -bool do_vlan_pvid_show (int nb UNUSED, const char **com UNUSED, struct ngadmin *nga) +bool do_vlan_pvid_show (int argc, const char **argv UNUSED, struct ngadmin *nga) { unsigned short *ports = NULL; const struct swi_attr *sa; @@ -347,6 +352,12 @@ bool do_vlan_pvid_show (int nb UNUSED, const char **com UNUSED, struct ngadmin * bool ret = true; + if (argc > 0) { + printf("this command takes no argument\n"); + ret = false; + goto end; + } + sa = ngadmin_getCurrentSwitch(nga); if (sa == NULL) { printf("must be logged\n"); diff --git a/cli/commands.c b/cli/commands.c index f0bf9a3..c5809e9 100644 --- a/cli/commands.c +++ b/cli/commands.c @@ -3,200 +3,200 @@ /* bitrate */ -bool do_bitrate_set (int nb, const char **com, struct ngadmin *nga); -bool do_bitrate_show (int nb, const char **com, struct ngadmin *nga); +bool do_bitrate_set (int argc, const char **argv, struct ngadmin *nga); +bool do_bitrate_show (int argc, const char **argv, struct ngadmin *nga); /* cabletest */ -bool do_cabletest (int nb, const char **com, struct ngadmin *nga); +bool do_cabletest (int argc, const char **argv, struct ngadmin *nga); /* defaults */ -bool do_defaults (int nb, const char **com, struct ngadmin *nga); +bool do_defaults (int argc, const char **argv, struct ngadmin *nga); /* firmware */ -bool do_firmware_show (int nb, const char **com, struct ngadmin *nga); -bool do_firmware_upgrade (int nb, const char **com, struct ngadmin *nga); +bool do_firmware_show (int argc, const char **argv, struct ngadmin *nga); +bool do_firmware_upgrade (int argc, const char **argv, struct ngadmin *nga); /* help */ -bool do_help (int nb, const char **com, struct ngadmin *nga); +bool do_help (int argc, const char **argv, struct ngadmin *nga); /* igmp */ -bool do_igmp_set (int nb, const char **com, struct ngadmin *nga); -bool do_igmp_show (int nb, const char **com, struct ngadmin *nga); +bool do_igmp_set (int argc, const char **argv, struct ngadmin *nga); +bool do_igmp_show (int argc, const char **argv, struct ngadmin *nga); /* list */ -bool do_list (int nb, const char **com, struct ngadmin *nga); +bool do_list (int argc, const char **argv, struct ngadmin *nga); /* login */ -bool do_login (int nb, const char **com, struct ngadmin *nga); +bool do_login (int argc, const char **argv, struct ngadmin *nga); /* mirror */ -bool do_mirror_disable (int nb, const char **com, struct ngadmin *nga); -bool do_mirror_set (int nb, const char **com, struct ngadmin *nga); -bool do_mirror_show (int nb, const char **com, struct ngadmin *nga); +bool do_mirror_disable (int argc, const char **argv, struct ngadmin *nga); +bool do_mirror_set (int argc, const char **argv, struct ngadmin *nga); +bool do_mirror_show (int argc, const char **argv, struct ngadmin *nga); /* name */ -bool do_name_show (int nb, const char **com, struct ngadmin *nga); -bool do_name_set (int nb, const char **com, struct ngadmin *nga); -bool do_name_clear (int nb, const char **com, struct ngadmin *nga); +bool do_name_show (int argc, const char **argv, struct ngadmin *nga); +bool do_name_set (int argc, const char **argv, struct ngadmin *nga); +bool do_name_clear (int argc, const char **argv, struct ngadmin *nga); /* netconf */ -bool do_netconf_set (int nb, const char **com, struct ngadmin *nga); +bool do_netconf_set (int argc, const char **argv, struct ngadmin *nga); /* password */ -bool do_password_change (int nb, const char **com, struct ngadmin *nga); -bool do_password_set (int nb, const char **com, struct ngadmin *nga); +bool do_password_change (int argc, const char **argv, struct ngadmin *nga); +bool do_password_set (int argc, const char **argv, struct ngadmin *nga); /* ports */ -bool do_ports_state (int nb, const char **com, struct ngadmin *nga); -bool do_ports_statistics_reset (int nb, const char **com, struct ngadmin *nga); -bool do_ports_statistics_show (int nb, const char **com, struct ngadmin *nga); +bool do_ports_state (int argc, const char **argv, struct ngadmin *nga); +bool do_ports_statistics_reset (int argc, const char **argv, struct ngadmin *nga); +bool do_ports_statistics_show (int argc, const char **argv, struct ngadmin *nga); /* qos */ -bool do_qos_mode (int nb, const char **com, struct ngadmin *nga); -bool do_qos_set (int nb, const char **com, struct ngadmin *nga); -bool do_qos_show (int nb, const char **com, struct ngadmin *nga); +bool do_qos_mode (int argc, const char **argv, struct ngadmin *nga); +bool do_qos_set (int argc, const char **argv, struct ngadmin *nga); +bool do_qos_show (int argc, const char **argv, struct ngadmin *nga); /* quit */ -bool do_quit (int nb, const char **com, struct ngadmin *nga); +bool do_quit (int argc, const char **argv, struct ngadmin *nga); /* restart */ -bool do_restart (int nb, const char **com, struct ngadmin *nga); +bool do_restart (int argc, const char **argv, struct ngadmin *nga); /* scan */ -bool do_scan (int nb, const char **com, struct ngadmin *nga); +bool do_scan (int argc, const char **argv, struct ngadmin *nga); /* stormfilter */ -bool do_stormfilter_enable (int nb, const char **com, struct ngadmin *nga); -bool do_stormfilter_disable (int nb, const char **com, struct ngadmin *nga); -bool do_stormfilter_set (int nb, const char **com, struct ngadmin *nga); -bool do_stormfilter_show (int nb, const char **com, struct ngadmin *nga); +bool do_stormfilter_enable (int argc, const char **argv, struct ngadmin *nga); +bool do_stormfilter_disable (int argc, const char **argv, struct ngadmin *nga); +bool do_stormfilter_set (int argc, const char **argv, struct ngadmin *nga); +bool do_stormfilter_show (int argc, const char **argv, struct ngadmin *nga); /* tree */ -bool do_tree (int nb, const char **com, struct ngadmin *nga); +bool do_tree (int argc, const char **argv, struct ngadmin *nga); /* vlan */ -bool do_vlan_8021q_del (int nb, const char **com, struct ngadmin *nga); -bool do_vlan_8021q_set (int nb, const char **com, struct ngadmin *nga); -bool do_vlan_8021q_show (int nb, const char **com, struct ngadmin *nga); -bool do_vlan_mode_set (int nb, const char **com, struct ngadmin *nga); -bool do_vlan_mode_show (int nb UNUSED, const char **com UNUSED, struct ngadmin *nga); -bool do_vlan_pvid_set (int nb, const char **com, struct ngadmin *nga); -bool do_vlan_pvid_show (int nb, const char **com, struct ngadmin *nga); +bool do_vlan_8021q_del (int argc, const char **argv, struct ngadmin *nga); +bool do_vlan_8021q_set (int argc, const char **argv, struct ngadmin *nga); +bool do_vlan_8021q_show (int argc, const char **argv, struct ngadmin *nga); +bool do_vlan_mode_set (int argc, const char **argv, struct ngadmin *nga); +bool do_vlan_mode_show (int argc, const char **argv, struct ngadmin *nga); +bool do_vlan_pvid_set (int argc, const char **argv, struct ngadmin *nga); +bool do_vlan_pvid_show (int argc, const char **argv, struct ngadmin *nga); /* commands structure */ -COM_ROOT_START(coms) +COM_ROOT_START(commands) COM_START(bitrate) - COM_TERM(set, do_bitrate_set, true) - COM_TERM(show, do_bitrate_show, false) + COM_TERM(set, do_bitrate_set) + COM_TERM(show, do_bitrate_show) COM_END - COM_TERM(cabletest, do_cabletest, true) + COM_TERM(cabletest, do_cabletest) - COM_TERM(defaults, do_defaults, false) + COM_TERM(defaults, do_defaults) COM_START(firmware) - COM_TERM(show, do_firmware_show, false) - COM_TERM(upgrade, do_firmware_upgrade, true) + COM_TERM(show, do_firmware_show) + COM_TERM(upgrade, do_firmware_upgrade) COM_END - COM_TERM(help, do_help, false) + COM_TERM(help, do_help) COM_START(igmp) - COM_TERM(set, do_igmp_set, true) - COM_TERM(show, do_igmp_show, false) + COM_TERM(set, do_igmp_set) + COM_TERM(show, do_igmp_show) COM_END - COM_TERM(list, do_list, false) + COM_TERM(list, do_list) - COM_TERM(login, do_login, true) + COM_TERM(login, do_login) COM_START(mirror) - COM_TERM(disable, do_mirror_disable, false) - COM_TERM(set, do_mirror_set, true) - COM_TERM(show, do_mirror_show, false) + COM_TERM(disable, do_mirror_disable) + COM_TERM(set, do_mirror_set) + COM_TERM(show, do_mirror_show) COM_END COM_START(name) - COM_TERM(show, do_name_show, false) - COM_TERM(set, do_name_set, true) - COM_TERM(clear, do_name_clear, false) + COM_TERM(show, do_name_show) + COM_TERM(set, do_name_set) + COM_TERM(clear, do_name_clear) COM_END COM_START(netconf) - COM_TERM(set, do_netconf_set, true) + COM_TERM(set, do_netconf_set) COM_END COM_START(password) - COM_TERM(change, do_password_change, true) - COM_TERM(set, do_password_set, true) + COM_TERM(change, do_password_change) + COM_TERM(set, do_password_set) COM_END COM_START(ports) - COM_TERM(state, do_ports_state, false) + COM_TERM(state, do_ports_state) COM_START(statistics) - COM_TERM(reset, do_ports_statistics_reset, false) - COM_TERM(show, do_ports_statistics_show, false) + COM_TERM(reset, do_ports_statistics_reset) + COM_TERM(show, do_ports_statistics_show) COM_END COM_END COM_START(qos) - COM_TERM(mode, do_qos_mode, true) - COM_TERM(set, do_qos_set, true) - COM_TERM(show, do_qos_show, false) + COM_TERM(mode, do_qos_mode) + COM_TERM(set, do_qos_set) + COM_TERM(show, do_qos_show) COM_END - COM_TERM(quit, do_quit, false) + COM_TERM(quit, do_quit) - COM_TERM(restart, do_restart, false) + COM_TERM(restart, do_restart) - COM_TERM(scan, do_scan, false) + COM_TERM(scan, do_scan) COM_START(stormfilter) - COM_TERM(enable, do_stormfilter_enable, false) - COM_TERM(disable, do_stormfilter_disable, false) - COM_TERM(set, do_stormfilter_set, true) - COM_TERM(show, do_stormfilter_show, false) + COM_TERM(enable, do_stormfilter_enable) + COM_TERM(disable, do_stormfilter_disable) + COM_TERM(set, do_stormfilter_set) + COM_TERM(show, do_stormfilter_show) COM_END - COM_TERM(tree, do_tree, false) + COM_TERM(tree, do_tree) COM_START(vlan) COM_START(802.1q) - COM_TERM(del, do_vlan_8021q_del, true) - COM_TERM(set, do_vlan_8021q_set, true) - COM_TERM(show, do_vlan_8021q_show, true) + COM_TERM(del, do_vlan_8021q_del) + COM_TERM(set, do_vlan_8021q_set) + COM_TERM(show, do_vlan_8021q_show) COM_END COM_START(mode) - COM_TERM(set, do_vlan_mode_set, true) - COM_TERM(show, do_vlan_mode_show, false) + COM_TERM(set, do_vlan_mode_set) + COM_TERM(show, do_vlan_mode_show) COM_END COM_START(port) - COM_TERM(set, NULL, true) - COM_TERM(show, NULL, false) + COM_TERM(set, NULL) + COM_TERM(show, NULL) COM_END COM_START(pvid) - COM_TERM(set, do_vlan_pvid_set, true) - COM_TERM(show, do_vlan_pvid_show, false) + COM_TERM(set, do_vlan_pvid_set) + COM_TERM(show, do_vlan_pvid_show) COM_END COM_END COM_ROOT_END diff --git a/cli/commands.h b/cli/commands.h index fa2ec66..5707dc0 100644 --- a/cli/commands.h +++ b/cli/commands.h @@ -9,19 +9,18 @@ struct TreeNode { const char *name; bool (* const comfunc)(int, const char**, struct ngadmin*); - bool hasArgs; const struct TreeNode *sub; }; -#define COM_ROOT_START(v) const struct TreeNode v = {.name = "", .comfunc = NULL, .hasArgs = false, .sub = (const struct TreeNode[]){ -#define COM_ROOT_END {.name = NULL, .comfunc = NULL, .hasArgs = false, .sub = NULL}}}; -#define COM_START(nam) {.name = #nam, .comfunc = NULL, .hasArgs = false, .sub = (const struct TreeNode[]){ -#define COM_END {.name = NULL, .comfunc = NULL, .hasArgs = false, .sub = NULL}}}, -#define COM_TERM(nam, func, args) {.name = #nam, .comfunc = func, .hasArgs = args, .sub = NULL}, +#define COM_ROOT_START(v) const struct TreeNode v = {.name = "", .comfunc = NULL, .sub = (const struct TreeNode[]){ +#define COM_ROOT_END {.name = NULL, .comfunc = NULL, .sub = NULL}}}; +#define COM_START(nam) {.name = #nam, .comfunc = NULL, .sub = (const struct TreeNode[]){ +#define COM_END {.name = NULL, .comfunc = NULL, .sub = NULL}}}, +#define COM_TERM(nam, func) {.name = #nam, .comfunc = func, .sub = NULL}, -extern const struct TreeNode coms; +extern const struct TreeNode commands; #endif diff --git a/cli/common.h b/cli/common.h index 6533f05..e50ae1e 100644 --- a/cli/common.h +++ b/cli/common.h @@ -16,7 +16,7 @@ #define NORET __attribute__((noreturn)) -extern int cont; +extern int main_loop_continue; extern struct termios current_term; -- 2.39.2