mirror of
https://github.com/thepigeongenerator/mcaselector-lite.git
synced 2025-12-19 12:55:45 +01:00
move /src/error.? to /src/util/error.?
This commit is contained in:
@@ -11,7 +11,7 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "../types.h"
|
||||
#include "../error.h"
|
||||
#include "../util/error.h"
|
||||
#include "atrb.h"
|
||||
|
||||
int conf_procbuf(const char *restrict buf, char *restrict kout, char *restrict vout, usize len) {
|
||||
|
||||
59
src/util/error.c
Normal file
59
src/util/error.c
Normal file
@@ -0,0 +1,59 @@
|
||||
/* Copyright (c) 2025 Quinn
|
||||
* Licensed under the MIT Licence. See LICENSE for details */
|
||||
#include "error.h"
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "../types.h"
|
||||
|
||||
static void error_log(FILE *restrict stream, const char *restrict pfx, uint ln, const char *restrict file, const char *restrict fmt, va_list ap) {
|
||||
fprintf(stream, "(%s:%u) [%s] '", file, ln, pfx);
|
||||
|
||||
vfprintf(stream, fmt, ap);
|
||||
|
||||
fprintf(stream, "'\n");
|
||||
}
|
||||
|
||||
void error_debug(uint ln, const char *restrict file, const char *restrict fmt, ...) {
|
||||
#ifndef NDEBUG
|
||||
#else
|
||||
char *env = getenv("DEBUG");
|
||||
if (env && env[0] != '1')
|
||||
return;
|
||||
#endif
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
error_log(stdout, "\033[95mDBG\033[0m", ln, file, fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
void error_info(uint ln, const char *restrict file, const char *restrict fmt, ...) {
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
error_log(stdout, "\033[94mINF\033[0m", ln, file, fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
void error_warn(uint ln, const char *restrict file, const char *restrict fmt, ...) {
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
error_log(stdout, "\033[93mWAR\033[0m", ln, file, fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
void error_error(uint ln, const char *restrict file, const char *restrict fmt, ...) {
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
error_log(stdout, "\033[91mERR\033[0m", ln, file, fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
void error_fatal(uint ln, const char *restrict file, const char *restrict fmt, ...) {
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
error_log(stdout, "\033[101mFAT\033[0m", ln, file, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
22
src/util/error.h
Normal file
22
src/util/error.h
Normal file
@@ -0,0 +1,22 @@
|
||||
/* Copyright (c) 2025 Quinn
|
||||
* Licensed under the MIT Licence. See LICENSE for details */
|
||||
#pragma once
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "../types.h"
|
||||
#include "../util/atrb.h"
|
||||
#include "../util/macro.h"
|
||||
|
||||
void error_debug(uint ln, const char *restrict file, const char *restrict fmt, ...);
|
||||
void error_info(uint ln, const char *restrict file, const char *restrict fmt, ...);
|
||||
void error_warn(uint ln, const char *restrict file, const char *restrict fmt, ...);
|
||||
void error_error(uint ln, const char *restrict file, const char *restrict fmt, ...);
|
||||
void error_fatal(uint ln, const char *restrict file, const char *restrict fmt, ...) NORET;
|
||||
|
||||
#define debug(...) error_debug(__LINE__, __FILE__ __VA_OPT__(, ) __VA_ARGS__)
|
||||
#define info(...) error_info(__LINE__, __FILE__ __VA_OPT__(, ) __VA_ARGS__)
|
||||
#define warn(...) error_warn(__LINE__, __FILE__ __VA_OPT__(, ) __VA_ARGS__)
|
||||
#define error(...) error_error(__LINE__, __FILE__ __VA_OPT__(, ) __VA_ARGS__)
|
||||
#define fatal(...) error_fatal(__LINE__, __FILE__ __VA_OPT__(, ) __VA_ARGS__)
|
||||
Reference in New Issue
Block a user