An emulator, assembler, and disassembler for the Sega Game Gear
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

39 lines
1.4 KiB

  1. /* Copyright (C) 2014-2015 Ben Kurtovic <ben.kurtovic@gmail.com>
  2. Released under the terms of the MIT License. See LICENSE for details. */
  3. #pragma once
  4. #include <errno.h>
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <string.h>
  8. /* Internal usage only */
  9. #define LOG_MSG_(dest, level, extra, after, ...) { \
  10. fprintf(dest, level ": " __VA_ARGS__); \
  11. extra; \
  12. fprintf(dest, "\n"); \
  13. after; \
  14. }
  15. #define LOG_ERR_(...) LOG_MSG_(stderr, __VA_ARGS__)
  16. #define LOG_OUT_(...) LOG_MSG_(stdout, __VA_ARGS__)
  17. #define PRINT_ERRNO_() fprintf(stderr, ": %s", strerror(errno))
  18. /* Public logging macros */
  19. #define FATAL(...) LOG_ERR_("fatal", {}, exit(EXIT_FAILURE), __VA_ARGS__)
  20. #define FATAL_ERRNO(...) LOG_ERR_("fatal", PRINT_ERRNO_(), exit(EXIT_FAILURE), __VA_ARGS__)
  21. #define ERROR(...) LOG_ERR_("error", {}, {}, __VA_ARGS__)
  22. #define ERROR_ERRNO(...) LOG_ERR_("error", PRINT_ERRNO_(), {}, __VA_ARGS__)
  23. #define WARN(...) LOG_ERR_("warning", {}, {}, __VA_ARGS__)
  24. #define WARN_ERRNO(...) LOG_ERR_("warning", PRINT_ERRNO_(), {}, __VA_ARGS__)
  25. #ifdef DEBUG_MODE
  26. #define DEBUG(...) LOG_OUT_("[DEBUG]", {}, {}, __VA_ARGS__)
  27. #else
  28. #define DEBUG(...) {}
  29. #endif