eiwd

no dbus iwd with iwctl functionality
git clone https://git.daat.foo/repos/eiwd.git
Log | Files | Refs | Submodules | README | LICENSE

commit c5cf3b083f947b26d3499c22603d009a0e414694
parent bb1a0adec75a1e3156e83e40008136c592cdd6da
Author: Tim Kourt <tim.a.kourt@linux.intel.com>
Date:   Tue, 24 Jul 2018 16:17:24 -0700

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.

Diffstat:
Mclient/command.c | 32++++++++++++++++++++++++++++++++
Mclient/command.h | 1+
2 files changed, 33 insertions(+), 0 deletions(-)

diff --git a/client/command.c b/client/command.c @@ -130,6 +130,38 @@ static bool cmd_completion_cmd_has_arg(const char *cmd, 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, const struct command *cmd_list) { diff --git a/client/command.h b/client/command.h @@ -49,6 +49,7 @@ struct command_family { 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_entity_arg_completion(const char *text, int state, const struct command *command_list);