--- a/mcabber/mcabber/commands.c Fri Oct 17 22:15:46 2014 +0200
+++ b/mcabber/mcabber/commands.c Fri Oct 17 22:31:03 2014 +0200
@@ -55,9 +55,6 @@
# define IMSTATUS_INVISIBLE "invisible"
#endif
-// Return value container for the following functions
-static int retval_for_cmds;
-
// Commands callbacks
static void do_roster(char *arg);
static void do_status(char *arg);
@@ -78,6 +75,7 @@
static void do_bind(char *arg);
static void do_connect(char *arg);
static void do_disconnect(char *arg);
+static void do_quit(char *arg);
static void do_rawxml(char *arg);
static void do_room(char *arg);
static void do_authorization(char *arg);
@@ -218,7 +216,7 @@
cmd_add("otrpolicy", "Manage OTR policies", COMPL_JID, COMPL_OTRPOLICY,
&do_otrpolicy, NULL);
cmd_add("pgp", "Manage PGP settings", COMPL_PGP, COMPL_JID, &do_pgp, NULL);
- cmd_add("quit", "Exit the software", 0, 0, NULL, NULL);
+ cmd_add("quit", "Exit the software", 0, 0, &do_quit, NULL);
cmd_add("rawxml", "Send a raw XML string", 0, 0, &do_rawxml, NULL);
cmd_add("rename", "Rename the current buddy", 0, 0, &do_rename, NULL);
cmd_add("request", "Send a Jabber IQ request", COMPL_REQUEST, COMPL_JID,
@@ -464,15 +462,14 @@
// Process a command line.
// If iscmd is TRUE, process the command even if verbatim mmode is set;
// it is intended to be used for key bindings.
-// Return 255 if this is the /quit command, and 0 for the other commands.
-int process_command(const char *line, guint iscmd)
+void process_command(const char *line, guint iscmd)
{
char *p;
char *xpline;
cmd *curcmd;
if (!line)
- return 0;
+ return;
// We do alias expansion here
if (iscmd || scr_get_multimode() != 2)
@@ -490,28 +487,13 @@
for (p-- ; p>xpline && (*p == ' ') ; p--)
*p = 0;
- // Command "quit"?
- if ((iscmd || scr_get_multimode() != 2)
- && (!strncasecmp(xpline, mkcmdstr("quit"), strlen(mkcmdstr("quit"))))) {
- if (!xpline[5] || xpline[5] == ' ') {
- g_free(xpline);
- return 255;
- }
- } else if (iscmd && !strncasecmp(xpline, "quit", 4) &&
- (!xpline[4] || xpline[4] == ' ')) {
- // If iscmd is true we can have the command without the command prefix
- // character (usually '/').
- g_free(xpline);
- return 255;
- }
-
// If verbatim multi-line mode, we check if another /msay command is typed
if (!iscmd && scr_get_multimode() == 2
&& (strncasecmp(xpline, mkcmdstr("msay "), strlen(mkcmdstr("msay "))))) {
// It isn't an /msay command
scr_append_multiline(xpline);
g_free(xpline);
- return 0;
+ return;
}
// Commands handling
@@ -521,13 +503,13 @@
scr_LogPrint(LPRINT_NORMAL, "Unrecognized command. "
"Please see the manual for a list of known commands.");
g_free(xpline);
- return 0;
+ return;
}
if (!curcmd->func) {
scr_LogPrint(LPRINT_NORMAL,
"This functionality is not yet implemented, sorry.");
g_free(xpline);
- return 0;
+ return;
}
// Lets go to the command parameters
for (p = xpline+1; *p && (*p != ' ') ; p++)
@@ -536,7 +518,6 @@
while (*p && (*p == ' '))
p++;
// Call command-specific function
- retval_for_cmds = 0;
#ifdef MODULES_ENABLE
if (curcmd->userdata)
(*(void (*)(char *p, gpointer u))curcmd->func)(p, curcmd->userdata);
@@ -546,20 +527,18 @@
(*curcmd->func)(p);
#endif
g_free(xpline);
- return retval_for_cmds;
}
// process_line(line)
// Process a command/message line.
// If this isn't a command, this is a message and it is sent to the
// currently selected buddy.
-// Return 255 if the line is the /quit command, or 0.
-int process_line(const char *line)
+void process_line(const char *line)
{
if (!*line) { // User only pressed enter
if (scr_get_multimode()) {
scr_append_multiline("");
- return 0;
+ return;
}
if (current_buddy) {
if (buddy_gettype(BUDDATA(current_buddy)) & ROSTER_TYPE_GROUP)
@@ -570,7 +549,7 @@
scr_show_buddy_window();
}
}
- return 0;
+ return;
}
if (*line != COMMAND_CHAR) {
@@ -579,11 +558,11 @@
scr_append_multiline(line);
else
say_cmd((char*)line, 0);
- return 0;
+ return;
}
/* It is _probably_ a command -- except for verbatim multi-line mode */
- return process_command(line, FALSE);
+ process_command(line, FALSE);
}
// Helper routine for buffer item_{lock,unlock,toggle_lock}
@@ -2483,6 +2462,11 @@
g_free(k_code);
}
+static void do_quit(char *arg)
+{
+ mcabber_set_terminate_ui();
+}
+
static void do_rawxml(char *arg)
{
char **paramlst;
@@ -4074,9 +4058,9 @@
} else if (!strcasecmp(arg, "send_multiline")) {
readline_send_multiline();
} else if (!strcasecmp(arg, "iline_accept")) {
- retval_for_cmds = readline_accept_line(FALSE);
+ readline_accept_line(FALSE);
} else if (!strcasecmp(arg, "iline_accept_down_hist")) {
- retval_for_cmds = readline_accept_line(TRUE);
+ readline_accept_line(TRUE);
} else if (!strcasecmp(arg, "compl_cancel")) {
readline_cancel_completion();
} else if (!strcasecmp(arg, "compl_do_fwd")) {
--- a/mcabber/mcabber/commands.h Fri Oct 17 22:15:46 2014 +0200
+++ b/mcabber/mcabber/commands.h Fri Oct 17 22:31:03 2014 +0200
@@ -16,8 +16,8 @@
void cmd_init(void);
cmd *cmd_get(const char *command);
-int process_line(const char *line);
-int process_command(const char *line, guint iscmd);
+void process_line(const char *line);
+void process_command(const char *line, guint iscmd);
char *expandalias(const char *line);
#ifdef MODULES_ENABLE
gpointer cmd_del(gpointer id);
--- a/mcabber/mcabber/fifo_internal.c Fri Oct 17 22:15:46 2014 +0200
+++ b/mcabber/mcabber/fifo_internal.c Fri Oct 17 22:31:03 2014 +0200
@@ -72,8 +72,7 @@
scr_LogPrint(logflag, "%s FIFO command: %s",
(fifo_ignore ? "Ignoring" : "Executing"), buf);
if (!fifo_ignore) {
- if (process_command(buf, TRUE) == 255)
- mcabber_set_terminate_ui();
+ process_command(buf, TRUE);
}
g_free(buf);
--- a/mcabber/mcabber/hooks.c Fri Oct 17 22:15:46 2014 +0200
+++ b/mcabber/mcabber/hooks.c Fri Oct 17 22:31:03 2014 +0200
@@ -634,8 +634,7 @@
scr_LogPrint(LPRINT_LOGNORM, "Running hook-post-connect...");
cmdline = from_utf8(hook_command);
- if (process_command(cmdline, TRUE) == 255)
- mcabber_set_terminate_ui();
+ process_command(cmdline, TRUE);
g_free(cmdline);
}
@@ -661,8 +660,7 @@
scr_LogPrint(LPRINT_LOGNORM, "Running hook-pre-disconnect...");
cmdline = from_utf8(hook_command);
- if (process_command(cmdline, TRUE) == 255)
- mcabber_set_terminate_ui();
+ process_command(cmdline, TRUE);
g_free(cmdline);
}
--- a/mcabber/mcabber/screen.c Fri Oct 17 22:15:46 2014 +0200
+++ b/mcabber/mcabber/screen.c Fri Oct 17 22:31:03 2014 +0200
@@ -3680,12 +3680,11 @@
// readline_accept_line(down_history)
// Validate current command line.
// If down_history is true, load the next history line.
-int readline_accept_line(int down_history)
+void readline_accept_line(int down_history)
{
scr_check_auto_away(TRUE);
last_activity_buddy = current_buddy;
- if (process_line(inputLine))
- return 255;
+ process_line(inputLine);
// Add line to history
scr_cmdhisto_addline(inputLine);
// Reset the line
@@ -3703,7 +3702,6 @@
// Reset history line pointer
cmdhisto_cur = NULL;
}
- return 0;
}
// readline_clear_history()
@@ -4335,7 +4333,7 @@
doupdate();
}
-static int bindcommand(keycode kcode)
+static void bindcommand(keycode kcode)
{
gchar asciikey[16], asciicode[16];
const gchar *boundcmd;
@@ -4359,10 +4357,9 @@
if (boundcmd) {
gchar *cmdline = from_utf8(boundcmd);
scr_check_auto_away(TRUE);
- if (process_command(cmdline, TRUE))
- return 255; // Quit
+ process_command(cmdline, TRUE);
g_free(cmdline);
- return 0;
+ return;
}
scr_LogPrint(LPRINT_NORMAL, "Unknown key=%s", asciikey);
@@ -4371,7 +4368,6 @@
scr_LogPrint(LPRINT_NORMAL,
"WARNING: Compiled without full UTF-8 support!");
#endif
- return -1;
}
// scr_process_key(key)
@@ -4392,10 +4388,7 @@
break;
case MKEY_META:
default:
- if (bindcommand(kcode) == 255) {
- mcabber_set_terminate_ui();
- return;
- }
+ bindcommand(kcode);
key = ERR; // Do not process any further
}
@@ -4417,10 +4410,7 @@
break;
case 13: // Enter
case 343: // Enter on Maemo
- if (readline_accept_line(FALSE) == 255) {
- mcabber_set_terminate_ui();
- return;
- }
+ readline_accept_line(FALSE);
break;
case 3: // Ctrl-C
scr_handle_CtrlC();
@@ -4467,10 +4457,8 @@
check_offset(1);
} else {
// Look for a key binding.
- if (!kcode.utf8 && (bindcommand(kcode) == 255)) {
- mcabber_set_terminate_ui();
- return;
- }
+ if (!kcode.utf8)
+ bindcommand(kcode);
}
}
--- a/mcabber/mcabber/screen.h Fri Oct 17 22:15:46 2014 +0200
+++ b/mcabber/mcabber/screen.h Fri Oct 17 22:31:03 2014 +0200
@@ -179,7 +179,7 @@
void readline_capitalize_word(void);
void readline_backward_char(void);
void readline_forward_char(void);
-int readline_accept_line(int down_history);
+void readline_accept_line(int down_history);
void readline_clear_history(void);
void readline_cancel_completion(void);
void readline_do_completion(gboolean fwd);
--- a/mcabber/mcabber/settings.c Fri Oct 17 22:15:46 2014 +0200
+++ b/mcabber/mcabber/settings.c Fri Oct 17 22:31:03 2014 +0200
@@ -203,8 +203,7 @@
// Set the leading COMMAND_CHAR to build a command line
// and process the command
*(--line) = COMMAND_CHAR;
- if (process_command(line, TRUE) == 255)
- mcabber_set_terminate_ui();
+ process_command(line, TRUE);
}
g_free(buf);
fclose(fp);