Mercurial > hg > nnchat
changeset 511:291e3caa91a0
Move logParseFilename() to nn_log_parse_filename() under util.c and rename logFileOpen() and logFileClose().
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 05 Jun 2012 19:28:34 +0300 |
parents | 54f4f84bae5c |
children | 93c8ba1ef55f |
files | main.c util.c util.h |
diffstat | 3 files changed, 53 insertions(+), 50 deletions(-) [+] |
line wrap: on
line diff
--- a/main.c Sun Jun 03 06:33:28 2012 +0300 +++ b/main.c Tue Jun 05 19:28:34 2012 +0300 @@ -1260,59 +1260,14 @@ } -#define VPUTCH(CH) th_vputch(&bufData, &bufSize, &bufLen, CH) -#define VPUTS(STR) th_vputs(&bufData, &bufSize, &bufLen, STR) - -char *logParseFilename(const char *fmt, int id) -{ - size_t bufSize = strlen(fmt) + TH_BUFGROW, bufLen = 0; - char *bufData = th_malloc(bufSize); - char tmpBuf[32]; - const char *s = fmt; - - while (*s) - { - if (*s == '%') - { - s++; - switch (*s) - { - case 'i': - snprintf(tmpBuf, sizeof(tmpBuf), "%05d", id); - VPUTS(tmpBuf); - break; - - case 'd': - snprintf(tmpBuf, sizeof(tmpBuf), "%d", id); - VPUTS(tmpBuf); - break; - - case '%': - VPUTCH('%'); - break; - } - s++; - } - else - { - VPUTCH(*s); - s++; - } - } - - VPUTCH(0); - return bufData; -} - - -BOOL logFileOpen(void) +BOOL nn_log_file_open(void) { char *filename; if (optLogFilename == NULL || !optLogEnable) return FALSE; - filename = logParseFilename(optLogFilename, optPort); + filename = nn_log_parse_filename(optLogFilename, optPort); if ((optLogFile = fopen(filename, "a")) == NULL) { @@ -1327,7 +1282,7 @@ } -void logFileClose(void) +void nn_log_file_close(void) { if (optLogFile) { @@ -1471,7 +1426,7 @@ } // Open logfile - logFileOpen(); + nn_log_file_open(); // Initialize network if (!nn_network_init()) @@ -1988,7 +1943,7 @@ THMSG(1, "Connection terminated.\n"); - logFileClose(); + nn_log_file_close(); return 0; }
--- a/util.c Sun Jun 03 06:33:28 2012 +0300 +++ b/util.c Tue Jun 05 19:28:34 2012 +0300 @@ -718,3 +718,48 @@ th_free(tuple->str); th_free(tuple); } + + +#define VPUTCH(CH) th_vputch(&bufData, &bufSize, &bufLen, CH) +#define VPUTS(STR) th_vputs(&bufData, &bufSize, &bufLen, STR) + +char *nn_log_parse_filename(const char *fmt, int id) +{ + size_t bufSize = strlen(fmt) + TH_BUFGROW, bufLen = 0; + char *bufData = th_malloc(bufSize); + char tmpBuf[32]; + const char *s = fmt; + + while (*s) + { + if (*s == '%') + { + s++; + switch (*s) + { + case 'i': + snprintf(tmpBuf, sizeof(tmpBuf), "%05d", id); + VPUTS(tmpBuf); + break; + + case 'd': + snprintf(tmpBuf, sizeof(tmpBuf), "%d", id); + VPUTS(tmpBuf); + break; + + case '%': + VPUTCH('%'); + break; + } + s++; + } + else + { + VPUTCH(*s); + s++; + } + } + + VPUTCH(0); + return bufData; +}