From d1438b178e922f7eca9c9f63c475d62d75323518 Mon Sep 17 00:00:00 2001 From: s-over-4 Date: Tue, 13 Jun 2023 12:09:17 -0400 Subject: yet more --- src/include/util.h | 1 + src/main.c | 23 ++++++++++------------- src/util.c | 17 ++++++++++------- 3 files changed, 21 insertions(+), 20 deletions(-) (limited to 'src') 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, ...); diff --git a/src/main.c b/src/main.c index 0c2755a..3b346de 100644 --- a/src/main.c +++ b/src/main.c @@ -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; } diff --git a/src/util.c b/src/util.c index 31878ed..5bdabfa 100644 --- a/src/util.c +++ b/src/util.c @@ -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"); } -- cgit v1.2.3