comparison mcabber/src/commands.c @ 967:303408ef5e5d

Configurable command character This patch sets the command character as a configurable compile time option.
author Alexis Hildebrandt
date Fri, 29 Sep 2006 20:28:20 +0200
parents 90ff94f0fbbb
children d3bfa9e9d88c
comparison
equal deleted inserted replaced
966:d9acb7f2a3d1 967:303408ef5e5d
30 #include "hooks.h" 30 #include "hooks.h"
31 #include "hbuf.h" 31 #include "hbuf.h"
32 #include "utils.h" 32 #include "utils.h"
33 #include "settings.h" 33 #include "settings.h"
34 #include "events.h" 34 #include "events.h"
35
36 #define IMSTATUS_AWAY "away"
37 #define IMSTATUS_ONLINE "online"
38 #define IMSTATUS_OFFLINE "offline"
39 #define IMSTATUS_FREE4CHAT "free"
40 #define IMSTATUS_INVISIBLE "invisible"
41 #define IMSTATUS_AVAILABLE "avail"
42 #define IMSTATUS_NOTAVAILABLE "notavail"
43 #define IMSTATUS_DONOTDISTURB "dnd"
35 44
36 // Commands callbacks 45 // Commands callbacks
37 static void do_roster(char *arg); 46 static void do_roster(char *arg);
38 static void do_status(char *arg); 47 static void do_status(char *arg);
39 static void do_status_to(char *arg); 48 static void do_status_to(char *arg);
219 const char *p1, *p2; 228 const char *p1, *p2;
220 char *word; 229 char *word;
221 const gchar *value; 230 const gchar *value;
222 char *newline = line; 231 char *newline = line;
223 232
224 // Ignore leading '/' 233 // Ignore leading COMMAND_CHAR
225 for (p1 = line ; *p1 == '/' ; p1++) 234 for (p1 = line ; *p1 == COMMAND_CHAR ; p1++)
226 ; 235 ;
227 // Locate the end of the word 236 // Locate the end of the word
228 for (p2 = p1 ; *p2 && (*p2 != ' ') ; p2++) 237 for (p2 = p1 ; *p2 && (*p2 != ' ') ; p2++)
229 ; 238 ;
230 // Extract the word 239 // Extract the word
233 // Look for an alias in the list 242 // Look for an alias in the list
234 value = settings_get(SETTINGS_TYPE_ALIAS, (const char*)word); 243 value = settings_get(SETTINGS_TYPE_ALIAS, (const char*)word);
235 if (value) { 244 if (value) {
236 // There is an alias to expand 245 // There is an alias to expand
237 newline = g_new(char, strlen(value)+strlen(p2)+2); 246 newline = g_new(char, strlen(value)+strlen(p2)+2);
238 *newline = '/'; 247 *newline = COMMAND_CHAR;
239 strcpy(newline+1, value); 248 strcpy(newline+1, value);
240 strcat(newline, p2); 249 strcat(newline, p2);
241 } 250 }
242 g_free(word); 251 g_free(word);
243 252
251 { 260 {
252 const char *p1, *p2; 261 const char *p1, *p2;
253 char *com; 262 char *com;
254 GSList *sl_com; 263 GSList *sl_com;
255 264
256 // Ignore leading '/' 265 // Ignore leading COMMAND_CHAR
257 for (p1 = command ; *p1 == '/' ; p1++) 266 for (p1 = command ; *p1 == COMMAND_CHAR ; p1++)
258 ; 267 ;
259 // Locate the end of the command 268 // Locate the end of the command
260 for (p2 = p1 ; *p2 && (*p2 != ' ') ; p2++) 269 for (p2 = p1 ; *p2 && (*p2 != ' ') ; p2++)
261 ; 270 ;
262 // Copy the clean command 271 // Copy the clean command
336 ; 345 ;
337 for (p-- ; p>xpline && (*p == ' ') ; p--) 346 for (p-- ; p>xpline && (*p == ' ') ; p--)
338 *p = 0; 347 *p = 0;
339 348
340 // Command "quit"? 349 // Command "quit"?
341 if ((!strncasecmp(xpline, "/quit", 5)) && (scr_get_multimode() != 2) ) 350 if ((scr_get_multimode() != 2)
351 && (!strncasecmp(xpline, mkcmdstr("quit"), strlen(mkcmdstr("quit")))))
342 if (!xpline[5] || xpline[5] == ' ') 352 if (!xpline[5] || xpline[5] == ' ')
343 return 255; 353 return 255;
344 354
345 // If verbatim multi-line mode, we check if another /msay command is typed 355 // If verbatim multi-line mode, we check if another /msay command is typed
346 if ((scr_get_multimode() == 2) && (strncasecmp(xpline, "/msay ", 6))) { 356 if ((scr_get_multimode() == 2)
357 && (strncasecmp(xpline, mkcmdstr("msay "), strlen(mkcmdstr("msay "))))) {
347 // It isn't an /msay command 358 // It isn't an /msay command
348 scr_append_multiline(xpline); 359 scr_append_multiline(xpline);
349 g_free(xpline); 360 g_free(xpline);
350 return 0; 361 return 0;
351 } 362 }
395 scr_ShowBuddyWindow(); 406 scr_ShowBuddyWindow();
396 } 407 }
397 return 0; 408 return 0;
398 } 409 }
399 410
400 if (*line != '/') { 411 if (*line != COMMAND_CHAR) {
401 // This isn't a command 412 // This isn't a command
402 if (scr_get_multimode()) 413 if (scr_get_multimode())
403 scr_append_multiline(line); 414 scr_append_multiline(line);
404 else 415 else
405 do_say(line); 416 do_say(line);
492 if (!status) { 503 if (!status) {
493 free_arg_lst(paramlst); 504 free_arg_lst(paramlst);
494 return; 505 return;
495 } 506 }
496 507
497 if (!strcasecmp(status, "offline")) st = offline; 508 if (!strcasecmp(status, IMSTATUS_OFFLINE)) st = offline;
498 else if (!strcasecmp(status, "online")) st = available; 509 else if (!strcasecmp(status, IMSTATUS_ONLINE)) st = available;
499 else if (!strcasecmp(status, "avail")) st = available; 510 else if (!strcasecmp(status, IMSTATUS_AVAILABLE)) st = available;
500 else if (!strcasecmp(status, "away")) st = away; 511 else if (!strcasecmp(status, IMSTATUS_AWAY)) st = away;
501 else if (!strcasecmp(status, "invisible")) st = invisible; 512 else if (!strcasecmp(status, IMSTATUS_INVISIBLE)) st = invisible;
502 else if (!strcasecmp(status, "dnd")) st = dontdisturb; 513 else if (!strcasecmp(status, IMSTATUS_DONOTDISTURB)) st = dontdisturb;
503 else if (!strcasecmp(status, "notavail")) st = notavail; 514 else if (!strcasecmp(status, IMSTATUS_NOTAVAILABLE)) st = notavail;
504 else if (!strcasecmp(status, "free")) st = freeforchat; 515 else if (!strcasecmp(status, IMSTATUS_FREE4CHAT)) st = freeforchat;
505 else { 516 else {
506 scr_LogPrint(LPRINT_NORMAL, "Unrecognized status!"); 517 scr_LogPrint(LPRINT_NORMAL, "Unrecognized status!");
507 free_arg_lst(paramlst); 518 free_arg_lst(paramlst);
508 return; 519 return;
509 } 520 }
802 813
803 if (!subcmd || !*subcmd) { 814 if (!subcmd || !*subcmd) {
804 scr_LogPrint(LPRINT_NORMAL, "Missing parameter."); 815 scr_LogPrint(LPRINT_NORMAL, "Missing parameter.");
805 scr_LogPrint(LPRINT_NORMAL, "Please read the manual before using " 816 scr_LogPrint(LPRINT_NORMAL, "Please read the manual before using "
806 "the /msay command."); 817 "the /msay command.");
807 scr_LogPrint(LPRINT_NORMAL, "(Use \"/msay begin\" to enter " 818 scr_LogPrint(LPRINT_NORMAL, "(Use \"%s begin\" to enter "
808 "multi-line mode...)"); 819 "multi-line mode...)", mkcmdstr("msay"));
809 free_arg_lst(paramlst); 820 free_arg_lst(paramlst);
810 return; 821 return;
811 } 822 }
812 823
813 if (!strcasecmp(subcmd, "toggle")) { 824 if (!strcasecmp(subcmd, "toggle")) {
839 verbat = FALSE; 850 verbat = FALSE;
840 } 851 }
841 852
842 scr_LogPrint(LPRINT_NORMAL, "Entered %smulti-line message mode.", 853 scr_LogPrint(LPRINT_NORMAL, "Entered %smulti-line message mode.",
843 verbat ? "VERBATIM " : ""); 854 verbat ? "VERBATIM " : "");
844 scr_LogPrint(LPRINT_NORMAL, "Select a buddy and use \"/msay send\" " 855 scr_LogPrint(LPRINT_NORMAL, "Select a buddy and use \"%s send\" "
845 "when your message is ready."); 856 "when your message is ready.", mkcmdstr("msay"));
846 if (verbat) 857 if (verbat)
847 scr_LogPrint(LPRINT_NORMAL, "Use \"/msay abort\" to abort this mode."); 858 scr_LogPrint(LPRINT_NORMAL, "Use \"%s abort\" to abort this mode.",
859 mkcmdstr("msay"));
848 g_free(subj_utf8); 860 g_free(subj_utf8);
849 return; 861 return;
850 } else if (strcasecmp(subcmd, "send") && strcasecmp(subcmd, "send_to")) { 862 } else if (strcasecmp(subcmd, "send") && strcasecmp(subcmd, "send_to")) {
851 scr_LogPrint(LPRINT_NORMAL, "Unrecognized parameter!"); 863 scr_LogPrint(LPRINT_NORMAL, "Unrecognized parameter!");
852 return; 864 return;
854 866
855 /* send/send_to command */ 867 /* send/send_to command */
856 868
857 if (!scr_get_multimode()) { 869 if (!scr_get_multimode()) {
858 scr_LogPrint(LPRINT_NORMAL, "No message to send. " 870 scr_LogPrint(LPRINT_NORMAL, "No message to send. "
859 "Use \"/msay begin\" first."); 871 "Use \"%s begin\" first.", mkcmdstr("msay"));
860 return; 872 return;
861 } 873 }
862 874
863 scr_set_chatmode(TRUE); 875 scr_set_chatmode(TRUE);
864 876
1048 } 1060 }
1049 1061
1050 free_arg_lst(paramlst); 1062 free_arg_lst(paramlst);
1051 } 1063 }
1052 1064
1053 static void do_clear(char *arg) // Alias for "/buffer clear" 1065 static void do_clear(char *arg) // Alias for "buffer clear"
1054 { 1066 {
1055 do_buffer("clear"); 1067 do_buffer("clear");
1056 } 1068 }
1057 1069
1058 static void do_info(char *arg) 1070 static void do_info(char *arg)
1840 return; 1852 return;
1841 } 1853 }
1842 1854
1843 arg = to_utf8(arg); 1855 arg = to_utf8(arg);
1844 // Set the topic 1856 // Set the topic
1845 msg = g_strdup_printf("/me has set the topic to: %s", arg); 1857 msg = g_strdup_printf("%s has set the topic to: %s", mkcmdstr("me"), arg);
1846 jb_send_msg(buddy_getjid(bud), msg, ROSTER_TYPE_ROOM, arg); 1858 jb_send_msg(buddy_getjid(bud), msg, ROSTER_TYPE_ROOM, arg);
1847 g_free(arg); 1859 g_free(arg);
1848 g_free(msg); 1860 g_free(msg);
1849 } 1861 }
1850 1862