# HG changeset patch # User Matti Hamalainen # Date 1303303474 -10800 # Node ID b7e7ed741a1836748fb0f67f168b87756de1d9d4 # Parent 87f434330547bcdf249da202d0d47229de02e801 Add unfinished code for logfile name parsing. diff -r 87f434330547 -r b7e7ed741a18 nnchat.c --- 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];