# HG changeset patch # User Matti Hamalainen # Date 1353003970 -7200 # Node ID c3e4e8f3c658d56d773fd484822de3f05c6a0853 # Parent dbeca46a7c58fc5e32e16f7874c45fc77d5a05a5 Refactor message/error/etc printing functions to be a bit more sane. diff -r dbeca46a7c58 -r c3e4e8f3c658 main.c --- 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); }