diff options
author | Timo Sirainen <cras@irssi.org> | 2000-06-28 17:15:37 +0000 |
---|---|---|
committer | cras <cras@dbcabf3a-b0e7-0310-adc4-f8d773084564> | 2000-06-28 17:15:37 +0000 |
commit | 7e531cec7a80a3bc6cecb844d66ae5127f7e7a94 (patch) | |
tree | 2e2452b4fbec35a8a34e0b7364544c43d71bcd83 /src/fe-common | |
parent | dd7ce4af23a0bb68a8c735c7e9a4c0d9c50ae08b (diff) | |
download | irssi-7e531cec7a80a3bc6cecb844d66ae5127f7e7a94.zip |
Automatic command completion and a few other fixes.
git-svn-id: http://svn.irssi.org/repos/irssi/trunk@387 dbcabf3a-b0e7-0310-adc4-f8d773084564
Diffstat (limited to 'src/fe-common')
-rw-r--r-- | src/fe-common/core/fe-core-commands.c | 72 | ||||
-rw-r--r-- | src/fe-common/core/fe-log.c | 7 | ||||
-rw-r--r-- | src/fe-common/core/module-formats.c | 8 | ||||
-rw-r--r-- | src/fe-common/core/module-formats.h | 10 | ||||
-rw-r--r-- | src/fe-common/irc/dcc/fe-dcc.c | 12 | ||||
-rw-r--r-- | src/fe-common/irc/fe-channels.c | 12 | ||||
-rw-r--r-- | src/fe-common/irc/fe-ircnet.c | 15 |
7 files changed, 75 insertions, 61 deletions
diff --git a/src/fe-common/core/fe-core-commands.c b/src/fe-common/core/fe-core-commands.c index 894eae6f..b1edbf78 100644 --- a/src/fe-common/core/fe-core-commands.c +++ b/src/fe-common/core/fe-core-commands.c @@ -30,14 +30,19 @@ #include "windows.h" -static const char *ret_texts[] = { - NULL, - "Not enough parameters given", - "Not connected to IRC server yet", - "Not joined to any channels yet", - "Not joined to such channel", - "Channel not fully synchronized yet, try again after a while", - "Doing this is not a good idea. Add -YES if you really mean it", +static int ret_texts[] = { + IRCTXT_OPTION_UNKNOWN, + IRCTXT_OPTION_AMBIGUOUS, + IRCTXT_OPTION_MISSING_ARG, + IRCTXT_COMMAND_UNKNOWN, + IRCTXT_COMMAND_AMBIGUOUS, + -1, + IRCTXT_NOT_ENOUGH_PARAMS, + IRCTXT_NOT_CONNECTED, + IRCTXT_NOT_JOINED, + IRCTXT_CHAN_NOT_FOUND, + IRCTXT_CHAN_NOT_SYNCED, + IRCTXT_NOT_GOOD_IDEA }; /* keep the whole command line here temporarily. we need it in @@ -269,17 +274,6 @@ static void cmd_beep(void) printbeep(); } -static void cmd_unknown(const char *data, void *server, WI_ITEM_REC *item) -{ - char *cmd; - - cmd = g_strdup(data); g_strup(cmd); - printtext(server, item == NULL ? NULL : item->name, MSGLEVEL_CRAP, "Unknown command: %s", cmd); - g_free(cmd); - - signal_stop(); -} - static void event_command(const char *data) { current_cmdline = data; @@ -287,21 +281,28 @@ static void event_command(const char *data) static void event_default_command(const char *data, void *server, WI_ITEM_REC *item) { - const char *cmd; + const char *ptr; + char *cmd, *p; - cmd = data; - while (*cmd != '\0' && *cmd != ' ') { - if (strchr(settings_get_str("cmdchars"), *cmd)) { + ptr = data; + while (*ptr != '\0' && *ptr != ' ') { + if (strchr(settings_get_str("cmdchars"), *ptr)) { /* command character inside command .. we probably want to send this text to channel. for example when pasting a path /usr/bin/xxx. */ signal_emit("send text", 3, current_cmdline, server, item); return; } - cmd++; + ptr++; } - cmd_unknown(data, server, item); + cmd = g_strdup(data); + p = strchr(cmd, ' '); + if (p != NULL) *p = '\0'; + + signal_emit("error command", 2, GINT_TO_POINTER(CMDERR_UNKNOWN), cmd); + + g_free(cmd); } static void event_cmderror(gpointer errorp, const char *arg) @@ -309,21 +310,12 @@ static void event_cmderror(gpointer errorp, const char *arg) int error; error = GPOINTER_TO_INT(errorp); - switch (error) { - case CMDERR_ERRNO: + if (error == CMDERR_ERRNO) { + /* errno is special */ printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, g_strerror(errno)); - break; - case CMDERR_OPTION_UNKNOWN: - printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, IRCTXT_OPTION_UNKNOWN, arg); - break; - case CMDERR_OPTION_AMBIGUOUS: - printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, IRCTXT_OPTION_AMBIGUOUS, arg); - break; - case CMDERR_OPTION_ARG_MISSING: - printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, IRCTXT_OPTION_MISSING_ARG, arg); - break; - default: - printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, ret_texts[error]); + } else { + /* others */ + printformat(NULL, NULL, MSGLEVEL_CLIENTERROR, ret_texts[error + -CMDERR_OPTION_UNKNOWN], arg); } } @@ -335,7 +327,6 @@ void fe_core_commands_init(void) command_bind("cat", NULL, (SIGNAL_FUNC) cmd_cat); command_bind("beep", NULL, (SIGNAL_FUNC) cmd_beep); - signal_add("unknown command", (SIGNAL_FUNC) cmd_unknown); signal_add("send command", (SIGNAL_FUNC) event_command); signal_add("default command", (SIGNAL_FUNC) event_default_command); signal_add("error command", (SIGNAL_FUNC) event_cmderror); @@ -349,7 +340,6 @@ void fe_core_commands_deinit(void) command_unbind("cat", (SIGNAL_FUNC) cmd_cat); command_unbind("beep", (SIGNAL_FUNC) cmd_beep); - signal_remove("unknown command", (SIGNAL_FUNC) cmd_unknown); signal_remove("send command", (SIGNAL_FUNC) event_command); signal_remove("default command", (SIGNAL_FUNC) event_default_command); signal_remove("error command", (SIGNAL_FUNC) event_cmderror); diff --git a/src/fe-common/core/fe-log.c b/src/fe-common/core/fe-log.c index 1da7e229..e0277029 100644 --- a/src/fe-common/core/fe-log.c +++ b/src/fe-common/core/fe-log.c @@ -176,7 +176,10 @@ static void cmd_log_list(void) static void cmd_log(const char *data, SERVER_REC *server, void *item) { - command_runsub("log", data, server, item); + if (*data == '\0') + cmd_log_list(); + else + command_runsub("log", data, server, item); } static LOG_REC *log_find_item(const char *item) @@ -438,7 +441,6 @@ void fe_log_init(void) command_bind("log close", NULL, (SIGNAL_FUNC) cmd_log_close); command_bind("log start", NULL, (SIGNAL_FUNC) cmd_log_start); command_bind("log stop", NULL, (SIGNAL_FUNC) cmd_log_stop); - command_bind("log ", NULL, (SIGNAL_FUNC) cmd_log_list); command_bind("window log", NULL, (SIGNAL_FUNC) cmd_window_log); command_bind("window logfile", NULL, (SIGNAL_FUNC) cmd_window_logfile); signal_add_first("print text stripped", (SIGNAL_FUNC) sig_printtext_stripped); @@ -461,7 +463,6 @@ void fe_log_deinit(void) command_unbind("log close", (SIGNAL_FUNC) cmd_log_close); command_unbind("log start", (SIGNAL_FUNC) cmd_log_start); command_unbind("log stop", (SIGNAL_FUNC) cmd_log_stop); - command_unbind("log ", (SIGNAL_FUNC) cmd_log_list); command_unbind("window log", (SIGNAL_FUNC) cmd_window_log); command_unbind("window logfile", (SIGNAL_FUNC) cmd_window_logfile); signal_remove("print text stripped", (SIGNAL_FUNC) sig_printtext_stripped); diff --git a/src/fe-common/core/module-formats.c b/src/fe-common/core/module-formats.c index 6f704e99..f7ff757f 100644 --- a/src/fe-common/core/module-formats.c +++ b/src/fe-common/core/module-formats.c @@ -94,6 +94,14 @@ FORMAT_REC fecommon_core_formats[] = { { "option_unknown", "Unknown option: $0", 1, { 0 } }, { "option_ambiguous", "Ambiguous option: $0", 1, { 0 } }, { "option_missing_arg", "Missing required argument for: $0", 1, { 0 } }, + { "command_unknown", "Unknown command: $0", 1, { 0 } }, + { "command_ambiguous", "Ambiguous command: $0", 1, { 0 } }, + { "not_enough_params", "Not enough parameters given", 0 }, + { "not_connected", "Not connected to IRC server yet", 0 }, + { "not_joined", "Not joined to any channels yet", 0 }, + { "chan_not_found", "Not joined to such channel", 0 }, + { "chan_not_synced", "Channel not fully synchronized yet, try again after a while", 0 }, + { "not_good_idea", "Doing this is not a good idea. Add -YES if you really mean it", 0 }, { NULL, NULL, 0 } }; diff --git a/src/fe-common/core/module-formats.h b/src/fe-common/core/module-formats.h index 9c5b1f15..f8249d33 100644 --- a/src/fe-common/core/module-formats.h +++ b/src/fe-common/core/module-formats.h @@ -66,7 +66,15 @@ enum { IRCTXT_PERL_ERROR, IRCTXT_OPTION_UNKNOWN, IRCTXT_OPTION_AMBIGUOUS, - IRCTXT_OPTION_MISSING_ARG + IRCTXT_OPTION_MISSING_ARG, + IRCTXT_COMMAND_UNKNOWN, + IRCTXT_COMMAND_AMBIGUOUS, + IRCTXT_NOT_ENOUGH_PARAMS, + IRCTXT_NOT_CONNECTED, + IRCTXT_NOT_JOINED, + IRCTXT_CHAN_NOT_FOUND, + IRCTXT_CHAN_NOT_SYNCED, + IRCTXT_NOT_GOOD_IDEA }; extern FORMAT_REC fecommon_core_formats[]; diff --git a/src/fe-common/irc/dcc/fe-dcc.c b/src/fe-common/irc/dcc/fe-dcc.c index ae3cee81..39b26565 100644 --- a/src/fe-common/irc/dcc/fe-dcc.c +++ b/src/fe-common/irc/dcc/fe-dcc.c @@ -416,6 +416,14 @@ static void cmd_dcc_list(const char *data) printformat(NULL, NULL, MSGLEVEL_DCC, IRCTXT_DCC_LIST_FOOTER); } +static void cmd_dcc(const char *data) +{ + if (*data == '\0') { + cmd_dcc_list(data); + signal_stop(); + } +} + static void sig_dcc_send_complete(GList **list, WINDOW_REC *window, const char *word, const char *line, int *want_space) { @@ -459,7 +467,7 @@ void fe_irc_dcc_init(void) command_bind("me", NULL, (SIGNAL_FUNC) cmd_me); command_bind("action", NULL, (SIGNAL_FUNC) cmd_action); command_bind("ctcp", NULL, (SIGNAL_FUNC) cmd_ctcp); - command_bind("dcc ", NULL, (SIGNAL_FUNC) cmd_dcc_list); + command_bind("dcc", NULL, (SIGNAL_FUNC) cmd_dcc); command_bind("dcc list", NULL, (SIGNAL_FUNC) cmd_dcc_list); theme_register(fecommon_irc_dcc_formats); @@ -492,6 +500,6 @@ void fe_irc_dcc_deinit(void) command_unbind("me", (SIGNAL_FUNC) cmd_me); command_unbind("action", (SIGNAL_FUNC) cmd_action); command_unbind("ctcp", (SIGNAL_FUNC) cmd_ctcp); - command_unbind("dcc ", (SIGNAL_FUNC) cmd_dcc_list); + command_unbind("dcc", (SIGNAL_FUNC) cmd_dcc); command_unbind("dcc list", (SIGNAL_FUNC) cmd_dcc_list); } diff --git a/src/fe-common/irc/fe-channels.c b/src/fe-common/irc/fe-channels.c index c17325eb..8eb1ebf9 100644 --- a/src/fe-common/irc/fe-channels.c +++ b/src/fe-common/irc/fe-channels.c @@ -182,12 +182,12 @@ static void cmd_channel_list(void) static void cmd_channel(const char *data, IRC_SERVER_REC *server, WI_ITEM_REC *item) { - if (ischannel(*data)) { + if (*data == '\0') + cmd_channel_list_joined(); + else if (ischannel(*data)) signal_emit("command join", 2, data, server); - return; - } - - command_runsub("channel", data, server, item); + else + command_runsub("channel", data, server, item); } static void cmd_channel_add(const char *data) @@ -260,7 +260,6 @@ void fe_channels_init(void) command_bind("wjoin", NULL, (SIGNAL_FUNC) cmd_wjoin); command_bind("channel", NULL, (SIGNAL_FUNC) cmd_channel); - command_bind("channel ", NULL, (SIGNAL_FUNC) cmd_channel_list_joined); command_bind("channel add", NULL, (SIGNAL_FUNC) cmd_channel_add); command_bind("channel remove", NULL, (SIGNAL_FUNC) cmd_channel_remove); command_bind("channel list", NULL, (SIGNAL_FUNC) cmd_channel_list); @@ -278,7 +277,6 @@ void fe_channels_deinit(void) command_unbind("wjoin", (SIGNAL_FUNC) cmd_wjoin); command_unbind("channel", (SIGNAL_FUNC) cmd_channel); - command_unbind("channel ", (SIGNAL_FUNC) cmd_channel_list_joined); command_unbind("channel add", (SIGNAL_FUNC) cmd_channel_add); command_unbind("channel remove", (SIGNAL_FUNC) cmd_channel_remove); command_unbind("channel list", (SIGNAL_FUNC) cmd_channel_list); diff --git a/src/fe-common/irc/fe-ircnet.c b/src/fe-common/irc/fe-ircnet.c index adc4f03c..9a361bce 100644 --- a/src/fe-common/irc/fe-ircnet.c +++ b/src/fe-common/irc/fe-ircnet.c @@ -28,11 +28,6 @@ #include "irc-server.h" #include "ircnet-setup.h" -static void cmd_ircnet(const char *data, IRC_SERVER_REC *server, WI_ITEM_REC *item) -{ - command_runsub("ircnet", data, server, item); -} - static void cmd_ircnet_list(void) { GString *str; @@ -155,10 +150,17 @@ static void cmd_ircnet_remove(const char *data) } } +static void cmd_ircnet(const char *data, IRC_SERVER_REC *server, WI_ITEM_REC *item) +{ + if (*data == '\0') + cmd_ircnet_list(); + else + command_runsub("ircnet", data, server, item); +} + void fe_ircnet_init(void) { command_bind("ircnet", NULL, (SIGNAL_FUNC) cmd_ircnet); - command_bind("ircnet ", NULL, (SIGNAL_FUNC) cmd_ircnet_list); command_bind("ircnet add", NULL, (SIGNAL_FUNC) cmd_ircnet_add); command_bind("ircnet remove", NULL, (SIGNAL_FUNC) cmd_ircnet_remove); @@ -168,7 +170,6 @@ void fe_ircnet_init(void) void fe_ircnet_deinit(void) { command_unbind("ircnet", (SIGNAL_FUNC) cmd_ircnet); - command_unbind("ircnet ", (SIGNAL_FUNC) cmd_ircnet_list); command_unbind("ircnet add", (SIGNAL_FUNC) cmd_ircnet_add); command_unbind("ircnet remove", (SIGNAL_FUNC) cmd_ircnet_remove); } |