mips/lib/error.c

73 lines
1.7 KiB
C
Raw Permalink Normal View History

#include <merror.h>
#include <stdarg.h>
#include <stdio.h>
char *current_file = NULL;
int log_disabled = 0;
__attribute__((format(printf, 4, 5)))
void __log_impl_pos(int line, int column, int type, const char *format, ...)
{
2024-09-13 15:11:18 +00:00
if (log_disabled)
return;
va_list list;
va_start(list, format);
char *t = NULL;
switch (type) {
case __DEBUG:
t = "\033[34mdebug:\033[0m";
break;
case __WARNING:
t = "\033[35mwarning:\033[0m";
break;
case __ERROR:
t = "\033[31merror:\033[0m";
break;
2024-10-09 16:06:16 +00:00
case __BUG:
t = "\033[31bug:\033[0m";
break;
}
if (current_file != NULL)
printf("%s:%d:%d: %s ", current_file, line, column, t);
else
printf("%s ", t);
vprintf(format, list);
putchar('\n');
}
__attribute__((format(printf, 2, 3)))
void __log_impl(int type, const char *format, ...)
{
2024-09-13 15:11:18 +00:00
if (log_disabled)
return;
va_list list;
va_start(list, format);
char *t = NULL;
switch (type) {
case __DEBUG:
t = "\033[34mdebug:\033[0m";
break;
case __WARNING:
t = "\033[35mwarning:\033[0m";
break;
case __ERROR:
t = "\033[31merror:\033[0m";
break;
2024-10-09 16:06:16 +00:00
case __BUG:
t = "\033[31bug:\033[0m";
break;
}
if (current_file != NULL)
printf("%s: %s ", current_file, t);
else
printf("%s ", t);
vprintf(format, list);
putchar('\n');
}