cli: Share a common get_cmd_arg_num() implementation

wpa_cli and hostapd_cli had identical copies of this function.

Signed-off-by: Jouni Malinen <j@w1.fi>
This commit is contained in:
Jouni Malinen 2016-08-06 12:39:56 +03:00
parent e55df99ee6
commit fcc84b48b2
4 changed files with 20 additions and 36 deletions

View file

@ -74,24 +74,6 @@ static void usage(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 void register_event_handler(struct wpa_ctrl *ctrl) static void register_event_handler(struct wpa_ctrl *ctrl)
{ {
if (!ctrl_conn) if (!ctrl_conn)

View file

@ -188,3 +188,21 @@ char ** cli_txt_list_array(struct dl_list *txt_list)
return res; return res;
} }
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;
}

View file

@ -37,4 +37,6 @@ int cli_txt_list_add_word(struct dl_list *txt_list, const char *txt,
char ** cli_txt_list_array(struct dl_list *txt_list); char ** cli_txt_list_array(struct dl_list *txt_list);
int get_cmd_arg_num(const char *str, int pos);
#endif /* CLI_H */ #endif /* CLI_H */

View file

@ -90,24 +90,6 @@ static void usage(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 wpa_cli_show_event(const char *event) static int wpa_cli_show_event(const char *event)
{ {
const char *start; const char *start;