Mercurial > hg
comparison mcabber/src/screen.c @ 1075:03bc225ad763
Improve scr_LogPrint() readability
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Sun, 03 Dec 2006 19:29:54 +0100 |
parents | 2a3cfb98bd5e |
children | b9698c89f46d |
comparison
equal
deleted
inserted
replaced
1074:b2fc694a8228 | 1075:03bc225ad763 |
---|---|
348 void scr_LogPrint(unsigned int flag, const char *fmt, ...) | 348 void scr_LogPrint(unsigned int flag, const char *fmt, ...) |
349 { | 349 { |
350 time_t timestamp; | 350 time_t timestamp; |
351 char strtimestamp[64]; | 351 char strtimestamp[64]; |
352 char *buffer, *btext; | 352 char *buffer, *btext; |
353 char *convbuf1 = NULL, *convbuf2 = NULL; | |
353 va_list ap; | 354 va_list ap; |
354 | 355 |
355 if (!(flag & ~LPRINT_NOTUTF8)) return; // Shouldn't happen | 356 if (!(flag & ~LPRINT_NOTUTF8)) return; // Shouldn't happen |
356 | 357 |
357 timestamp = time(NULL); | 358 timestamp = time(NULL); |
366 | 367 |
367 buffer = g_strdup_printf("%s %s", strtimestamp, btext); | 368 buffer = g_strdup_printf("%s %s", strtimestamp, btext); |
368 | 369 |
369 // Convert buffer to current locale for wprintw() | 370 // Convert buffer to current locale for wprintw() |
370 if (!(flag & LPRINT_NOTUTF8)) | 371 if (!(flag & LPRINT_NOTUTF8)) |
371 buffer_locale = from_utf8(buffer); | 372 buffer_locale = convbuf1 = from_utf8(buffer); |
372 else | 373 else |
373 buffer_locale = buffer; | 374 buffer_locale = buffer; |
374 | 375 |
375 if (!buffer_locale) { | 376 if (!buffer_locale) { |
376 wprintw(logWnd, | 377 wprintw(logWnd, |
381 return; | 382 return; |
382 } | 383 } |
383 | 384 |
384 // For the special status buffer, we need utf-8, but without the timestamp | 385 // For the special status buffer, we need utf-8, but without the timestamp |
385 if (flag & LPRINT_NOTUTF8) | 386 if (flag & LPRINT_NOTUTF8) |
386 buf_specialwindow = to_utf8(btext); | 387 buf_specialwindow = convbuf2 = to_utf8(btext); |
387 else | 388 else |
388 buf_specialwindow = btext; | 389 buf_specialwindow = btext; |
389 | 390 |
390 if (Curses) { | 391 if (Curses) { |
391 wprintw(logWnd, "\n%s", buffer_locale); | 392 wprintw(logWnd, "\n%s", buffer_locale); |
397 // ncurses are not initialized yet, so we call directly hbuf routine | 398 // ncurses are not initialized yet, so we call directly hbuf routine |
398 hbuf_add_line(&statushbuf, buf_specialwindow, timestamp, | 399 hbuf_add_line(&statushbuf, buf_specialwindow, timestamp, |
399 HBB_PREFIX_SPECIAL, 0); | 400 HBB_PREFIX_SPECIAL, 0); |
400 } | 401 } |
401 | 402 |
402 if (buf_specialwindow != btext) | 403 g_free(convbuf1); |
403 g_free(buf_specialwindow); | 404 g_free(convbuf2); |
404 if (!(flag & LPRINT_NOTUTF8)) | |
405 g_free(buffer_locale); | |
406 | |
407 g_free(buffer); | 405 g_free(buffer); |
408 } | 406 } |
409 | 407 |
410 if (flag & (LPRINT_LOG|LPRINT_DEBUG)) { | 408 if (flag & (LPRINT_LOG|LPRINT_DEBUG)) { |
411 strftime(strtimestamp, 23, "[%Y-%m-%d %H:%M:%S]", localtime(×tamp)); | 409 strftime(strtimestamp, 23, "[%Y-%m-%d %H:%M:%S]", localtime(×tamp)); |