]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
wlantest: Replace the duplicate functions with reuse of cli.h
authorGokul Sivakumar <gokulkumar792@gmail.com>
Wed, 3 Nov 2021 16:50:22 +0000 (22:20 +0530)
committerJouni Malinen <j@w1.fi>
Sat, 11 Dec 2021 19:50:41 +0000 (21:50 +0200)
The definitions of max_args, get_cmd_arg_num(), and tokenize_cmd() are
already shared by the hostapd_cli and wpa_cli commands by including the
cli.h header. So follow the same for wlantest_cli and remove the
duplicate function defitions.

Signed-off-by: Gokul Sivakumar <gokulkumar792@gmail.com>
wlantest/Makefile
wlantest/wlantest_cli.c

index 0045020d413053c3302c9fc5b29b03a93a6fa86f..1eba3cec9fd5dbbf391291091e5d62d2812652e9 100644 (file)
@@ -64,6 +64,7 @@ TOBJS += gcmp.o
 
 
 OBJS_cli = wlantest_cli.o
+OBJS_cli += ../src/common/cli.o
 
 _OBJS_VAR := OBJS
 include ../src/objs.mk
index 7aa0c9ce2c434ca0024453613a176692079c63eb..0a1384ed9e2afc220ed4f050eb1d744670973d6f 100644 (file)
 #include "utils/common.h"
 #include "utils/eloop.h"
 #include "utils/edit.h"
+#include "common/cli.h"
 #include "wlantest_ctrl.h"
 
 static void print_help(FILE *stream, const char *cmd);
 static char ** wlantest_cli_cmd_list(void);
 
 
-static int get_cmd_arg_num(const char *str, int pos)
-{
-       int arg = 0, i;
-
-       for (i = 0; i <= pos; i++) {
-               if (str[i] != ' ') {
-                       arg++;
-                       while (i <= pos && str[i] != ' ')
-                               i++;
-               }
-       }
-
-       if (arg > 0)
-               arg--;
-       return arg;
-}
-
-
 static int get_prev_arg_pos(const char *str, int pos)
 {
        while (pos > 0 && str[pos - 1] != ' ')
@@ -1732,38 +1715,6 @@ struct wlantest_cli {
 };
 
 
-#define max_args 10
-
-static int tokenize_cmd(char *cmd, char *argv[])
-{
-       char *pos;
-       int argc = 0;
-
-       pos = cmd;
-       for (;;) {
-               while (*pos == ' ')
-                       pos++;
-               if (*pos == '\0')
-                       break;
-               argv[argc] = pos;
-               argc++;
-               if (argc == max_args)
-                       break;
-               if (*pos == '"') {
-                       char *pos2 = os_strrchr(pos, '"');
-                       if (pos2)
-                               pos = pos2 + 1;
-               }
-               while (*pos != '\0' && *pos != ' ')
-                       pos++;
-               if (*pos == ' ')
-                       *pos++ = '\0';
-       }
-
-       return argc;
-}
-
-
 static void wlantest_cli_edit_cmd_cb(void *ctx, char *cmd)
 {
        struct wlantest_cli *cli = ctx;