changeset 239:b7e7ed741a18

Add unfinished code for logfile name parsing.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 20 Apr 2011 15:44:34 +0300
parents 87f434330547
children e85d453e82eb
files nnchat.c
diffstat 1 files changed, 67 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/nnchat.c	Sun Mar 13 11:49:33 2011 +0200
+++ b/nnchat.c	Wed Apr 20 15:44:34 2011 +0300
@@ -925,6 +925,66 @@
     return FALSE;
 }
 
+char *logParseFilename(const char *fmt, int id)
+{
+    size_t tmpLen = strlen(fmt) + 32;
+    char *res = NULL, tmpBuf[32];
+    const char *s = fmt;
+    
+    if ((res = th_malloc(len)) == NULL)
+        return NULL;
+
+    while (*s) {
+        if (*s == '%') {
+            s++;
+            switch (*s) {
+                case 'i':
+                    
+                    {
+                    snprintf(tmpBuf, sizeof(tmpBuf), "%05d", id);
+                    len -= strlen(tmpBuf) + 1;
+                    if (len <= 0) {
+                        res = th_realloc(res, 
+                    }
+                    VPUTS(tmpBuf);
+                    }
+                    break;
+                
+                case '%':
+                    VPUTCH(res, '%');
+                    break;
+                
+                default:
+                    VPUTCH(res, '%');
+                    VPUTCH(res, *s);
+                    break;
+            }
+        }
+    }
+}
+
+
+BOOL logFileOpen(void)
+{
+    char *filename;
+    
+    if (optLogFilename == NULL)
+        return FALSE;
+
+    
+
+    if ((optLogFile = fopen(filename, "a")) == NULL) {
+        errMsg("Could not open logfile '%s' for appending!\n", filename);
+        th_free(filename);
+        return FALSE;
+    }
+    return TRUE;
+}
+
+BOOL logFileClose(void)
+{
+}
+
 char *promptRequester(const char *info, BOOL allowEmpty)
 {
     char tmpBuf[512], *ptr;
@@ -995,6 +1055,13 @@
     th_cfg_add_int(&tmpcfg, "port", &optPort, optPort);
     th_cfg_add_section(&cfg, "server", tmpcfg);
 
+    tmpcfg = NULL;
+    th_cfg_add_comment(&tmpcfg, "Enable logging");
+    th_cfg_add_string(&tmpcfg, "host", &optServer, optServer);
+    th_cfg_add_comment(&tmpcfg, "Default port to connect to (8002 = public room, 8003 = passion pit, 8005 = members only)");
+    th_cfg_add_int(&tmpcfg, "port", &optPort, optPort);
+    th_cfg_add_section(&cfg, "server", tmpcfg);
+
 #ifdef __WIN32
     {
     char tmpPath[MAX_PATH];