#ifndef __COMMON_H__
#define __COMMON_H__

#include <stdio.h>
#include <ctype.h>

#ifdef _GNU_SOURCE
#undef _GNU_SOURCE
#endif

#define COLOR_OFF       "\x1B[0m"
#define COLOR_RED       "\x1B[0;91m"
#define COLOR_GREEN     "\x1B[0;92m"
#define COLOR_YELLOW    "\x1B[0;93m"
#define COLOR_BLUE      "\x1B[0;94m"
#define COLOR_MAGENTA   "\x1B[0;95m"
#define COLOR_BOLDGRAY  "\x1B[1;30m"
#define COLOR_BOLDWHITE "\x1B[1;37m"

/* ENABLE_DEBUG should be set on compile time */

#define debug_alert(fmt, ...) \
	do { if (ENABLE_DEBUG) fprintf(stderr, COLOR_RED fmt COLOR_OFF, ##__VA_ARGS__); } while (0)
#define debug_warn(fmt, ...) \
	do { if (ENABLE_DEBUG) fprintf(stderr, COLOR_YELLOW fmt COLOR_OFF, ##__VA_ARGS__); } while (0)
#define debug_success(fmt, ...) \
	do { if (ENABLE_DEBUG) fprintf(stderr, COLOR_GREEN fmt COLOR_OFF, ##__VA_ARGS__); } while (0)
#define debug_info(fmt, ...) \
	do { if (ENABLE_DEBUG) fprintf(stderr, COLOR_BOLDWHITE fmt COLOR_OFF, ##__VA_ARGS__); } while (0)
#define print_error(fmt, ...) \
	do { fprintf(stderr, COLOR_RED "ERROR: " fmt COLOR_OFF, ##__VA_ARGS__); } while (0)
#define print_warn(fmt, ...) \
	do { fprintf(stderr, COLOR_YELLOW "WARN: " fmt COLOR_OFF, ##__VA_ARGS__); } while (0)
#define print_info(fmt, ...) \
	do { fprintf(stdout, COLOR_OFF "INFO: " fmt COLOR_OFF, ##__VA_ARGS__); } while (0)

#endif /* __COMMON_H__ */
