aboutsummaryrefslogtreecommitdiff
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
parent2c2b197255f05a70172d9d89bc43af438787692f (diff)
util
-rw-r--r--Makefile4
-rwxr-xr-xhalkbin26064 -> 31096 bytes
-rw-r--r--src/main.c4
-rw-r--r--src/util.c62
4 files changed, 64 insertions, 6 deletions
diff --git a/Makefile b/Makefile
index df0a9bb..6628a8b 100644
--- a/Makefile
+++ b/Makefile
@@ -13,10 +13,10 @@ $(name): $(objects)
install:
make
- [ $(XDG_DATA_HOME) ] && cp ./$(name) $(XDG_DATA_HOME)/bin/$(name) || cp ./$(name) /usr/local/bin/$(name)
+ cp ./$(name) $(HOME)/.local/bin/$(name)
uninstall:
- [ $(XDG_DATA_HOME) ] && rm -f $(XDG_DATA_HOME)/bin/$(name) || rm -f /usr/local/bin/$(name)
+ rm -f $(HOME)/.local/bin/$(name)
clean:
rm -f ./$(name) ./src/*.o
diff --git a/halk b/halk
index 10f533e..3be1165 100755
--- a/halk
+++ b/halk
Binary files differ
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");
}