diff options
-rw-r--r-- | Makefile | 4 | ||||
-rwxr-xr-x | halk | bin | 26064 -> 31096 bytes | |||
-rw-r--r-- | src/main.c | 4 | ||||
-rw-r--r-- | src/util.c | 62 |
4 files changed, 64 insertions, 6 deletions
@@ -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 Binary files differ@@ -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[]) { @@ -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"); } |