mirror of
https://git.kernel.org/pub/scm/network/wireless/iwd.git
synced 2024-11-10 14:09:22 +01:00
client: add cmd line token finder
This allows to inspect the cmd line for the existence of a provided token. This enables the completers to look back to what was entered before them and make decisions based on that information. For example, this can be used in completion of the property values to identify the property for which the value is being completed.
This commit is contained in:
parent
bb1a0adec7
commit
c5cf3b083f
@ -130,6 +130,38 @@ static bool cmd_completion_cmd_has_arg(const char *cmd,
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool find_next_token(int *i, const char *token, int token_len)
|
||||||
|
{
|
||||||
|
char *line = rl_line_buffer;
|
||||||
|
|
||||||
|
while (*i && line[*i] == ' ')
|
||||||
|
(*i)--;
|
||||||
|
|
||||||
|
while (*i && line[*i] != ' ')
|
||||||
|
(*i)--;
|
||||||
|
|
||||||
|
return !strncmp(line + (line[*i] == ' ' ? *i + 1 : *i),
|
||||||
|
token, token_len);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool command_line_find_token(const char *token, uint8_t num_to_inspect)
|
||||||
|
{
|
||||||
|
int i = rl_point - 1;
|
||||||
|
int len = strlen(token);
|
||||||
|
|
||||||
|
if (!len)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
while (i && num_to_inspect) {
|
||||||
|
if (find_next_token(&i, token, len))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
num_to_inspect--;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
static char **cmd_completion_match_entity_cmd(const char *cmd, const char *text,
|
static char **cmd_completion_match_entity_cmd(const char *cmd, const char *text,
|
||||||
const struct command *cmd_list)
|
const struct command *cmd_list)
|
||||||
{
|
{
|
||||||
|
@ -49,6 +49,7 @@ struct command_family {
|
|||||||
void (*set_default_entity)(const char *entity);
|
void (*set_default_entity)(const char *entity);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
bool command_line_find_token(const char *token, uint8_t num_to_inspect);
|
||||||
char **command_completion(const char *text, int start, int end);
|
char **command_completion(const char *text, int start, int end);
|
||||||
char *command_entity_arg_completion(const char *text, int state,
|
char *command_entity_arg_completion(const char *text, int state,
|
||||||
const struct command *command_list);
|
const struct command *command_list);
|
||||||
|
Loading…
Reference in New Issue
Block a user