/* 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;
}
-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;
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 */
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 */
}
-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");