From 64efc4d32dfbe8f1a864ff9fdcc6e55d7f408088 Mon Sep 17 00:00:00 2001 From: veradec Date: Sun, 3 May 2026 21:49:27 +0530 Subject: [PATCH] feat: parse into head lib --- README.md | 4 ++-- sonuva.c | 36 ++---------------------------------- sonuva.h | 45 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 36 deletions(-) create mode 100644 sonuva.h diff --git a/README.md b/README.md index c575d70..0180cd7 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,8 @@ sonuva is a c helper single header library -feat: -[ ] LOG +feat: +[ ] Log [ ] String Tokenizer [ ] File I/O diff --git a/sonuva.c b/sonuva.c index 38400dc..37e4326 100644 --- a/sonuva.c +++ b/sonuva.c @@ -1,37 +1,5 @@ -#include -#include -#include -#include - - -/* I took it from stack overflow man stop asking me questions */ -#define NARGS(...) NARGS_(__VA_ARGS__, 5, 4, 3, 2, 1, 0) -#define NARGS_(_5, _4, _3, _2, _1, N, ...) N - -#define LOGG(A, B) LOGG_(A, B) -#define LOGG_(A, B) A##B - -#define LOG(...) LOGG(LOG, NARGS(__VA_ARGS__))(__VA_ARGS__) - - -void LOG1(char *str) { printf("\e[0;34m+ [INFO] \e[0m%s\n", str); } - -void LOG2(char *str, char *level) { - if (strcmp(level, "warn") == 0) { - printf("\e[0;33m! [WARN] \e[0m%s\n", str); - return; - } - - if (strcmp(level, "fatal") == 0) { - printf("\e[0;31m!! [FATAL] \e[0m%s\n", str); - exit(1); - } - - if (strcmp(level, "todo") == 0) { - printf("+ [TODO] %s\n", str); - } -} - +#define SONUVA_IMPLEMENTATION +#include "sonuva.h" int main() { diff --git a/sonuva.h b/sonuva.h new file mode 100644 index 0000000..6a5a348 --- /dev/null +++ b/sonuva.h @@ -0,0 +1,45 @@ +#ifdef SONUVA_IMPLEMENTATION + +#include +#include +#include +#include + + +#define NARGS(...) NARGS_(__VA_ARGS__, 5, 4, 3, 2, 1, 0) +#define NARGS_(_5, _4, _3, _2, _1, N, ...) N + +#define LOGG(A, B) LOGG_(A, B) +#define LOGG_(A, B) A##B + +#define LOG(...) LOGG(LOG, NARGS(__VA_ARGS__))(__VA_ARGS__) + +void LOG1(char *str); +void LOG2(char *str, char* level); + + +void LOG1(char *str) { printf("\e[0;34m+ [INFO] \e[0m%s\n", str); } + +void LOG2(char *str, char *level) { + if (strcmp(level, "warn") == 0) { + printf("\e[0;33m! [WARN] \e[0m%s\n", str); + return; + } + + if (strcmp(level, "fatal") == 0) { + printf("\e[0;31m!! [FATAL] \e[0m%s\n", str); + exit(1); + } + + if (strcmp(level, "todo") == 0) { + printf("+ [TODO] %s\n", str); + } +} + + + +#endif // SONUVA_IMPLEMENTATION + + +/* I took it from stack overflow man stop asking me questions */ +