diff --git a/client/ad-hoc.c b/client/ad-hoc.c index 1bb1e302..ca6db2d4 100644 --- a/client/ad-hoc.c +++ b/client/ad-hoc.c @@ -229,31 +229,8 @@ static const struct command ad_hoc_commands[] = { static char *family_arg_completion(const char *text, int state) { - static bool first_pass; - static size_t index; - static size_t len; - const char *cmd; - - if (!state) { - index = 0; - len = strlen(text); - first_pass = true; - } - - while ((cmd = ad_hoc_commands[index].cmd)) { - if (ad_hoc_commands[index++].entity) - continue; - - if (!strncmp(cmd, text, len)) - return l_strdup(cmd); - } - - if (first_pass) { - state = 0; - first_pass = false; - } - - return device_ad_hoc_family_arg_completion(text, state); + return device_arg_completion(text, state, ad_hoc_commands, + IWD_AD_HOC_INTERFACE); } static char *entity_arg_completion(const char *text, int state) diff --git a/client/ap.c b/client/ap.c index ad6fb83a..0c7a08e5 100644 --- a/client/ap.c +++ b/client/ap.c @@ -201,31 +201,8 @@ static const struct command ap_commands[] = { static char *family_arg_completion(const char *text, int state) { - static bool first_pass; - static size_t index; - static size_t len; - const char *cmd; - - if (!state) { - index = 0; - len = strlen(text); - first_pass = true; - } - - while ((cmd = ap_commands[index].cmd)) { - if (ap_commands[index++].entity) - continue; - - if (!strncmp(cmd, text, len)) - return l_strdup(cmd); - } - - if (first_pass) { - state = 0; - first_pass = false; - } - - return device_ap_family_arg_completion(text, state); + return device_arg_completion(text, state, ap_commands, + IWD_ACCESS_POINT_INTERFACE); } static char *entity_arg_completion(const char *text, int state) diff --git a/client/device.c b/client/device.c index 9996eaea..9e8ab916 100644 --- a/client/device.c +++ b/client/device.c @@ -435,39 +435,9 @@ static const struct command device_commands[] = { { } }; -char *device_wsc_family_arg_completion(const char *text, int state) -{ - return proxy_property_str_completion(&device_interface_type, - match_by_partial_name, - "Name", text, state, - IWD_WSC_INTERFACE); -} - -char *device_ap_family_arg_completion(const char *text, int state) -{ - return proxy_property_str_completion(&device_interface_type, - match_by_partial_name, - "Name", text, state, - IWD_ACCESS_POINT_INTERFACE); -} - -char *device_ad_hoc_family_arg_completion(const char *text, int state) -{ - return proxy_property_str_completion(&device_interface_type, - match_by_partial_name, - "Name", text, state, - IWD_AD_HOC_INTERFACE); -} - -char *device_station_family_arg_completion(const char *text, int state) -{ - return proxy_property_str_completion(&device_interface_type, - match_by_partial_name, - "Name", text, state, - IWD_STATION_INTERFACE); -} - -static char *family_arg_completion(const char *text, int state) +char *device_arg_completion(const char *text, int state, + const struct command *commands, + const char *extra_interface) { static bool first_pass; static size_t index; @@ -480,8 +450,8 @@ static char *family_arg_completion(const char *text, int state) first_pass = true; } - while ((cmd = device_commands[index].cmd)) { - if (device_commands[index++].entity) + while ((cmd = commands[index].cmd)) { + if (commands[index++].entity) continue; if (!strncmp(cmd, text, len)) @@ -495,7 +465,12 @@ static char *family_arg_completion(const char *text, int state) return proxy_property_str_completion(&device_interface_type, match_by_partial_name, "Name", - text, state, NULL); + text, state, extra_interface); +} + +static char *family_arg_completion(const char *text, int state) +{ + return device_arg_completion(text, state, device_commands, NULL); } static char *entity_arg_completion(const char *text, int state) diff --git a/client/device.h b/client/device.h index 5ed2597e..e27c2db0 100644 --- a/client/device.h +++ b/client/device.h @@ -22,10 +22,9 @@ struct proxy_interface; -char *device_wsc_family_arg_completion(const char *text, int state); -char *device_ap_family_arg_completion(const char *text, int state); -char *device_ad_hoc_family_arg_completion(const char *text, int state); -char *device_station_family_arg_completion(const char *text, int state); +char *device_arg_completion(const char *text, int state, + const struct command *commands, + const char *extra_interface); const struct proxy_interface *device_proxy_find_by_name(const char *name); const struct proxy_interface *device_proxy_find(const char *device_name, diff --git a/client/station.c b/client/station.c index f2106afa..dc3306a9 100644 --- a/client/station.c +++ b/client/station.c @@ -494,31 +494,8 @@ static const struct command station_commands[] = { static char *family_arg_completion(const char *text, int state) { - static bool first_pass; - static size_t index; - static size_t len; - const char *cmd; - - if (!state) { - index = 0; - len = strlen(text); - first_pass = true; - } - - while ((cmd = station_commands[index].cmd)) { - if (station_commands[index++].entity) - continue; - - if (!strncmp(cmd, text, len)) - return l_strdup(cmd); - } - - if (first_pass) { - state = 0; - first_pass = false; - } - - return device_station_family_arg_completion(text, state); + return device_arg_completion(text, state, station_commands, + IWD_STATION_INTERFACE); } static char *entity_arg_completion(const char *text, int state) diff --git a/client/wsc.c b/client/wsc.c index 31c54c7c..1c53a2e2 100644 --- a/client/wsc.c +++ b/client/wsc.c @@ -214,31 +214,8 @@ static const struct command wsc_commands[] = { static char *family_arg_completion(const char *text, int state) { - static bool first_pass; - static size_t index; - static size_t len; - const char *cmd; - - if (!state) { - index = 0; - len = strlen(text); - first_pass = true; - } - - while ((cmd = wsc_commands[index].cmd)) { - if (wsc_commands[index++].entity) - continue; - - if (!strncmp(cmd, text, len)) - return l_strdup(cmd); - } - - if (first_pass) { - state = 0; - first_pass = false; - } - - return device_wsc_family_arg_completion(text, state); + return device_arg_completion(text, state, wsc_commands, + IWD_WSC_INTERFACE); } static char *entity_arg_completion(const char *text, int state)