about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2012-04-26 23:37:54 +0100
committerJames Booth <boothj5@gmail.com>2012-04-26 23:37:54 +0100
commit887278b91bbb88f746e4dda2dff3a5ad78f8483c (patch)
tree57469c7339ed6232634b8a50bd598d4869c6d1a7
parent1b7d9e9e26e63afc660d7f8f8827be637f0655a4 (diff)
parenta41dab3d3c8ba290e2ae5c715844d9432ec9220b (diff)
downloadprofani-tty-887278b91bbb88f746e4dda2dff3a5ad78f8483c.tar.gz
Merge branch 'glib'
Conflicts:
	command.c
-rw-r--r--Makefile4
-rw-r--r--command.c62
-rw-r--r--command.h2
-rw-r--r--main.c1
-rw-r--r--profanity.c5
-rw-r--r--test_util.c1
-rw-r--r--util.c19
-rw-r--r--util.h1
8 files changed, 39 insertions, 56 deletions
diff --git a/Makefile b/Makefile
index 706fe2d2..698939ec 100644
--- a/Makefile
+++ b/Makefile
@@ -1,9 +1,9 @@
 CC = gcc
 WARNS = -Werror -Wall -Wextra -Wno-unused-parameter -Wno-unused-but-set-variable
-LIBS = -lxml2 -lexpat -lssl -lresolv -lncurses -L ~/lib -lstrophe
+LIBS = -lxml2 -lexpat -lssl -lresolv -lncurses -L ~/lib -lstrophe `pkg-config --libs glib-2.0`
 TESTLIB = -L ~/lib -l headunit
 CPPLIB = -lstdc++
-CFLAGS = -I ~/include -O3 $(WARNS) $(LIBS)
+CFLAGS = -I ~/include -O3 $(WARNS) $(LIBS) `pkg-config --cflags glib-2.0`
 OBJS = log.o windows.o title_bar.o status_bar.o input_win.o jabber.o \
        profanity.o util.o command.o history.o contact_list.o main.o
 TESTOBJS = test_history.o history.o test_contact_list.o contact_list.o \
diff --git a/command.c b/command.c
index caa6a11d..17c2dcb0 100644
--- a/command.c
+++ b/command.c
@@ -22,7 +22,9 @@
 
 #include <string.h>
 #include <stdlib.h>
-#include <ncurses.h>
+
+#include <glib.h>
+
 #include "command.h"
 #include "contact_list.h"
 #include "history.h"
@@ -30,21 +32,24 @@
 #include "windows.h"
 #include "util.h"
 
-static int _handle_command(const char * const command, const char * const inp);
-static int _cmd_quit(void);
-static int _cmd_help(void);
-static int _cmd_who(void);
-static int _cmd_ros(void);
-static int _cmd_connect(const char * const inp);
-static int _cmd_msg(const char * const inp);
-static int _cmd_close(const char * const inp);
-static int _cmd_set_beep(const char * const inp);
-static int _cmd_set_flash(const char * const inp);
-static int _cmd_default(const char * const inp);
-
-int process_input(char *inp)
+static gboolean _handle_command(const char * const command, 
+    const char * const inp);
+static gboolean _cmd_quit(void);
+static gboolean _cmd_help(void);
+static gboolean _cmd_who(void);
+static gboolean _cmd_ros(void);
+static gboolean _cmd_connect(const char * const inp);
+static gboolean _cmd_msg(const char * const inp);
+static gboolean _cmd_close(const char * const inp);
+static gboolean _cmd_set_beep(const char * const inp);
+static gboolean _cmd_set_flash(const char * const inp);
+static gboolean _cmd_default(const char * const inp);
+
+gboolean process_input(char *inp)
 {
-    int result = FALSE;
+    gboolean result = FALSE;
+
+    g_strstrip(inp);
 
     if (strlen(inp) > 0)
         history_append(inp);
@@ -52,7 +57,6 @@ int process_input(char *inp)
     if (strlen(inp) == 0) {
         result = TRUE;
     } else if (inp[0] == '/') {
-        inp = trim(inp);
         char inp_cpy[strlen(inp) + 1];
         strcpy(inp_cpy, inp);
         char *command = strtok(inp_cpy, " ");
@@ -68,9 +72,9 @@ int process_input(char *inp)
     return result;
 }
 
-static int _handle_command(const char * const command, const char * const inp)
+static gboolean _handle_command(const char * const command, const char * const inp)
 {
-    int result = FALSE;
+    gboolean result = FALSE;
 
     if (strcmp(command, "/quit") == 0) {
         result = _cmd_quit();
@@ -97,9 +101,9 @@ static int _handle_command(const char * const command, const char * const inp)
     return result;
 }
 
-static int _cmd_connect(const char * const inp)
+static gboolean _cmd_connect(const char * const inp)
 {
-    int result = FALSE;
+    gboolean result = FALSE;
     jabber_status_t conn_status = jabber_connection_status();
 
     if ((conn_status != JABBER_DISCONNECTED) && (conn_status != JABBER_STARTED)) {
@@ -130,19 +134,19 @@ static int _cmd_connect(const char * const inp)
     return result;
 }
 
-static int _cmd_quit(void)
+static gboolean _cmd_quit(void)
 {
     return FALSE;
 }
 
-static int _cmd_help(void)
+static gboolean _cmd_help(void)
 {
     cons_help();
 
     return TRUE;
 }
 
-static int _cmd_ros(void)
+static gboolean _cmd_ros(void)
 {
     jabber_status_t conn_status = jabber_connection_status();
 
@@ -154,7 +158,7 @@ static int _cmd_ros(void)
     return TRUE;
 }
 
-static int _cmd_who(void)
+static gboolean _cmd_who(void)
 {
     jabber_status_t conn_status = jabber_connection_status();
 
@@ -168,7 +172,7 @@ static int _cmd_who(void)
     return TRUE;
 }
 
-static int _cmd_msg(const char * const inp)
+static gboolean _cmd_msg(const char * const inp)
 {
     char *usr = NULL;
     char *msg = NULL;
@@ -202,7 +206,7 @@ static int _cmd_msg(const char * const inp)
     return TRUE;
 }
 
-static int _cmd_close(const char * const inp)
+static gboolean _cmd_close(const char * const inp)
 {
     if (!win_close_win())
         cons_bad_command(inp);
@@ -210,7 +214,7 @@ static int _cmd_close(const char * const inp)
     return TRUE;
 }
 
-static int _cmd_set_beep(const char * const inp)
+static gboolean _cmd_set_beep(const char * const inp)
 {
     if (strcmp(inp, "/beep on") == 0) {
         cons_show("Sound enabled.");
@@ -225,7 +229,7 @@ static int _cmd_set_beep(const char * const inp)
     return TRUE;
 }
 
-static int _cmd_set_flash(const char * const inp)
+static gboolean _cmd_set_flash(const char * const inp)
 {
     if (strcmp(inp, "/flash on") == 0) {
         cons_show("Screen flash enabled.");
@@ -240,7 +244,7 @@ static int _cmd_set_flash(const char * const inp)
     return TRUE;
 }
 
-static int _cmd_default(const char * const inp)
+static gboolean _cmd_default(const char * const inp)
 {
     if (win_in_chat()) {
         char *recipient = win_get_recipient();
diff --git a/command.h b/command.h
index 7efc4acf..d0d57022 100644
--- a/command.h
+++ b/command.h
@@ -24,6 +24,6 @@
 #define COMMAND_H
 
 void cmd_init(void);
-int process_input(char *inp);
+gboolean process_input(char *inp);
 
 #endif
diff --git a/main.c b/main.c
index 392b9ef6..520fb4bb 100644
--- a/main.c
+++ b/main.c
@@ -47,7 +47,6 @@ int main(int argc, char **argv)
 
     profanity_init(disable_tls);
     profanity_run();
-    //profanity_shutdown();
 
     return 0;
 }
diff --git a/profanity.c b/profanity.c
index 2e2e27fa..de26f8b8 100644
--- a/profanity.c
+++ b/profanity.c
@@ -22,8 +22,7 @@
 
 #include <string.h>
 #include <stdlib.h>
-
-#include <ncurses.h>
+#include <glib.h>
 
 #include "profanity.h"
 #include "log.h"
@@ -36,7 +35,7 @@ static void _profanity_shutdown(void);
 
 void profanity_run(void)
 {
-    int cmd_result = TRUE;
+    gboolean cmd_result = TRUE;
 
     inp_non_block();
     while(cmd_result == TRUE) {
diff --git a/test_util.c b/test_util.c
index ae936d9a..ffe12506 100644
--- a/test_util.c
+++ b/test_util.c
@@ -1,4 +1,5 @@
 #include <stdlib.h>
+#include <string.h>
 #include <head-unit.h>
 #include "util.h"
 
diff --git a/util.c b/util.c
index bfe21263..58f4fbf1 100644
--- a/util.c
+++ b/util.c
@@ -36,25 +36,6 @@ void get_time(char *thetime)
     strftime(thetime, 80, "%H:%M", timeinfo);
 }
 
-char *trim(char *str)
-{
-    char *end;
-
-    while (isspace(*str)) 
-        str++;
-
-    if (*str == 0)
-      return str;
-
-    end = str + strlen(str) - 1;
-    while (end > str && isspace(*end)) 
-        end--;
-
-    *(end+1) = 0;
-
-    return str;
-}
-
 char * str_replace (const char *string, const char *substr, 
     const char *replacement) {
     char *tok = NULL;
diff --git a/util.h b/util.h
index 0982f816..4326fbb4 100644
--- a/util.h
+++ b/util.h
@@ -24,7 +24,6 @@
 #define UTIL_H
 
 void get_time(char *thetime);
-char * trim(char *str);
 char * str_replace(const char *string, const char *substr, 
     const char *replacement);