about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2014-01-23 23:04:00 +0000
committerJames Booth <boothj5@gmail.com>2014-01-23 23:04:00 +0000
commit66631308a5f09645fa8975a19615b6c1127031a4 (patch)
treec298db35aed17a34b57333697bef4a157a008fc7
parente089ffb15ca3918b456e05c6198fc0cd122d08a2 (diff)
downloadprofani-tty-66631308a5f09645fa8975a19615b6c1127031a4.tar.gz
Implemented basic running of alias commands
-rw-r--r--src/command/command.c28
-rw-r--r--src/command/command.h1
-rw-r--r--src/profanity.c11
-rw-r--r--src/profanity.h2
4 files changed, 35 insertions, 7 deletions
diff --git a/src/command/command.c b/src/command/command.c
index 87161c4f..c933bff4 100644
--- a/src/command/command.c
+++ b/src/command/command.c
@@ -1205,7 +1205,33 @@ cmd_execute(const char * const command, const char * const inp)
             return result;
         }
     } else {
-        return cmd_execute_default(inp);
+        gboolean ran_alias = FALSE;
+        gboolean alias_result = cmd_execute_alias(inp, &ran_alias);
+        if (!ran_alias) {
+            return cmd_execute_default(inp);
+        } else {
+            return alias_result;
+        }
+    }
+}
+
+gboolean
+cmd_execute_alias(const char * const inp, gboolean *ran)
+{
+    if (inp[0] != '/') {
+        ran = FALSE;
+        return TRUE;
+    } else {
+        char *alias = strdup(inp+1);
+        char *value = prefs_get_alias(alias);
+        free(alias);
+        if (value != NULL) {
+            *ran = TRUE;
+            return process_input(value);
+        } else {
+            *ran = FALSE;
+            return TRUE;
+        }
     }
 }
 
diff --git a/src/command/command.h b/src/command/command.h
index f958c0d1..ddf19ff7 100644
--- a/src/command/command.h
+++ b/src/command/command.h
@@ -34,6 +34,7 @@ void cmd_autocomplete(char *input, int *size);
 void cmd_reset_autocomplete(void);
 
 gboolean cmd_execute(const char * const command, const char * const inp);
+gboolean cmd_execute_alias(const char * const inp, gboolean *ran);
 gboolean cmd_execute_default(const char * const inp);
 
 GSList * cmd_get_basic_help(void);
diff --git a/src/profanity.c b/src/profanity.c
index 9c44e0d5..827cd962 100644
--- a/src/profanity.c
+++ b/src/profanity.c
@@ -51,7 +51,6 @@
 #include "ui/ui.h"
 #include "xmpp/xmpp.h"
 
-static gboolean _process_input(char *inp);
 static void _handle_idle_time(void);
 static void _init(const int disable_tls, char *log_level);
 static void _shutdown(void);
@@ -77,11 +76,11 @@ prof_run(const int disable_tls, char *log_level, char *account_name)
     if (account_name != NULL) {
       char *cmd = "/connect";
       snprintf(inp, sizeof(inp), "%s %s", cmd, account_name);
-      _process_input(inp);
+      process_input(inp);
     } else if (prefs_get_string(PREF_CONNECT_ACCOUNT) != NULL) {
       char *cmd = "/connect";
       snprintf(inp, sizeof(inp), "%s %s", cmd, prefs_get_string(PREF_CONNECT_ACCOUNT));
-      _process_input(inp);
+      process_input(inp);
     }
 
     while(cmd_result == TRUE) {
@@ -113,7 +112,7 @@ prof_run(const int disable_tls, char *log_level, char *account_name)
         }
 
         inp[size++] = '\0';
-        cmd_result = _process_input(inp);
+        cmd_result = process_input(inp);
     }
 
     g_timer_destroy(timer);
@@ -172,8 +171,8 @@ prof_handle_activity(void)
  * Take a line of input and process it, return TRUE if profanity is to
  * continue, FALSE otherwise
  */
-static gboolean
-_process_input(char *inp)
+gboolean
+process_input(char *inp)
 {
     log_debug("Input recieved: %s", inp);
     gboolean result = FALSE;
diff --git a/src/profanity.h b/src/profanity.h
index c55e6c47..e4c97353 100644
--- a/src/profanity.h
+++ b/src/profanity.h
@@ -31,4 +31,6 @@ void prof_run(const int disable_tls, char *log_level, char *account_name);
 void prof_handle_idle(void);
 void prof_handle_activity(void);
 
+gboolean process_input(char *inp);
+
 #endif