diff options
author | s-over-4 | 2023-06-13 12:09:17 -0400 |
---|---|---|
committer | s-over-4 | 2023-06-13 12:09:17 -0400 |
commit | d1438b178e922f7eca9c9f63c475d62d75323518 (patch) | |
tree | a7799ba46b785d2d3d7396b06fd57c70438a6134 | |
parent | 71adf42ce6801074211caabc5c1618d1ca1c3bcb (diff) |
yet more
-rwxr-xr-x | halk | bin | 31096 -> 31144 bytes | |||
-rw-r--r-- | src/include/util.h | 1 | ||||
-rw-r--r-- | src/main.c | 23 | ||||
-rw-r--r-- | src/util.c | 17 |
4 files changed, 21 insertions, 20 deletions
Binary files differ diff --git a/src/include/util.h b/src/include/util.h index 500fb5f..a8efe7a 100644 --- a/src/include/util.h +++ b/src/include/util.h @@ -8,6 +8,7 @@ void log_inf(const char* fmt, ...); +void log_raw(const char* fmt, ...); void log_war(const char* fmt, ...); void log_err(const char* fmt, ...); void die(const char* fmt, ...); @@ -13,8 +13,7 @@ int main(int argc, char* argv[]) { fsource = fopen("examples/hello.halk", "rb"); if (!fsource) { - log_err("Source file not found"); - exit(1); + die("source file not found: %s", "examples/hello.halk"); }; fseek(fsource, 0L, SEEK_END); @@ -25,36 +24,34 @@ int main(int argc, char* argv[]) { if (!source) { fclose(fsource); - log_err("Memory allocation failed"); - exit(1); + die("calloc failed"); } if (1 != fread(source, fsource_size, 1, fsource)) { fclose(fsource); free(source); - log_err("Could not read source file"); - exit(1); + die("could not read source"); } - log_inf("Source file loaded"); + log_inf("source file loaded"); lexer_t* lexer = lexer_init(source); - log_inf("Lexer created"); + log_inf("lexer created"); - log_inf("== BEGIN INPUT =="); - log_inf(lexer->content); - log_inf("=== END INPUT ==="); + log_inf("BEGIN INPUT"); + log_raw(lexer->content); + log_inf("END INPUT"); token_t* token = NULL; while ((token = lexer_get_next_token(lexer)) != NULL) { - printf("===\ntoken type: %d:\ntoken value: || %s ||\n===\n", token->type, token->value); + log_inf("token type: [%d]\ttoken value: [%s]", token->type, token->value); } fclose(fsource); free(source); - log_inf("Source file closed"); + log_inf("source file closed"); return 0; } @@ -24,18 +24,21 @@ void die(const char* fmt, ...) { void log_inf(const char* fmt, ...) { va_list ap; - fprintf(stderr, "== INFO ==\n"); + fprintf(stderr, "== "); 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_raw(const char* fmt, ...) { + va_list ap; + + va_start(ap, fmt); + vfprintf(stderr, fmt, ap); + va_end(ap); fprintf(stderr, "\n"); } |