about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--Makefile.am8
-rw-r--r--src/chat_log.c2
-rw-r--r--src/common.c72
-rw-r--r--src/common.h4
-rw-r--r--src/contact_list.c2
-rw-r--r--src/input_win.c2
-rw-r--r--src/jabber.c2
-rw-r--r--src/profanity.c1
-rw-r--r--src/status_bar.c2
-rw-r--r--src/util.c95
-rw-r--r--src/util.h31
-rw-r--r--src/windows.c2
-rw-r--r--tests/test_common.c (renamed from tests/test_util.c)6
-rw-r--r--tests/testsuite.c2
-rw-r--r--tests/testsuite.h2
15 files changed, 91 insertions, 142 deletions
diff --git a/Makefile.am b/Makefile.am
index 80ea76ea..d4a8da4d 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,18 +1,18 @@
 bin_PROGRAMS = profanity
 profanity_SOURCES = src/command.c src/contact.c src/history.c src/jabber.h \
-	src/preferences.c src/prof_autocomplete.c src/status_bar.c src/util.h \
+	src/preferences.c src/prof_autocomplete.c src/status_bar.c \
 	src/command.h src/contact.h src/history.h src/log.c src/preferences.h \
 	src/prof_autocomplete.h src/title_bar.c src/windows.c src/common.c \
 	src/contact_list.c src/input_win.c src/log.h src/profanity.c \
 	src/prof_history.c src/ui.h src/common.h src/ contact_list.h src/jabber.c \
-	src/main.c src/profanity.h src/prof_history.h src/util.c src/chat_log.c \
+	src/main.c src/profanity.h src/prof_history.h src/chat_log.c \
 	src/chat_log.h src/tinyurl.c src/tinyurl.h
 
 TESTS = tests/testsuite
 check_PROGRAMS = tests/testsuite
 tests_testsuite_SOURCES = tests/test_contact_list.c src/contact_list.c src/contact.c \
-	tests/test_util.c tests/test_prof_history.c src/prof_history.c src/util.c \
-	tests/test_prof_autocomplete.c src/prof_autocomplete.c src/common.c tests/testsuite.c
+	tests/test_common.c tests/test_prof_history.c src/prof_history.c src/common.c \
+	tests/test_prof_autocomplete.c src/prof_autocomplete.c tests/testsuite.c
 tests_testsuite_LDADD = -lheadunit -lstdc++
 
 man_MANS = docs/profanity.1
diff --git a/src/chat_log.c b/src/chat_log.c
index 955e49ad..1ef1a079 100644
--- a/src/chat_log.c
+++ b/src/chat_log.c
@@ -27,7 +27,7 @@
 
 #include "chat_log.h"
 #include "common.h"
-#include "util.h"
+#include "common.h"
 #include "log.h"
 
 static GHashTable *logs;
diff --git a/src/common.c b/src/common.c
index a7e6d8e0..064e032c 100644
--- a/src/common.c
+++ b/src/common.c
@@ -25,6 +25,9 @@
 #include <stdlib.h>
 #include <errno.h>
 #include <stdio.h>
+#include <time.h>
+#include <string.h>
+#include <ctype.h>
 
 #include <glib.h>
 
@@ -57,3 +60,72 @@ create_dir(char *name)
         if (errno == ENOENT)
             e = mkdir(name, S_IRWXU);
 }
+
+void
+get_time(char *thetime)
+{
+    time_t rawtime;
+    struct tm *timeinfo;
+
+    time(&rawtime);
+    timeinfo = localtime(&rawtime);
+
+    strftime(thetime, 80, "%H:%M", timeinfo);
+}
+
+char *
+str_replace(const char *string, const char *substr, 
+    const char *replacement) 
+{
+    char *tok = NULL;
+    char *newstr = NULL;
+    char *oldstr = NULL;
+    char *head = NULL;
+ 
+    if (string == NULL)
+        return NULL;
+
+    if ( substr == NULL || 
+         replacement == NULL || 
+         (strcmp(substr, "") == 0)) 
+        return strdup (string);
+
+    newstr = strdup (string);
+    head = newstr;
+
+    while ( (tok = strstr ( head, substr ))) {
+        oldstr = newstr;
+        newstr = malloc ( strlen ( oldstr ) - strlen ( substr ) + 
+            strlen ( replacement ) + 1 );
+        
+        if ( newstr == NULL ) { 
+            free (oldstr);
+            return NULL;
+        }
+        
+        memcpy ( newstr, oldstr, tok - oldstr );
+        memcpy ( newstr + (tok - oldstr), replacement, strlen ( replacement ) );
+        memcpy ( newstr + (tok - oldstr) + strlen( replacement ), 
+            tok + strlen ( substr ), 
+            strlen ( oldstr ) - strlen ( substr ) - ( tok - oldstr ) );
+        memset ( newstr + strlen ( oldstr ) - strlen ( substr ) + 
+            strlen ( replacement ) , 0, 1 );
+        
+        head = newstr + (tok - oldstr) + strlen( replacement );
+        free (oldstr);
+    }
+  
+    return newstr;
+}
+
+int
+str_contains(char str[], int size, char ch)
+{
+    int i;
+    for (i = 0; i < size; i++) {
+        if (str[i] == ch)
+            return 1;
+    }
+
+    return 0;
+}
diff --git a/src/common.h b/src/common.h
index ae99b165..1061f27f 100644
--- a/src/common.h
+++ b/src/common.h
@@ -54,5 +54,9 @@ typedef enum {
 void p_slist_free_full(GSList *items, GDestroyNotify free_func);
 void create_config_directory(void);
 void create_dir(char *name);
+void get_time(char *thetime);
+char * str_replace(const char *string, const char *substr, 
+    const char *replacement);
+int str_contains(char str[], int size, char ch);
 
 #endif
diff --git a/src/contact_list.c b/src/contact_list.c
index 485a7a35..b244ac3e 100644
--- a/src/contact_list.c
+++ b/src/contact_list.c
@@ -29,14 +29,12 @@
 #include "contact.h"
 #include "contact_list.h"
 #include "prof_autocomplete.h"
-#include "log.h"
 
 static PAutocomplete ac;
 
 void
 contact_list_init(void)
 {
-    log_msg(PROF_LEVEL_INFO, "prof", "Initialising contact list");
     ac = p_obj_autocomplete_new((PStrFunc)p_contact_name, 
                             (PCopyFunc)p_contact_copy,
                             (PEqualDeepFunc)p_contacts_equal_deep,
diff --git a/src/input_win.c b/src/input_win.c
index f9c10b6a..a79ed5c5 100644
--- a/src/input_win.c
+++ b/src/input_win.c
@@ -47,7 +47,7 @@
 #include "ui.h"
 #include "history.h"
 #include "preferences.h"
-#include "util.h"
+#include "common.h"
 #include "command.h"
 
 static WINDOW *inp_win;
diff --git a/src/jabber.c b/src/jabber.c
index 95a7f25a..1901b6b2 100644
--- a/src/jabber.c
+++ b/src/jabber.c
@@ -30,7 +30,7 @@
 #include "chat_log.h"
 #include "contact_list.h"
 #include "ui.h"
-#include "util.h"
+#include "common.h"
 #include "preferences.h"
 
 #define PING_INTERVAL 120000 // 2 minutes
diff --git a/src/profanity.c b/src/profanity.c
index 5663454e..253c7f32 100644
--- a/src/profanity.c
+++ b/src/profanity.c
@@ -86,6 +86,7 @@ profanity_init(const int disable_tls, char *log_level)
     gui_init();
     jabber_init(disable_tls);
     cmd_init();
+    log_msg(PROF_LEVEL_INFO, "prof", "Initialising contact list");
     contact_list_init();
     atexit(_profanity_shutdown);
 }
diff --git a/src/status_bar.c b/src/status_bar.c
index 5005f2b9..d2094cf9 100644
--- a/src/status_bar.c
+++ b/src/status_bar.c
@@ -26,7 +26,7 @@
 #include <ncurses.h>
 
 #include "ui.h"
-#include "util.h"
+#include "common.h"
 
 static WINDOW *status_bar;
 static char *message = NULL;
diff --git a/src/util.c b/src/util.c
deleted file mode 100644
index 00a020b3..00000000
--- a/src/util.c
+++ /dev/null
@@ -1,95 +0,0 @@
-/* 
- * util.c
- *
- * Copyright (C) 2012 James Booth <boothj5@gmail.com>
- * 
- * This file is part of Profanity.
- *
- * Profanity is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Profanity is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Profanity.  If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-#include <time.h>
-#include <string.h>
-#include <ctype.h>
-#include <stdlib.h>
-
-void
-get_time(char *thetime)
-{
-    time_t rawtime;
-    struct tm *timeinfo;
-
-    time(&rawtime);
-    timeinfo = localtime(&rawtime);
-
-    strftime(thetime, 80, "%H:%M", timeinfo);
-}
-
-char *
-str_replace (const char *string, const char *substr, 
-    const char *replacement) 
-{
-    char *tok = NULL;
-    char *newstr = NULL;
-    char *oldstr = NULL;
-    char *head = NULL;
- 
-    if (string == NULL)
-        return NULL;
-
-    if ( substr == NULL || 
-         replacement == NULL || 
-         (strcmp(substr, "") == 0)) 
-        return strdup (string);
-
-    newstr = strdup (string);
-    head = newstr;
-
-    while ( (tok = strstr ( head, substr ))) {
-        oldstr = newstr;
-        newstr = malloc ( strlen ( oldstr ) - strlen ( substr ) + 
-            strlen ( replacement ) + 1 );
-        
-        if ( newstr == NULL ) { 
-            free (oldstr);
-            return NULL;
-        }
-        
-        memcpy ( newstr, oldstr, tok - oldstr );
-        memcpy ( newstr + (tok - oldstr), replacement, strlen ( replacement ) );
-        memcpy ( newstr + (tok - oldstr) + strlen( replacement ), 
-            tok + strlen ( substr ), 
-            strlen ( oldstr ) - strlen ( substr ) - ( tok - oldstr ) );
-        memset ( newstr + strlen ( oldstr ) - strlen ( substr ) + 
-            strlen ( replacement ) , 0, 1 );
-        
-        head = newstr + (tok - oldstr) + strlen( replacement );
-        free (oldstr);
-    }
-  
-    return newstr;
-}
-
-int
-str_contains(char str[], int size, char ch)
-{
-    int i;
-    for (i = 0; i < size; i++) {
-        if (str[i] == ch)
-            return 1;
-    }
-
-    return 0;
-}
diff --git a/src/util.h b/src/util.h
deleted file mode 100644
index 59469de0..00000000
--- a/src/util.h
+++ /dev/null
@@ -1,31 +0,0 @@
-/* 
- * util.h
- *
- * Copyright (C) 2012 James Booth <boothj5@gmail.com>
- * 
- * This file is part of Profanity.
- *
- * Profanity is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * Profanity is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with Profanity.  If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-#ifndef UTIL_H
-#define UTIL_H
-
-void get_time(char *thetime);
-char * str_replace(const char *string, const char *substr, 
-    const char *replacement);
-int str_contains(char str[], int size, char ch);
-
-#endif
diff --git a/src/windows.c b/src/windows.c
index 12a21aa5..3a6a5c7e 100644
--- a/src/windows.c
+++ b/src/windows.c
@@ -31,7 +31,7 @@
 #endif
 
 #include "ui.h"
-#include "util.h"
+#include "common.h"
 #include "contact.h"
 #include "command.h"
 #include "preferences.h"
diff --git a/tests/test_util.c b/tests/test_common.c
index ffe12506..6bdcfb76 100644
--- a/tests/test_util.c
+++ b/tests/test_common.c
@@ -1,7 +1,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <head-unit.h>
-#include "util.h"
+#include "common.h"
 
 void replace_one_substr(void)
 {
@@ -146,9 +146,9 @@ void replace_when_new_null(void)
     assert_string_equals("hello", result);
 }
 
-void register_util_tests(void)
+void register_common_tests(void)
 {
-    TEST_MODULE("util tests");
+    TEST_MODULE("common tests");
     TEST(replace_one_substr);
     TEST(replace_one_substr_beginning);
     TEST(replace_one_substr_end);
diff --git a/tests/testsuite.c b/tests/testsuite.c
index c3f164f9..e7a23005 100644
--- a/tests/testsuite.c
+++ b/tests/testsuite.c
@@ -5,7 +5,7 @@ int main(void)
 {
     register_prof_history_tests();
     register_contact_list_tests();
-    register_util_tests();
+    register_common_tests();
     register_prof_autocomplete_tests();
     run_suite();
     return 0;
diff --git a/tests/testsuite.h b/tests/testsuite.h
index f4bd9046..45145c9b 100644
--- a/tests/testsuite.h
+++ b/tests/testsuite.h
@@ -3,7 +3,7 @@
 
 void register_prof_history_tests(void);
 void register_contact_list_tests(void);
-void register_util_tests(void);
+void register_common_tests(void);
 void register_prof_autocomplete_tests(void);
 
 #endif