]> git.sur5r.net Git - ngadmin/commitdiff
Let commands handle themselves absence of arguments
authordarkcoven <admin@darkcoven.tk>
Fri, 20 Sep 2013 17:51:17 +0000 (19:51 +0200)
committerdarkcoven <admin@darkcoven.tk>
Fri, 20 Sep 2013 17:51:17 +0000 (19:51 +0200)
24 files changed:
cli/admin.c
cli/com_bitrate.c
cli/com_cabletest.c
cli/com_defaults.c
cli/com_firmware.c
cli/com_help.c
cli/com_igmp.c
cli/com_list.c
cli/com_login.c
cli/com_mirror.c
cli/com_name.c
cli/com_netconf.c
cli/com_password.c
cli/com_ports.c
cli/com_qos.c
cli/com_quit.c
cli/com_restart.c
cli/com_scan.c
cli/com_stormfilter.c
cli/com_tree.c
cli/com_vlan.c
cli/commands.c
cli/commands.h
cli/common.h

index e3fbec65e89bb37577796a6f4449cb8b579b946a..14ad11cf9ce1bc413f98be4baface91bd27b0ce4 100644 (file)
@@ -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 <interface>]\n", argv[0]);
+                       printf("usage: %s [-b] [-f] [-g] [-i <interface>]\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++) {
index 2f7a5a934626b335926b286d7c9fa458e2727751..60415822baeb07bd6d55f39e347fc9b1eca64dd3 100644 (file)
@@ -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] <port1> SPEEDSPEC [<port2> SPEEDSPEC ...]\n"
+               "usage: bitrate set [all SPEEDSPEC] <port1> SPEEDSPEC [<port2> SPEEDSPEC ...]\n"
                "SPEEDSPEC: [inout <speed>] [in <ispeed>] [out <ospeed>]\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 <sa->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");
index f23763f9e9ce0a898d79724c5a415f6483e7e9d9..370d1cd90ac31217588dae01e87d8b22b94a3464 100644 (file)
@@ -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 <port1> [<port2> ...]\n");
+       if (argc < 1) {
+               printf("usage: cabletest <port1> [<port2> ...]\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++;
        }
index a1c7107fc7972063989ad560e7000ec0880c300c..3574e4b52b63c69fdd928d129fb48e1adf399a16 100644 (file)
@@ -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");
index cc931fecf30d40699a694cb84d14e7c1e0f2f228..d3e9d0df24f5bd94f83ebd8ea41fdb76a64dbebc 100644 (file)
@@ -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 <file>\n");
+       if (argc != 1) {
+               printf("usage: firmware upgrade <file>\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:
index e1bad0e5289f8f6e71097ee46cdcba5df3e51510..a857cc15b61bfbd4f269677305f1da67d3aff992 100644 (file)
@@ -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');
        
index 3d57a03407ce21f6a27aef19d1d0e1963b9facb4..22647ff614e21f5d94c95d724dbf3e3c3669f3e4 100644 (file)
@@ -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 <enable> <vlan> <validate> <block>\n");
+       if (argc != 4) {
+               printf("usage: igmp set <enable> <vlan> <validate> <block>\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;
index 820d6989ec00e2c2b2679a8638611ae5b57b3e3c..064690cde700eebe8010b8f47592c5c6d6ebc883 100644 (file)
@@ -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);
        
index 61b4f074d1be20dc0137a40727b33c99bffc4d29..ed4154e3c715e40a7ec056a6e1217eeeae8048d0 100644 (file)
@@ -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 <num>\n");
+       if (argc != 1) {
+               printf("usage: login <num>\n");
                return false;
        }
        
-       i = strtol(com[0], NULL, 0);
+       i = strtol(argv[0], NULL, 0);
        i = ngadmin_login(nga, i);
        printErrCode(i);
        
index 75ca75ca63a1c0cbf14d5fc6fa0485d9aa0fd59d..507ee1f8fbf9336f1bc84ff181fe8887dbe8a1e0 100644 (file)
@@ -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 <destination port> clone <port1> [<port2> ...]\n");
+       if (argc < 3) {
+               printf("usage: mirror set <destination port> clone <port1> [<port2> ...]\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) {
index 0e2524ab0b22b68bff22cb82d2dcb71cded89761..8e47878c0f27c4065cb692f1d01efc064dfda61f 100644 (file)
@@ -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 <value>\n");
+       if (argc != 1) {
+               printf("usage: name set <value>\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");
index 5c165ae186969ddcf3720189b9699164e8eecbeb..99cd6baa9926b046de174619c499dd0afb15a5f8 100644 (file)
@@ -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 <ip>] [mask <mask>] [gw <gw>]\n");
+       if (argc == 0) {
+               printf("usage: netconf set [dhcp yes|no] [ip <ip>] [mask <mask>] [gw <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;
index 9264bb9e443840c4b75129d84218aca1f0f8f4e2..f67ccc09e96c55b6d6aeaa38f8010ad2de421d05 100644 (file)
@@ -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 <value>\n");
+       if (argc != 1) {
+               printf("usage: password change <value>\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 [<value>]\n");
+       if (argc > 1) {
+               printf("usage: password set [<value>]\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, &current_term);
                putchar('\n');
        } else {
-               pass = com[0];
+               pass = argv[0];
        }
        
        if (pass != NULL) {
index 7c3fbb22b6ca6ec57764f311ef935bfb4bad760b..866a84b49a5413ecabafd77e8bc723ac64dd730d 100644 (file)
@@ -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");
index 4adf9b61c378fca6e7423910295e0f25debae7c8..ac2ea81823cc2a5f463e66a6d0ce0be0cdddbc00 100644 (file)
@@ -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 <prio0>)|(<port1> <prio1> [<port2> <prio2> ...])\n");
+       if (argc < 2) {
+               printf("usage: qos set (all <prio0>)|(<port1> <prio1> [<port2> <prio2> ...])\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");
index 96cb0690099f2730d56d15ee1d75a5c8f5b30245..8a78fe16ec09e627d20bce9cdf149fbb7c5cf084 100644 (file)
@@ -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;
 }
index 9c001d1aebc249c4ec6f9389aab498e665f139ec..590ac6b0241959502230e75859e675e8f1005b49 100644 (file)
@@ -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");
index 9d9bb136b0efc5514727ba9c97eb8fb8b6513ba3..7b96e5ea003129f59ecf54d48c3f7073cb93d5c9 100644 (file)
@@ -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;
index 76076bfe517c0838be0d556b5ea6643ef5c0ffd1..6f2f5165adb30a6935ae7df95861a76364b4d1a2 100644 (file)
@@ -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 <speed0>)|(<port1> <speed1> [<port2> <speed2> ...])\n");
+       if (argc < 2) {
+               printf("usage: stormfilt set (all <speed0>)|(<port1> <speed1> [<port2> <speed2> ...])\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");
index cad5d5725d2bb96bb015be06620db2112580186f..4b4384b3e56b96b242e5b83f2a52b47056edacc4 100644 (file)
@@ -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;
 }
index 0f7014e9c175bb0d22e6d9bc439d9cab4d2cdac7..f70a6c941b411ea8c487563ca84d84ab075377cf 100644 (file)
@@ -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 <vlan>\n");
+       if (argc != 1) {
+               printf("usage: vlan 8021q del <vlan>\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 <vlan> [all unspec|no|untagged|tagged] [<port1> unspec|no|untagged|tagged ...]\n");
+       if (argc == 0) {
+               printf("usage: vlan 802.1q set <vlan> [all unspec|no|untagged|tagged] [<port1> 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 <mode>\n"
+               "usage: vlan mode set <mode>\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 <port> <vlan>\n");
+       if (argc != 2) {
+               printf("usage: vlan pvid set <port> <vlan>\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");
index f0bf9a31eadfe57c2af8670f2856bd03a5257de2..c5809e92bb2a41fcc50374d4250ef6724f826a78 100644 (file)
 
 
 /* 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
index fa2ec667a60dd1f3aba1b0bebcf84158fce531fe..5707dc099ec15390978d303f2b2911ac377baafb 100644 (file)
@@ -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 = "<root>", .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 = "<root>", .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
index 6533f05dfaeb9c2a17d66b8d40c76241781bd805..e50ae1e6e57a557a04a38a6175868155456b6983 100644 (file)
@@ -16,7 +16,7 @@
 #define NORET                  __attribute__((noreturn))
 
 
-extern int cont;
+extern int main_loop_continue;
 extern struct termios current_term;