Mercurial > hg > nnchat
changeset 563:c3e4e8f3c658
Refactor message/error/etc printing functions to be a bit more sane.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 15 Nov 2012 20:26:10 +0200 |
parents | dbeca46a7c58 |
children | 6e5789cbb4d4 |
files | main.c |
diffstat | 1 files changed, 24 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/main.c Thu Nov 15 19:53:08 2012 +0200 +++ b/main.c Thu Nov 15 20:26:10 2012 +0200 @@ -253,9 +253,9 @@ BOOL nn_log_reopen(nn_window_t *win); -void printMsgV(nn_window_t *win, int flags, const char *fmt, va_list ap) +void printMsgConst(nn_window_t *win, int flags, const char *msg) { - char tmpStr[128], *buf; + char tmpStr[128]; nn_window_t *tmpwin = (win != NULL) ? win : nnwin_main_window(); // Only the main window @@ -282,24 +282,27 @@ str_get_timestamp(tmpStr, sizeof(tmpStr), "½17½[½11½%H:%M:%S½17½]½0½ "); } - buf = th_strdup_vprintf(fmt, ap); - if (flags & LOG_FILE) { - printMsgFile(win != NULL ? win : nnwin_main_window(), flags, tmpStr, buf); + printMsgFile(win != NULL ? win : nnwin_main_window(), flags, tmpStr, msg); } if (flags & LOG_FILE2) { - printMsgFile(nnwin_main_window(), flags, tmpStr, buf); + printMsgFile(nnwin_main_window(), flags, tmpStr, msg); } if (!optDaemon && (flags & LOG_WINDOW)) { if (flags & LOG_STAMP) nnwin_print(tmpwin, tmpStr); - nnwin_print(tmpwin, buf); + nnwin_print(tmpwin, msg); } +} +void printMsgV(nn_window_t *win, int flags, const char *fmt, va_list ap) +{ + char *buf = th_strdup_vprintf(fmt, ap); + printMsgConst(win, flags, buf); th_free(buf); } @@ -333,21 +336,27 @@ char *errorMessages = NULL; -void errorMsgV(const char *fmt, va_list ap) +void errorMsgConst(const char *msg) { - char *tmp = th_strdup_vprintf(fmt, ap); - - printMsg(NULL, "%s", tmp); + printMsgConst(NULL, LOG_STAMP | LOG_WINDOW | LOG_FILE, msg); if (errorMessages != NULL) { - char *tmp2 = th_strdup_printf("%s%s", errorMessages, tmp); + // XXX Yes, this is lazy. + char *tmp = th_strdup_printf("%s%s", errorMessages, msg); th_free(errorMessages); - th_free(tmp); - errorMessages = tmp2; + errorMessages = tmp; } else - errorMessages = tmp; + errorMessages = th_strdup(msg); +} + + +void errorMsgV(const char *fmt, va_list ap) +{ + char *msg = th_strdup_vprintf(fmt, ap); + errorMsgConst(msg); + th_free(msg); }