# HG changeset patch # User Mikael Berthe # Date 1194782757 -3600 # Node ID 7daf906fbcdca84aba22d6ab15469ea32eba0853 # Parent 005df14df743b1a1e6757e750b495c13bee037f3 The command /quit can be used in bindings, hooks and sourced files (It used to work in bindings only) diff -r 005df14df743 -r 7daf906fbcdc mcabber/src/commands.c --- a/mcabber/src/commands.c Sun Nov 11 12:22:41 2007 +0100 +++ b/mcabber/src/commands.c Sun Nov 11 13:05:57 2007 +0100 @@ -386,6 +386,12 @@ 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 diff -r 005df14df743 -r 7daf906fbcdc mcabber/src/commands.h --- a/mcabber/src/commands.h Sun Nov 11 12:22:41 2007 +0100 +++ b/mcabber/src/commands.h Sun Nov 11 13:05:57 2007 +0100 @@ -19,6 +19,7 @@ extern char *mcabber_version(void); extern void mcabber_connect(void); +extern void mcabber_set_terminate_ui(void); void room_whois(gpointer bud, char *nick_locale, guint interactive); void room_leave(gpointer bud, char *arg); diff -r 005df14df743 -r 7daf906fbcdc mcabber/src/hooks.c --- a/mcabber/src/hooks.c Sun Nov 11 12:22:41 2007 +0100 +++ b/mcabber/src/hooks.c Sun Nov 11 13:05:57 2007 +0100 @@ -349,7 +349,8 @@ scr_LogPrint(LPRINT_LOGNORM, "%s", buf); cmdline = from_utf8(hook_command); - process_command(cmdline, TRUE); // XXX Note: /quit won't work. + if (process_command(cmdline, TRUE) == 255) + mcabber_set_terminate_ui(); g_free(cmdline); g_free(buf); diff -r 005df14df743 -r 7daf906fbcdc mcabber/src/jab_priv.h --- a/mcabber/src/jab_priv.h Sun Nov 11 12:22:41 2007 +0100 +++ b/mcabber/src/jab_priv.h Sun Nov 11 13:05:57 2007 +0100 @@ -34,7 +34,6 @@ extern enum enum_jstate jstate; extern xmlnode bookmarks, rosternotes; -extern char *mcabber_version(void); const char *entity_version(void); extern time_t iqlast; /* last message/status change time */ diff -r 005df14df743 -r 7daf906fbcdc mcabber/src/main.c --- a/mcabber/src/main.c Sun Nov 11 12:22:41 2007 +0100 +++ b/mcabber/src/main.c Sun Nov 11 13:05:57 2007 +0100 @@ -51,6 +51,8 @@ # define WAIT_ANY -1 #endif +static unsigned int terminate_ui; + static struct termios *backup_termios; char *mcabber_version(void) @@ -336,6 +338,11 @@ #endif /* HAVE_GPGME */ } +void mcabber_set_terminate_ui(void) +{ + terminate_ui = TRUE; +} + int main(int argc, char **argv) { char *configFile = NULL; @@ -472,12 +479,12 @@ scr_LogPrint(LPRINT_DEBUG, "Entering into main loop..."); - for (ret = 0 ; ret != 255 ; ) { + while (!terminate_ui) { scr_DoUpdate(); scr_Getch(&kcode); if (kcode.value != ERR) { - ret = process_key(kcode); + process_key(kcode); } else { scr_CheckAutoAway(FALSE); diff -r 005df14df743 -r 7daf906fbcdc mcabber/src/screen.c --- a/mcabber/src/screen.c Sun Nov 11 12:22:41 2007 +0100 +++ b/mcabber/src/screen.c Sun Nov 11 13:05:57 2007 +0100 @@ -3697,7 +3697,7 @@ // process_key(key) // Handle the pressed key, in the command line (bottom). -int process_key(keycode kcode) +void process_key(keycode kcode) { int key = kcode.value; int display_char = FALSE; @@ -3712,8 +3712,10 @@ break; case MKEY_META: default: - if (bindcommand(kcode) == 255) - return 255; + if (bindcommand(kcode) == 255) { + mcabber_set_terminate_ui(); + return; + } key = ERR; // Do not process any further } @@ -3731,8 +3733,10 @@ readline_do_completion(); break; case 13: // Enter - if (readline_accept_line(FALSE) == 255) - return 255; + if (readline_accept_line(FALSE) == 255) { + mcabber_set_terminate_ui(); + return; + } break; case 3: // Ctrl-C scr_handle_CtrlC(); @@ -3751,7 +3755,7 @@ // Check the line isn't too long if (strlen(inputLine) + 4 > INPUTLINE_LENGTH) - return 0; + return; // Insert char strcpy(tmpLine, ptr_inputline); @@ -3760,8 +3764,10 @@ check_offset(1); } else { // Look for a key binding. - if (!kcode.utf8 && (bindcommand(kcode) == 255)) - return 255; + if (!kcode.utf8 && (bindcommand(kcode) == 255)) { + mcabber_set_terminate_ui(); + return; + } } } @@ -3779,7 +3785,7 @@ if (chatstate) time(&chatstate_timestamp); } - return 0; + return; } #ifdef HAVE_ASPELL_H diff -r 005df14df743 -r 7daf906fbcdc mcabber/src/screen.h --- a/mcabber/src/screen.h Sun Nov 11 12:22:41 2007 +0100 +++ b/mcabber/src/screen.h Sun Nov 11 13:05:57 2007 +0100 @@ -102,7 +102,7 @@ void scr_init_bindings(void); void scr_Getch(keycode *kcode); -int process_key(keycode kcode); +void process_key(keycode kcode); void scr_InitLocaleCharSet(void); void scr_InitCurses(void); diff -r 005df14df743 -r 7daf906fbcdc mcabber/src/settings.c --- a/mcabber/src/settings.c Sun Nov 11 12:22:41 2007 +0100 +++ b/mcabber/src/settings.c Sun Nov 11 13:05:57 2007 +0100 @@ -198,7 +198,8 @@ // Set the leading COMMAND_CHAR to build a command line // and process the command *(--line) = COMMAND_CHAR; - process_command(line, TRUE); + if (process_command(line, TRUE) == 255) + mcabber_set_terminate_ui(); } else { scr_LogPrint(LPRINT_LOGNORM, "Error in configuration file (l. %d): " "this is not an assignment", ln);