2024-09-09 16:41:49 +00:00
|
|
|
/* Copyright (c) 2024 Freya Murphy */
|
|
|
|
#ifndef __MERROR_H__
|
|
|
|
#define __MERROR_H__
|
|
|
|
|
2024-09-21 00:46:37 +00:00
|
|
|
#include <errno.h>
|
2024-09-22 20:02:42 +00:00
|
|
|
#include <string.h>
|
2024-09-21 00:46:37 +00:00
|
|
|
|
2024-09-09 16:41:49 +00:00
|
|
|
/* Error codes
|
|
|
|
*/
|
|
|
|
#define M_SUCCESS 0
|
2024-10-04 23:41:10 +00:00
|
|
|
#define M_ERROR 1
|
|
|
|
#define M_EOF 2
|
2024-09-09 16:41:49 +00:00
|
|
|
|
|
|
|
#define __DEBUG 1
|
|
|
|
#define __WARNING 2
|
|
|
|
#define __ERROR 3
|
2024-10-09 16:06:16 +00:00
|
|
|
#define __BUG 4
|
2024-09-09 16:41:49 +00:00
|
|
|
|
|
|
|
__attribute__((format(printf, 4, 5)))
|
|
|
|
void __log_impl_pos(int line, int column, int type, const char *format, ...);
|
|
|
|
void __log_impl(int type, const char *format, ...);
|
|
|
|
|
|
|
|
#define DEBUG(format, ...) \
|
|
|
|
__log_impl(__DEBUG, format, ##__VA_ARGS__)
|
|
|
|
|
|
|
|
#define WARNING(format, ...) \
|
|
|
|
__log_impl(__WARNING, format, ##__VA_ARGS__)
|
|
|
|
|
2024-10-09 16:06:16 +00:00
|
|
|
#define BUG(format, ...) \
|
|
|
|
__log_impl(__BUG, format, ##__VA_ARGS__)
|
|
|
|
|
2024-09-09 16:41:49 +00:00
|
|
|
#define ERROR(format, ...) \
|
|
|
|
__log_impl(__ERROR, format, ##__VA_ARGS__)
|
|
|
|
|
|
|
|
#define DEBUG_POS(pos, format, ...) \
|
|
|
|
__log_impl_pos(pos.y, pos.x, __DEBUG, format, ##__VA_ARGS__)
|
|
|
|
|
|
|
|
#define WARNING_POS(pos, format, ...) \
|
|
|
|
__log_impl_pos(pos.y, pos.x, __WARNING, format, ##__VA_ARGS__)
|
|
|
|
|
|
|
|
#define ERROR_POS(pos, format, ...) \
|
|
|
|
__log_impl_pos(pos.y, pos.x, __ERROR, format, ##__VA_ARGS__)
|
|
|
|
|
2024-09-21 00:46:37 +00:00
|
|
|
#define PERROR(format, ...) \
|
|
|
|
__log_impl(__ERROR, format ": %s", ##__VA_ARGS__, (strerror(errno)))
|
|
|
|
|
2024-09-09 16:41:49 +00:00
|
|
|
#endif /* __MERROR_H__ */
|