changeset 325:c086345d176b

Move some functions to libnnchat and rename nn_find_window to findWindow()
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 11 Jun 2011 10:03:44 +0300
parents ba4cc7ebe311
children 2f7849e505f3
files libnnchat.c libnnchat.h nnchat.c
diffstat 3 files changed, 48 insertions(+), 48 deletions(-) [+]
line wrap: on
line diff
--- a/libnnchat.c	Sat Jun 11 09:49:42 2011 +0300
+++ b/libnnchat.c	Sat Jun 11 10:03:44 2011 +0300
@@ -891,3 +891,29 @@
 }
 
 
+nn_window_t *nn_window_new(const char *id)
+{
+    nn_window_t *res = th_calloc(1, sizeof(nn_window_t));
+    
+    if (res == NULL) return NULL;
+
+    res->data = th_ringbuf_new(NN_BACKBUF_LEN, th_free);
+    if (res->data == NULL) {
+        th_free(res);
+        return NULL;
+    }
+
+    res->id = th_strdup(id);
+    
+    return res;
+}
+
+
+void nn_window_free(nn_window_t *win)
+{
+    if (win != NULL) {
+        th_ringbuf_free(win->data);
+        th_free(win->id);
+        th_free(win);
+    }
+}
--- a/libnnchat.h	Sat Jun 11 09:49:42 2011 +0300
+++ b/libnnchat.h	Sat Jun 11 10:03:44 2011 +0300
@@ -30,6 +30,7 @@
 #define NN_CONNBUF_SIZE   (64 * 1024)
 #define NN_NUM_BUCKETS    (256)
 #define NN_DELAY_USEC     (15 * 1000)
+#define NN_BACKBUF_LEN    (512)       /* Backbuffer size (in lines) */
 
 typedef struct {
     ssize_t pos, len, size;
@@ -72,6 +73,19 @@
 } nn_conn_t;
 
 
+typedef struct {
+    qringbuf_t *data;   /* "Backbuffer" data for this window */
+    int pos;            /* Current position in the window, 0 = real time */
+    BOOL dirty;
+
+    char *id;           /* Chatter ID, NULL = main window */
+    int num;		/* Window number */
+    
+    char *buf;
+    size_t len, bufsize;
+} nn_window_t;
+
+
 const char *nn_get_errstr(int err);
 BOOL        nn_network_init(void);
 void        nn_network_close(void);
@@ -119,4 +133,7 @@
 char *      nn_editbuf_get_string(nn_editbuf_t *buf, ssize_t start, ssize_t end);
 
 
+nn_window_t *nn_window_new(const char *);
+void        nn_window_free(nn_window_t *);
+
 #endif
--- a/nnchat.c	Sat Jun 11 09:49:42 2011 +0300
+++ b/nnchat.c	Sat Jun 11 10:03:44 2011 +0300
@@ -32,25 +32,11 @@
 #define SET_DELAY          (5)
 #endif
 
-#define SET_BACKBUF_LEN (512)       /* Backbuffer size (in lines) */
 #define SET_MAX_HISTORY (16)        /* Command history length */
 #define SET_KEEPALIVE   (15*60)     /* Ping/keepalive period in seconds */
 #define SET_MAX_WINDOWS (32)
 
 
-typedef struct {
-    qringbuf_t *data;   /* "Backbuffer" data for this window */
-    int pos;            /* Current position in the window, 0 = real time */
-    BOOL dirty;
-
-    char *id;           /* Chatter ID, NULL = main window */
-    int num;		/* Window number */
-    
-    char *buf;
-    size_t len, bufsize;
-} nn_window_t;
-
-
 /* Options
  */
 int     optPort = 8005;
@@ -203,35 +189,7 @@
 }
 
 
-nn_window_t *nn_window_new(const char *id)
-{
-    nn_window_t *res = th_calloc(1, sizeof(nn_window_t));
-    
-    if (res == NULL) return NULL;
-
-    res->data = th_ringbuf_new(SET_BACKBUF_LEN, th_free);
-    if (res->data == NULL) {
-        th_free(res);
-        return NULL;
-    }
-
-    res->id = th_strdup(id);
-    
-    return res;
-}
-
-
-void nn_window_free(nn_window_t *win)
-{
-    if (win != NULL) {
-        th_ringbuf_free(win->data);
-        th_free(win->id);
-        th_free(win);
-    }
-}
-
-
-nn_window_t *nn_find_window(const char *id)
+nn_window_t *findWindow(const char *id)
 {
     int i;
 
@@ -646,7 +604,7 @@
             *tmp = 0;
 
             isIgnored = setIgnoreMode && checkIgnoreList(name);
-            win = nn_find_window(name);
+            win = findWindow(name);
             
             if (win != NULL) {
                 printMsgF(win, isIgnored ? LOG_FILE : (LOG_WINDOW | LOG_FILE),
@@ -715,7 +673,7 @@
     p = nn_dbldecode_str(str);
     if (!p) return -1;
 
-    win = nn_find_window(p);
+    win = findWindow(p);
     nn_userhash_insert(nnUsers, nn_username_encode(p));
 
     printMsg(NULL, "! ˝3˝%s˝0˝ ˝2˝ADDED.˝0˝\n", p);
@@ -740,7 +698,7 @@
     p = nn_dbldecode_str(str);
     if (!p) return -1;
 
-    win = nn_find_window(p);
+    win = findWindow(p);
     nn_userhash_delete(nnUsers, nn_username_encode(p));
 
     printMsg(NULL, "! ˝3˝%s˝0˝ ˝1˝DELETED.˝0˝\n", p);
@@ -921,8 +879,7 @@
     else if (!strncasecmp(buf, "/close", 6)) {
         char *name = trimLeft(buf + 6);
         if (strlen(name) > 0) {
-            nn_window_t *win;
-            win = nn_find_window(name);
+            nn_window_t *win = findWindow(name);
             if (win != NULL) {
                 closeWindow(win);
                 printMsgQ(currWin, "Closed PRV query to '%s'.\n", name);