comparison nnchat.c @ 223:03af28fb1c38

Show error messages printed out to stderr only after the program has quit.
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 27 Nov 2010 18:44:55 +0200
parents a1fefbce0b7a
children 801ac37321f6
comparison
equal deleted inserted replaced
222:a1fefbce0b7a 223:03af28fb1c38
378 printMsgV(TRUE, logOnly, fmt, ap); 378 printMsgV(TRUE, logOnly, fmt, ap);
379 va_end(ap); 379 va_end(ap);
380 } 380 }
381 381
382 382
383 char *errorMessages = NULL;
384
383 void errorMsg(const char *fmt, ...) 385 void errorMsg(const char *fmt, ...)
384 { 386 {
387 char *tmp;
385 va_list ap1, ap2; 388 va_list ap1, ap2;
386 389
387 va_start(ap1, fmt); 390 va_start(ap1, fmt);
388 va_copy(ap2, ap1); 391 va_copy(ap2, ap1);
389 printMsgV(TRUE, FALSE, fmt, ap1); 392 printMsgV(TRUE, FALSE, fmt, ap1);
390 va_end(ap1); 393 va_end(ap1);
391 394
392 THERR_V(fmt, ap2); 395 tmp = th_strdup_vprintf(fmt, ap2);
393 va_end(ap2); 396 va_end(ap2);
397
398 if (errorMessages != NULL) {
399 char *tmp2 = th_strdup_printf("%s%s", errorMessages, tmp);
400 th_free(errorMessages);
401 th_free(tmp);
402 errorMessages = tmp2;
403 } else
404 errorMessages = tmp;
394 } 405 }
395 406
396 int handleUser(nn_conn_t *conn, const char *str) 407 int handleUser(nn_conn_t *conn, const char *str)
397 { 408 {
398 const char *msg = "</USER><MESSAGE>", *p = str; 409 const char *msg = "</USER><MESSAGE>", *p = str;
1408 closeWindows(); 1419 closeWindows();
1409 endwin(); 1420 endwin();
1410 THMSG(1, "NCurses deinitialized.\n"); 1421 THMSG(1, "NCurses deinitialized.\n");
1411 } 1422 }
1412 1423
1424 if (errorMessages)
1425 THERR("%s", errorMessages);
1426
1413 if (isError) { 1427 if (isError) {
1414 #ifdef __WIN32 1428 #ifdef __WIN32
1415 char *tmp = promptRequester("Press enter to quit.\n", FALSE); 1429 char *tmp = promptRequester("Press enter to quit.\n", FALSE);
1416 th_free(tmp); 1430 th_free(tmp);
1417 #else 1431 #else