]> git.sur5r.net Git - ngadmin/blobdiff - cli/com_bitrate.c
Let commands handle themselves absence of arguments
[ngadmin] / cli / com_bitrate.c
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");