3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-12-22 13:02:44 +01:00

client: define basic command ops

This commit is contained in:
Tim Kourt 2017-04-12 13:04:48 -07:00 committed by Denis Kenzior
parent af8afc6814
commit 17569c8d8b
2 changed files with 84 additions and 0 deletions

View File

@ -27,9 +27,80 @@
#include <ell/ell.h>
#include "command.h"
#include "display.h"
static struct l_queue *command_families;
static void cmd_version(const char *entity, char *arg)
{
display("IWD version %s\n", VERSION);
}
static void cmd_quit(const char *entity, char *arg)
{
display_quit();
l_main_quit();
}
static const struct command command_list[] = {
{ NULL, "version", NULL, cmd_version, "Display version" },
{ NULL, "quit", NULL, cmd_quit, "Quit program" },
{ NULL, "exit", NULL, cmd_quit },
{ NULL, "help" },
{ }
};
static bool match_cmd(const char *family, const char *entity, const char *cmd,
char *args, const struct command *command_list)
{
return false;
}
static bool match_cmd_family(const char *cmd_family, char *arg)
{
return false;
}
static void list_commands(const char *command_family,
const struct command *cmd_list)
{
}
static void list_cmd_families(void)
{
}
void command_process_prompt(char *prompt)
{
const char *cmd;
char *arg = NULL;
cmd = strtok_r(prompt, " ", &arg);
if (!cmd)
return;
if (match_cmd_family(cmd, arg))
return;
if (match_cmd(NULL, NULL, cmd, arg, command_list))
return;
if (strcmp(cmd, "help")) {
display("Invalid command\n");
return;
}
display_table_header("Available commands", MARGIN "%-*s%-*s",
50, "Commands", 28, "Description");
list_cmd_families();
display("\n");
list_commands(NULL, command_list);
}
void command_family_register(const struct command_family *family)
{
l_queue_push_tail(command_families, (void *) family);

View File

@ -20,10 +20,23 @@
*
*/
typedef char *(*command_completion_func_t) (const char *text, int state);
struct command {
const char *entity;
const char *cmd;
const char *arg;
void (*function)(const char *entity, char *arg);
const char *desc;
};
struct command_family {
const char *name;
const struct command *command_list;
};
void command_process_prompt(char *prompt);
void command_family_register(const struct command_family *family);
void command_family_unregister(const struct command_family *family);