macro refactoring for clarity [sic]

This commit is contained in:
Aaron Culliney 2013-10-05 23:13:24 -07:00
parent a063669cb8
commit 0f26899420

View File

@ -1,7 +1,5 @@
/* /*
* Apple // emulator : misc defines * Apple // emulator for *nix
*
* Copyright 2013 Aaron Culliney
* *
* This software package is subject to the GNU General Public License * This software package is subject to the GNU General Public License
* version 2 or later (your choice) as published by the Free Software * version 2 or later (your choice) as published by the Free Software
@ -18,20 +16,25 @@
#include <stdlib.h> #include <stdlib.h>
#include <errno.h> #include <errno.h>
#include <string.h> #include <string.h>
#include <stdint.h>
#include <stdbool.h>
#include <time.h>
#include <unistd.h>
#include <assert.h>
#include <pthread.h>
#ifndef NDEBUG #ifndef NDEBUG
# if defined(__GNUC__)
#if defined(__GNUC__) # pragma GCC diagnostic push
# pragma GCC diagnostic push # pragma GCC diagnostic ignored "-Wunused-variable"
# pragma GCC diagnostic ignored "-Wunused-variable" # elif defined(__clang__)
#elif defined(__clang__) # pragma clang diagnostic push
# pragma clang diagnostic push # pragma clang diagnostic ignored "-Wunused-variable"
# pragma clang diagnostic ignored "-Werror=unused-variable" # endif
#endif
static FILE *error_log=0; static FILE *error_log=0;
#define ERRLOG(/* err message format string, args */...) \ #define ERRLOG(/* err message format string, args */...) \
{ \ do { \
int saverr = errno; errno = 0; \ int saverr = errno; errno = 0; \
fprintf(error_log ? error_log : stderr, "%s:%d - ", __FILE__, __LINE__); \ fprintf(error_log ? error_log : stderr, "%s:%d - ", __FILE__, __LINE__); \
fprintf(error_log ? error_log : stderr, __VA_ARGS__); \ fprintf(error_log ? error_log : stderr, __VA_ARGS__); \
@ -39,13 +42,13 @@ static FILE *error_log=0;
fprintf(error_log ? error_log : stderr, " (syserr: %s)", strerror(saverr)); \ fprintf(error_log ? error_log : stderr, " (syserr: %s)", strerror(saverr)); \
} \ } \
fprintf(error_log ? error_log : stderr, "\n"); \ fprintf(error_log ? error_log : stderr, "\n"); \
} } while(0);
#define ERRQUIT(...) \ #define ERRQUIT(...) \
{ \ do { \
ERRLOG(__VA_ARGS__); \ ERRLOG(__VA_ARGS__); \
exit(0); \ exit(0); \
} } while(0);
#else // NDEBUG #else // NDEBUG
@ -55,15 +58,23 @@ static FILE *error_log=0;
# pragma clang diagnostic pop # pragma clang diagnostic pop
#endif #endif
#define ERRLOG(...) \ #define ERRLOG(...) \
do \ do \
{ \ { \
} while(0); } while(0);
#endif #endif
#define LOG(...) ERRLOG(__VA_ARGS__) #define LOG(...) \
do { \
errno = 0; \
ERRLOG(__VA_ARGS__); \
} while(0);
static void inline Free(void *x) { free(x); x=NULL; } #define Free(X) \
do { \
free(X); \
X=NULL; \
} while (0);
#endif // whole file #endif // whole file