An emulator, assembler, and disassembler for the Sega Game Gear
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 

48 lignes
1.9 KiB

  1. /* Copyright (C) 2014-2016 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, type, extra, after, ...) \
  10. do { \
  11. if (logging_level_ >= level) { \
  12. fprintf(dest, type " " __VA_ARGS__); \
  13. extra; \
  14. fprintf(dest, "\n"); \
  15. after; \
  16. } \
  17. } while (0);
  18. #define LOG_ERR_(...) LOG_MSG_(stderr, __VA_ARGS__)
  19. #define LOG_OUT_(...) LOG_MSG_(stdout, __VA_ARGS__)
  20. #define PRINT_ERR_ fprintf(stderr, ": %s", strerror(errno))
  21. #define EXIT_FAIL_ exit(EXIT_FAILURE)
  22. #define DEBUG_TEXT_ "\x1b[0m\x1b[37m[DEBUG]\x1b[0m"
  23. #define TRACE_TEXT_ "\x1b[1m\x1b[33m[TRACE]\x1b[0m"
  24. unsigned logging_level_;
  25. /* Public logging macros */
  26. #define FATAL(...) LOG_ERR_(0, "fatal:", {}, EXIT_FAIL_, __VA_ARGS__)
  27. #define FATAL_ERRNO(...) LOG_ERR_(0, "fatal:", PRINT_ERR_, EXIT_FAIL_, __VA_ARGS__)
  28. #define ERROR(...) LOG_ERR_(0, "error:", {}, {}, __VA_ARGS__)
  29. #define ERROR_ERRNO(...) LOG_ERR_(0, "error:", PRINT_ERR_, {}, __VA_ARGS__)
  30. #define WARN(...) LOG_ERR_(0, "warning:", {}, {}, __VA_ARGS__)
  31. #define WARN_ERRNO(...) LOG_ERR_(0, "warning:", PRINT_ERR_, {}, __VA_ARGS__)
  32. #define DEBUG(...) LOG_OUT_(1, DEBUG_TEXT_, {}, {}, __VA_ARGS__)
  33. #define TRACE(...) LOG_OUT_(2, TRACE_TEXT_, {}, {}, __VA_ARGS__)
  34. #define SET_LOG_LEVEL(level) logging_level_ = (level);
  35. #define DEBUG_LEVEL (logging_level_ >= 1)
  36. #define TRACE_LEVEL (logging_level_ >= 2)