comparison util.c @ 1792:52a47611a273

Avoid printing a bunch of junk to stdout when GDB remote debugging is enabled as this can confuse GDB
author Michael Pavone <pavone@retrodev.com>
date Wed, 20 Mar 2019 22:05:27 -0700
parents eda8df5bc74c
children 243f3a7247f9
comparison
equal deleted inserted replaced
1791:1843823f1e9b 1792:52a47611a273
475 } 475 }
476 #endif 476 #endif
477 va_end(args); 477 va_end(args);
478 } 478 }
479 479
480 static uint8_t output_enabled = 1;
480 void info_message(char *format, ...) 481 void info_message(char *format, ...)
481 { 482 {
482 va_list args; 483 va_list args;
483 va_start(args, format); 484 va_start(args, format);
484 #ifndef _WIN32 485 #ifndef _WIN32
485 if (headless || (isatty(STDOUT_FILENO) && isatty(STDIN_FILENO))) { 486 if (headless || (isatty(STDOUT_FILENO) && isatty(STDIN_FILENO))) {
486 info_printf(format, args); 487 if (output_enabled) {
488 info_printf(format, args);
489 }
487 } else { 490 } else {
488 #endif 491 #endif
489 int32_t size = strlen(format) * 2; 492 int32_t size = strlen(format) * 2;
490 char *buf = malloc(size); 493 char *buf = malloc(size);
491 int32_t actual = vsnprintf(buf, size, format, args); 494 int32_t actual = vsnprintf(buf, size, format, args);
501 buf = malloc(actual); 504 buf = malloc(actual);
502 va_end(args); 505 va_end(args);
503 va_start(args, format); 506 va_start(args, format);
504 vsnprintf(buf, actual, format, args); 507 vsnprintf(buf, actual, format, args);
505 } 508 }
506 info_puts(buf); 509 if (output_enabled) {
510 info_puts(buf);
511 }
507 render_infobox("BlastEm Info", buf); 512 render_infobox("BlastEm Info", buf);
508 free(buf); 513 free(buf);
509 #ifndef _WIN32 514 #ifndef _WIN32
510 } 515 }
511 #endif 516 #endif
512 va_end(args); 517 va_end(args);
518 }
519
520 void debug_message(char *format, ...)
521 {
522 va_list args;
523 va_start(args, format);
524 if (output_enabled) {
525 info_printf(format, args);
526 }
527 }
528
529 void disable_stdout_messages(void)
530 {
531 output_enabled = 0;
513 } 532 }
514 533
515 #ifdef _WIN32 534 #ifdef _WIN32
516 #include <windows.h> 535 #include <windows.h>
517 #include <shlobj.h> 536 #include <shlobj.h>