An emulator, assembler, and disassembler for the Sega Game Gear
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

vor 8 Jahren
vor 8 Jahren
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 (!level || 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 NO_EOL_ if (0)
  23. #define FLUSH_OUT_ fflush(stdout);
  24. #define FATAL_TEXT_ "\x1b[1m\x1b[31m" "fatal:" "\x1b[0m"
  25. #define ERROR_TEXT_ "\x1b[1m\x1b[31m" "error:" "\x1b[0m"
  26. #define WARN_TEXT_ "\x1b[1m\x1b[33m" "warning:" "\x1b[0m"
  27. #define DEBUG_TEXT_ "\x1b[0m\x1b[37m" "[DEBUG]" "\x1b[0m"
  28. #define TRACE_TEXT_ "\x1b[1m\x1b[30m" "[TRACE]" "\x1b[0m"
  29. unsigned logging_level_;
  30. /* Public logging macros */
  31. #define FATAL(...) LOG_ERR_(0, FATAL_TEXT_, {}, EXIT_FAIL_, __VA_ARGS__)
  32. #define FATAL_ERRNO(...) LOG_ERR_(0, FATAL_TEXT_, PRINT_ERR_, EXIT_FAIL_, __VA_ARGS__)
  33. #define ERROR(...) LOG_ERR_(0, ERROR_TEXT_, {}, {}, __VA_ARGS__)
  34. #define ERROR_ERRNO(...) LOG_ERR_(0, ERROR_TEXT_, PRINT_ERR_, {}, __VA_ARGS__)
  35. #define WARN(...) LOG_ERR_(0, WARN_TEXT_, {}, {}, __VA_ARGS__)
  36. #define WARN_ERRNO(...) LOG_ERR_(0, WARN_TEXT_, PRINT_ERR_, {}, __VA_ARGS__)
  37. #define DEBUG(...) LOG_OUT_(1, DEBUG_TEXT_, {}, {}, __VA_ARGS__)
  38. #define TRACE(...) LOG_OUT_(2, TRACE_TEXT_, {}, {}, __VA_ARGS__)
  39. #define TRACE_NOEOL(...) LOG_OUT_(2, TRACE_TEXT_, NO_EOL_, FLUSH_OUT_, __VA_ARGS__)
  40. #define SET_LOG_LEVEL(level) logging_level_ = (level);
  41. #define DEBUG_LEVEL (logging_level_ >= 1)
  42. #define TRACE_LEVEL (logging_level_ >= 2)