aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authors-over-42023-06-13 11:59:39 -0400
committers-over-42023-06-13 11:59:39 -0400
commit71adf42ce6801074211caabc5c1618d1ca1c3bcb (patch)
tree64653a0028e3e70d8a5963f85f5a9d0a3ed35c15 /src
parent2c2b197255f05a70172d9d89bc43af438787692f (diff)
util
Diffstat (limited to 'src')
-rw-r--r--src/main.c4
-rw-r--r--src/util.c62
2 files changed, 62 insertions, 4 deletions
diff --git a/src/main.c b/src/main.c
index ceefadd..0c2755a 100644
--- a/src/main.c
+++ b/src/main.c
@@ -2,10 +2,8 @@
#include <stdlib.h>
-#include "include/log.h"
+#include "include/util.h"
#include "include/lexer.h"
-// #include "include/tree.h"
-// #include "include/parser.h"
int main(int argc, char* argv[]) {
diff --git a/src/util.c b/src/util.c
index 32cef99..31878ed 100644
--- a/src/util.c
+++ b/src/util.c
@@ -1,9 +1,31 @@
#include "include/util.h"
+void die(const char* fmt, ...) {
+ va_list ap;
+
+ fprintf(stderr, "== FATAL ERROR ==\n");
+
+ va_start(ap, fmt);
+ vfprintf(stderr, fmt, ap);
+ va_end(ap);
+
+ if (fmt[0] && fmt[strlen(fmt) - 1] == ':') {
+ fputc(' ', stderr);
+ perror(NULL);
+ } else {
+ fputc('\n', stderr);
+ }
+
+ fprintf(stderr, "\n");
+
+ exit(1);
+}
void log_inf(const char* fmt, ...) {
va_list ap;
+ fprintf(stderr, "== INFO ==\n");
+
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
va_end(ap);
@@ -15,5 +37,43 @@ void log_inf(const char* fmt, ...) {
fputc('\n', stderr);
}
- exit(1);
+ fprintf(stderr, "\n");
+}
+
+void log_war(const char* fmt, ...) {
+ va_list ap;
+
+ fprintf(stderr, "== WARNING ==\n");
+
+ va_start(ap, fmt);
+ vfprintf(stderr, fmt, ap);
+ va_end(ap);
+
+ if (fmt[0] && fmt[strlen(fmt) - 1] == ':') {
+ fputc(' ', stderr);
+ perror(NULL);
+ } else {
+ fputc('\n', stderr);
+ }
+
+ fprintf(stderr, "\n");
+}
+
+void log_err(const char* fmt, ...) {
+ va_list ap;
+
+ fprintf(stderr, "== ERROR ==");
+
+ va_start(ap, fmt);
+ vfprintf(stderr, fmt, ap);
+ va_end(ap);
+
+ if (fmt[0] && fmt[strlen(fmt) - 1] == ':') {
+ fputc(' ', stderr);
+ perror(NULL);
+ } else {
+ fputc('\n', stderr);
+ }
+
+ fprintf(stderr, "\n");
}