aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authors-over-42023-06-13 12:09:17 -0400
committers-over-42023-06-13 12:09:17 -0400
commitd1438b178e922f7eca9c9f63c475d62d75323518 (patch)
treea7799ba46b785d2d3d7396b06fd57c70438a6134 /src
parent71adf42ce6801074211caabc5c1618d1ca1c3bcb (diff)
yet more
Diffstat (limited to 'src')
-rw-r--r--src/include/util.h1
-rw-r--r--src/main.c23
-rw-r--r--src/util.c17
3 files changed, 21 insertions, 20 deletions
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");
}