changeset 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 d9acb7f2a3d1
children d3bfa9e9d88c
files mcabber/src/commands.c mcabber/src/hooks.c mcabber/src/screen.c mcabber/src/settings.c mcabber/src/settings.h
diffstat 5 files changed, 55 insertions(+), 36 deletions(-) [+]
line wrap: on
line diff
--- a/mcabber/src/commands.c	Thu Sep 28 21:36:58 2006 +0200
+++ b/mcabber/src/commands.c	Fri Sep 29 20:28:20 2006 +0200
@@ -33,6 +33,15 @@
 #include "settings.h"
 #include "events.h"
 
+#define IMSTATUS_AWAY           "away"
+#define IMSTATUS_ONLINE         "online"
+#define IMSTATUS_OFFLINE        "offline"
+#define IMSTATUS_FREE4CHAT      "free"
+#define IMSTATUS_INVISIBLE      "invisible"
+#define IMSTATUS_AVAILABLE      "avail"
+#define IMSTATUS_NOTAVAILABLE   "notavail"
+#define IMSTATUS_DONOTDISTURB   "dnd"
+
 // Commands callbacks
 static void do_roster(char *arg);
 static void do_status(char *arg);
@@ -221,8 +230,8 @@
   const gchar *value;
   char *newline = line;
 
-  // Ignore leading '/'
-  for (p1 = line ; *p1 == '/' ; p1++)
+  // Ignore leading COMMAND_CHAR
+  for (p1 = line ; *p1 == COMMAND_CHAR ; p1++)
     ;
   // Locate the end of the word
   for (p2 = p1 ; *p2 && (*p2 != ' ') ; p2++)
@@ -235,7 +244,7 @@
   if (value) {
     // There is an alias to expand
     newline = g_new(char, strlen(value)+strlen(p2)+2);
-    *newline = '/';
+    *newline = COMMAND_CHAR;
     strcpy(newline+1, value);
     strcat(newline, p2);
   }
@@ -253,8 +262,8 @@
   char *com;
   GSList *sl_com;
 
-  // Ignore leading '/'
-  for (p1 = command ; *p1 == '/' ; p1++)
+  // Ignore leading COMMAND_CHAR
+  for (p1 = command ; *p1 == COMMAND_CHAR ; p1++)
     ;
   // Locate the end of the command
   for (p2 = p1 ; *p2 && (*p2 != ' ') ; p2++)
@@ -338,12 +347,14 @@
     *p = 0;
 
   // Command "quit"?
-  if ((!strncasecmp(xpline, "/quit", 5)) && (scr_get_multimode() != 2) )
+  if ((scr_get_multimode() != 2)
+      && (!strncasecmp(xpline, mkcmdstr("quit"), strlen(mkcmdstr("quit")))))
     if (!xpline[5] || xpline[5] == ' ')
       return 255;
 
   // If verbatim multi-line mode, we check if another /msay command is typed
-  if ((scr_get_multimode() == 2) && (strncasecmp(xpline, "/msay ", 6))) {
+  if ((scr_get_multimode() == 2)
+      && (strncasecmp(xpline, mkcmdstr("msay "), strlen(mkcmdstr("msay "))))) {
     // It isn't an /msay command
     scr_append_multiline(xpline);
     g_free(xpline);
@@ -397,7 +408,7 @@
     return 0;
   }
 
-  if (*line != '/') {
+  if (*line != COMMAND_CHAR) {
     // This isn't a command
     if (scr_get_multimode())
       scr_append_multiline(line);
@@ -494,14 +505,14 @@
     return;
   }
 
-  if      (!strcasecmp(status, "offline"))   st = offline;
-  else if (!strcasecmp(status, "online"))    st = available;
-  else if (!strcasecmp(status, "avail"))     st = available;
-  else if (!strcasecmp(status, "away"))      st = away;
-  else if (!strcasecmp(status, "invisible")) st = invisible;
-  else if (!strcasecmp(status, "dnd"))       st = dontdisturb;
-  else if (!strcasecmp(status, "notavail"))  st = notavail;
-  else if (!strcasecmp(status, "free"))      st = freeforchat;
+  if      (!strcasecmp(status, IMSTATUS_OFFLINE))       st = offline;
+  else if (!strcasecmp(status, IMSTATUS_ONLINE))        st = available;
+  else if (!strcasecmp(status, IMSTATUS_AVAILABLE))     st = available;
+  else if (!strcasecmp(status, IMSTATUS_AWAY))          st = away;
+  else if (!strcasecmp(status, IMSTATUS_INVISIBLE))     st = invisible;
+  else if (!strcasecmp(status, IMSTATUS_DONOTDISTURB))  st = dontdisturb;
+  else if (!strcasecmp(status, IMSTATUS_NOTAVAILABLE))  st = notavail;
+  else if (!strcasecmp(status, IMSTATUS_FREE4CHAT))     st = freeforchat;
   else {
     scr_LogPrint(LPRINT_NORMAL, "Unrecognized status!");
     free_arg_lst(paramlst);
@@ -804,8 +815,8 @@
     scr_LogPrint(LPRINT_NORMAL, "Missing parameter.");
     scr_LogPrint(LPRINT_NORMAL, "Please read the manual before using "
                  "the /msay command.");
-    scr_LogPrint(LPRINT_NORMAL, "(Use \"/msay begin\" to enter "
-                 "multi-line mode...)");
+    scr_LogPrint(LPRINT_NORMAL, "(Use \"%s begin\" to enter "
+                 "multi-line mode...)", mkcmdstr("msay"));
     free_arg_lst(paramlst);
     return;
   }
@@ -841,10 +852,11 @@
 
     scr_LogPrint(LPRINT_NORMAL, "Entered %smulti-line message mode.",
                  verbat ? "VERBATIM " : "");
-    scr_LogPrint(LPRINT_NORMAL, "Select a buddy and use \"/msay send\" "
-                 "when your message is ready.");
+    scr_LogPrint(LPRINT_NORMAL, "Select a buddy and use \"%s send\" "
+                 "when your message is ready.", mkcmdstr("msay"));
     if (verbat)
-      scr_LogPrint(LPRINT_NORMAL, "Use \"/msay abort\" to abort this mode.");
+      scr_LogPrint(LPRINT_NORMAL, "Use \"%s abort\" to abort this mode.",
+                   mkcmdstr("msay"));
     g_free(subj_utf8);
     return;
   } else if (strcasecmp(subcmd, "send") && strcasecmp(subcmd, "send_to")) {
@@ -856,7 +868,7 @@
 
   if (!scr_get_multimode()) {
     scr_LogPrint(LPRINT_NORMAL, "No message to send.  "
-                 "Use \"/msay begin\" first.");
+                 "Use \"%s begin\" first.", mkcmdstr("msay"));
     return;
   }
 
@@ -1050,7 +1062,7 @@
   free_arg_lst(paramlst);
 }
 
-static void do_clear(char *arg)    // Alias for "/buffer clear"
+static void do_clear(char *arg)    // Alias for "buffer clear"
 {
   do_buffer("clear");
 }
@@ -1842,7 +1854,7 @@
 
   arg = to_utf8(arg);
   // Set the topic
-  msg = g_strdup_printf("/me has set the topic to: %s", arg);
+  msg = g_strdup_printf("%s has set the topic to: %s", mkcmdstr("me"), arg);
   jb_send_msg(buddy_getjid(bud), msg, ROSTER_TYPE_ROOM, arg);
   g_free(arg);
   g_free(msg);
--- a/mcabber/src/hooks.c	Thu Sep 28 21:36:58 2006 +0200
+++ b/mcabber/src/hooks.c	Fri Sep 29 20:28:20 2006 +0200
@@ -57,10 +57,10 @@
       bmsg = g_strdup_printf("<%s> %s", resname, msg);
     }
     wmsg = bmsg;
-    if (!strncmp(msg, "/me ", 4))
+    if (!strncmp(msg, mkcmdstr("me "), strlen(mkcmdstr("me "))))
       wmsg = mmsg = g_strdup_printf("*%s %s", resname, msg+4);
   } else {
-    if (!strncmp(msg, "/me ", 4))
+    if (!strncmp(msg, mkcmdstr("me "), strlen(mkcmdstr("me "))))
       wmsg = mmsg = g_strdup_printf("*%s %s", jid, msg+4);
     else
       wmsg = (char*) msg;
@@ -92,7 +92,7 @@
         wmsg = bmsg = g_strdup(msg);
       } else {
         wmsg = bmsg = g_strdup_printf("PRIV#<%s> %s", resname, msg);
-        if (!strncmp(msg, "/me ", 4))
+        if (!strncmp(msg, mkcmdstr("me "), strlen(mkcmdstr("me "))))
           wmsg = mmsg = g_strdup_printf("PRIV#*%s %s", resname, msg+4);
       }
     } else {
@@ -174,7 +174,7 @@
     wmsg = bmsg = g_strdup_printf("PRIV#<%s> %s", nick, msg);
   } else {
     wmsg = (char*)msg;
-    if (!strncmp(msg, "/me ", 4)) {
+    if (!strncmp(msg, mkcmdstr("me "), strlen(mkcmdstr("me ")))) {
       const char *myid = settings_opt_get("username");
       if (myid)
         wmsg = mmsg = g_strdup_printf("*%s %s", settings_opt_get("username"),
--- a/mcabber/src/screen.c	Thu Sep 28 21:36:58 2006 +0200
+++ b/mcabber/src/screen.c	Fri Sep 29 20:28:20 2006 +0200
@@ -2064,7 +2064,7 @@
   int quote = FALSE;
 
   // Not a command?
-  if ((ptr_inputline == inputLine) || (inputLine[0] != '/')) {
+  if ((ptr_inputline == inputLine) || (inputLine[0] != COMMAND_CHAR)) {
     if (!current_buddy) return -2;
     if (buddy_gettype(BUDDATA(current_buddy)) == ROSTER_TYPE_ROOM) {
       *p_row = inputLine;
@@ -2253,7 +2253,7 @@
 {
   if (!Curses) return;
   // Leave multi-line mode
-  process_command("/msay abort");
+  process_command(mkcmdstr("msay abort"));
   // Same as Ctrl-g, now
   scr_cancel_current_completion();
   scr_end_current_completion();
@@ -2444,7 +2444,7 @@
   if (boundcmd) {
     gchar *cmd, *boundcmd_locale;
     boundcmd_locale = from_utf8(boundcmd);
-    cmd = g_strdup_printf("/%s", boundcmd_locale);
+    cmd = g_strdup_printf(mkcmdstr("%s"), boundcmd_locale);
     scr_CheckAutoAway(TRUE);
     if (process_command(cmd))
       return 255; // Quit
--- a/mcabber/src/settings.c	Thu Sep 28 21:36:58 2006 +0200
+++ b/mcabber/src/settings.c	Fri Sep 29 20:28:20 2006 +0200
@@ -136,16 +136,18 @@
 
     if ((strchr(line, '=') != NULL)) {
       // Only accept the set, alias and bind commands
-      if (strncmp(line, "set ", 4) &&
-          strncmp(line, "bind ", 5) &&
-          strncmp(line, "alias ", 6)) {
+      if (strncmp(line, "set ", strlen("set ")) &&
+          strncmp(line, "bind ", strlen("bind ")) &&
+          strncmp(line, "alias ", strlen("alias "))) {
         scr_LogPrint(LPRINT_LOGNORM,
                      "Error in configuration file (l. %d): bad command", ln);
         err++;
         continue;
       }
-      *(--line) = '/';        // Set the leading '/' to build a command line
-      process_command(line);  // Process the command
+      // Set the leading COMMAND_CHAR to build a command line
+      // and process the command
+      *(--line) = COMMAND_CHAR;
+      process_command(line);
     } else {
       scr_LogPrint(LPRINT_LOGNORM,
                    "Error in configuration file (l. %d): no assignment", ln);
--- a/mcabber/src/settings.h	Thu Sep 28 21:36:58 2006 +0200
+++ b/mcabber/src/settings.h	Fri Sep 29 20:28:20 2006 +0200
@@ -15,9 +15,14 @@
 #define SETTINGS_TYPE_ALIAS     2
 #define SETTINGS_TYPE_BINDING   3
 
+#define COMMAND_CHAR    '/'
+#define COMMAND_CHARSTR "/"
+
 #define settings_opt_get(k)     settings_get(SETTINGS_TYPE_OPTION, k)
 #define settings_opt_get_int(k) settings_get_int(SETTINGS_TYPE_OPTION, k)
 
+#define mkcmdstr(cmd) COMMAND_CHARSTR cmd
+
 int     cfg_read_file(char *filename);
 guint   parse_assigment(gchar *assignment,
                         const gchar **pkey, const gchar **pval);