From 22102bdd37fa3c46c4002148e1b4048bffa4ad70 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sat, 11 Aug 2012 00:18:03 +0100 Subject: [PATCH] Refactored commands Now include usage and short help string --- src/command.c | 103 +++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 80 insertions(+), 23 deletions(-) diff --git a/src/command.c b/src/command.c index 8d906b15..c37763fa 100644 --- a/src/command.c +++ b/src/command.c @@ -36,8 +36,14 @@ #include "prof_autocomplete.h" #include "tinyurl.h" + +// helpers static gboolean _handle_command(const char * const command, const char * const inp); +static void _update_presence(const jabber_presence_t presence, + const char * const show, const char * const inp); + +// command prototypes static gboolean _cmd_quit(const char * const inp); static gboolean _cmd_help(const char * const inp); static gboolean _cmd_prefs(const char * const inp); @@ -58,38 +64,89 @@ static gboolean _cmd_dnd(const char * const inp); static gboolean _cmd_chat(const char * const inp); static gboolean _cmd_xa(const char * const inp); static gboolean _cmd_default(const char * const inp); -static void _update_presence(const jabber_presence_t presence, - const char * const show, const char * const inp); +typedef enum { + CMD_BASIC, + CMD_SETTING, + CMD_STATUS +} cmd_category_t; + + +/* command structure + * cmd - The actual string of the command + * func - The function to execute for the command + */ struct cmd_t { const gchar *cmd; + cmd_category_t category; gboolean (*func)(const char * const inp); + const gchar *usage; + const gchar *short_help; }; -static PAutocomplete commands_ac; - +// The commands static struct cmd_t commands[] = { - { "/away", _cmd_away }, - { "/beep", _cmd_set_beep }, - { "/notify", _cmd_set_notify }, - { "/chat", _cmd_chat }, - { "/close", _cmd_close }, - { "/connect", _cmd_connect }, - { "/dnd", _cmd_dnd }, - { "/flash", _cmd_set_flash }, - { "/prefs", _cmd_prefs }, - { "/msg", _cmd_msg }, - { "/tiny", _cmd_tiny }, - { "/online", _cmd_online }, - { "/quit", _cmd_quit }, - { "/ros", _cmd_ros }, - { "/showsplash", _cmd_set_showsplash }, - { "/chlog", _cmd_set_chlog }, - { "/who", _cmd_who }, - { "/xa", _cmd_xa }, - { "/help", _cmd_help } + + { "/close", CMD_BASIC, _cmd_close, NULL, + "Close current chat window." }, + + { "/connect", CMD_BASIC, _cmd_connect, "/connect user@host", + "Login to jabber." }, + + { "/prefs", CMD_BASIC, _cmd_prefs, NULL, + "Show current preferences." }, + + { "/msg", CMD_BASIC, _cmd_msg, "/msg user@host mesg", + "Send mesg to user." }, + + { "/tiny", CMD_BASIC, _cmd_tiny, "/tiny url", + "Send url as tinyurl in current chat." }, + + { "/quit", CMD_BASIC, _cmd_quit, NULL, + "Quit Profanity." }, + + { "/ros", CMD_BASIC, _cmd_ros, NULL, + "List all contacts." }, + + { "/who", CMD_BASIC, _cmd_who, NULL, + "Find out who is online." }, + + { "/help", CMD_BASIC, _cmd_help, NULL, + "This help." }, + + { "/beep", CMD_SETTING, _cmd_set_beep, "/beep ", + "Enable/disable sound notifications." }, + + { "/notify", CMD_SETTING, _cmd_set_notify, "/notify ", + "Enable/disable desktop notifications." }, + + { "/flash", CMD_SETTING, _cmd_set_flash, "/flash ", + "Enable/disable screen flash notifications." }, + + { "/showsplash", CMD_SETTING, _cmd_set_showsplash, "/showsplash ", + "Enable/disable splash logo on startup." }, + + { "/chlog", CMD_SETTING, _cmd_set_chlog, "/chlog ", + "Enable/disable chat logging." }, + + { "/away", CMD_STATUS, _cmd_away, "/away ", + "Set status to away." }, + + { "/chat", CMD_STATUS, _cmd_chat, "/chat ", + "Set status to chat (available for chat)." }, + + { "/dnd", CMD_STATUS, _cmd_dnd, "/dnd ", + "Set status to dnd (do not disturb." }, + + { "/online", CMD_STATUS, _cmd_online, "/online ", + "Set status to online." }, + + { "/xa", CMD_STATUS, _cmd_xa, "/xa ", + "Set status to xa (extended away)." } }; +static PAutocomplete commands_ac; + gboolean process_input(char *inp) {