mirror of
https://github.com/profanity-im/profanity.git
synced 2024-11-03 19:37:16 -05:00
Created command_t struct for command handling
This commit is contained in:
parent
887278b91b
commit
0c0a242972
22
command.c
22
command.c
@ -34,6 +34,7 @@
|
|||||||
|
|
||||||
static gboolean _handle_command(const char * const command,
|
static gboolean _handle_command(const char * const command,
|
||||||
const char * const inp);
|
const char * const inp);
|
||||||
|
static struct command_t _parse_command(char *str);
|
||||||
static gboolean _cmd_quit(void);
|
static gboolean _cmd_quit(void);
|
||||||
static gboolean _cmd_help(void);
|
static gboolean _cmd_help(void);
|
||||||
static gboolean _cmd_who(void);
|
static gboolean _cmd_who(void);
|
||||||
@ -45,6 +46,11 @@ static gboolean _cmd_set_beep(const char * const inp);
|
|||||||
static gboolean _cmd_set_flash(const char * const inp);
|
static gboolean _cmd_set_flash(const char * const inp);
|
||||||
static gboolean _cmd_default(const char * const inp);
|
static gboolean _cmd_default(const char * const inp);
|
||||||
|
|
||||||
|
struct command_t {
|
||||||
|
char *command;
|
||||||
|
char **params;
|
||||||
|
};
|
||||||
|
|
||||||
gboolean process_input(char *inp)
|
gboolean process_input(char *inp)
|
||||||
{
|
{
|
||||||
gboolean result = FALSE;
|
gboolean result = FALSE;
|
||||||
@ -57,10 +63,8 @@ gboolean process_input(char *inp)
|
|||||||
if (strlen(inp) == 0) {
|
if (strlen(inp) == 0) {
|
||||||
result = TRUE;
|
result = TRUE;
|
||||||
} else if (inp[0] == '/') {
|
} else if (inp[0] == '/') {
|
||||||
char inp_cpy[strlen(inp) + 1];
|
struct command_t cmd = _parse_command(inp);
|
||||||
strcpy(inp_cpy, inp);
|
result = _handle_command(cmd.command, inp);
|
||||||
char *command = strtok(inp_cpy, " ");
|
|
||||||
result = _handle_command(command, inp);
|
|
||||||
} else {
|
} else {
|
||||||
result = _cmd_default(inp);
|
result = _cmd_default(inp);
|
||||||
}
|
}
|
||||||
@ -72,6 +76,16 @@ gboolean process_input(char *inp)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct command_t _parse_command(char *str)
|
||||||
|
{
|
||||||
|
struct command_t cmd;
|
||||||
|
char **split = g_strsplit(str, " ", 0);
|
||||||
|
|
||||||
|
cmd.command = split[0];
|
||||||
|
cmd.params = NULL;
|
||||||
|
return cmd;
|
||||||
|
}
|
||||||
|
|
||||||
static gboolean _handle_command(const char * const command, const char * const inp)
|
static gboolean _handle_command(const char * const command, const char * const inp)
|
||||||
{
|
{
|
||||||
gboolean result = FALSE;
|
gboolean result = FALSE;
|
||||||
|
Loading…
Reference in New Issue
Block a user