mirror of
https://github.com/thepigeongenerator/mcaselector-lite.git
synced 2025-12-18 20:35:45 +01:00
Compare commits
2 Commits
527b1e2b16
...
c6c9cc147e
| Author | SHA1 | Date | |
|---|---|---|---|
| c6c9cc147e | |||
| 63df7430b7 |
@@ -117,5 +117,5 @@ size_t mcx_calcsize(const u8 *restrict buf) {
|
|||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
for (uint i = 0; i < CHUNKS; i++)
|
for (uint i = 0; i < CHUNKS; i++)
|
||||||
size += *(buf + (i * 4) + 3);
|
size += *(buf + (i * 4) + 3);
|
||||||
return (size * CHUNKS) + (TABLE * 4);
|
return (size * SECTOR) + (TABLE * 4);
|
||||||
}
|
}
|
||||||
|
|||||||
51
src/error.c
Normal file
51
src/error.c
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
#include "error.h"
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "util/intdef.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:%lu) [%s] '", file, ln, pfx);
|
||||||
|
|
||||||
|
vfprintf(stream, fmt, ap);
|
||||||
|
|
||||||
|
fprintf(stream, "'\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
void error_dbg(uint ln, const char *restrict file, const char *restrict fmt, ...) {
|
||||||
|
va_list ap;
|
||||||
|
va_start(ap, fmt);
|
||||||
|
error_log(stdout, "\033[95mDBG\033[0m", ln, file, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
}
|
||||||
|
|
||||||
|
void error_inf(uint ln, const char *restrict file, const char *restrict fmt, ...) {
|
||||||
|
va_list ap;
|
||||||
|
va_start(ap, fmt);
|
||||||
|
error_log(stdout, "\033[93mINF\033[0m", ln, file, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
}
|
||||||
|
|
||||||
|
void error_war(uint ln, const char *restrict file, const char *restrict fmt, ...) {
|
||||||
|
va_list ap;
|
||||||
|
va_start(ap, fmt);
|
||||||
|
error_log(stdout, "\033[91mWAR\033[0m", ln, file, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
}
|
||||||
|
|
||||||
|
void error_err(uint ln, const char *restrict file, const char *restrict fmt, ...) {
|
||||||
|
va_list ap;
|
||||||
|
va_start(ap, fmt);
|
||||||
|
error_log(stdout, "\033[mFAT\033[0m", ln, file, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
}
|
||||||
|
|
||||||
|
void error_fat(uint ln, const char *restrict file, const char *restrict fmt, ...) {
|
||||||
|
va_list ap;
|
||||||
|
va_start(ap, fmt);
|
||||||
|
error_log(stdout, "\033[mFAT\033[0m", ln, file, fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
23
src/error.h
23
src/error.h
@@ -2,20 +2,21 @@
|
|||||||
* Licensed under the MIT Licence. See LICENSE for details */
|
* Licensed under the MIT Licence. See LICENSE for details */
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#if __INCLUDE_LEVEL__ > 0
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "util/atrb.h"
|
||||||
|
#include "util/intdef.h"
|
||||||
#include "util/macro.h"
|
#include "util/macro.h"
|
||||||
#endif
|
|
||||||
|
|
||||||
#define debug(s, ...) printf("\033[95m" __FILE__ ":" MACRO_STR2(__LINE__) ": [DBG]: " s "\033[0m\n", ##__VA_ARGS__)
|
void error_dbg(uint ln, const char *restrict file, const char *restrict fmt, ...);
|
||||||
#define info(s, ...) printf(__FILE__ ":" MACRO_STR2(__LINE__) ": [INF]: " s "\n", ##__VA_ARGS__)
|
void error_inf(uint ln, const char *restrict file, const char *restrict fmt, ...);
|
||||||
#define warn(s, ...) fprintf(stderr, "\033[93m" __FILE__ ":" MACRO_STR2(__LINE__) ": [WAR]: " s "\033[0m\n", ##__VA_ARGS__)
|
void error_war(uint ln, const char *restrict file, const char *restrict fmt, ...);
|
||||||
#define error(s, ...) fprintf(stderr, "\033[91m" __FILE__ ":" MACRO_STR2(__LINE__) ": [ERR]: " s "\033[0m\n", ##__VA_ARGS__)
|
void error_err(uint ln, const char *restrict file, const char *restrict fmt, ...);
|
||||||
|
void error_fat(uint ln, const char *restrict file, const char *restrict fmt, ...) NORET;
|
||||||
|
|
||||||
#define fatal(s, ...) \
|
#define debug(s, ...) error_dbg(__LINE__, __FILE__, s, ##__VA_ARGS__)
|
||||||
do { \
|
#define info(s, ...) error_inf(__LINE__, __FILE__, s, ##__VA_ARGS__)
|
||||||
fprintf(stderr, "\033[101m" __FILE__ ":" MACRO_STR2(__LINE__) ": [FAT]: " s "\033[0m\n", ##__VA_ARGS__); \
|
#define warn(s, ...) error_war(__LINE__, __FILE__, s, ##__VA_ARGS__)
|
||||||
exit(EXIT_FAILURE); \
|
#define error(s, ...) error_err(__LINE__, __FILE__, s, ##__VA_ARGS__)
|
||||||
} while (0)
|
#define fatal(s, ...) error_fat(__LINE__, __FILE__, s, ##__VA_ARGS__)
|
||||||
|
|||||||
Reference in New Issue
Block a user