summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/lexer.c5
-rw-r--r--core/parser.c11
-rw-r--r--head/defconf/trace.h14
3 files changed, 23 insertions, 7 deletions
diff --git a/core/lexer.c b/core/lexer.c
index 72aa942..ac5194f 100644
--- a/core/lexer.c
+++ b/core/lexer.c
@@ -9,6 +9,7 @@
#include <string.h>
#include "defconf/lexer.h"
#include "defconf/ptrbox.h"
+#include "defconf/trace.h"
/* Constants */
#define MAX_KW_LEN 32
@@ -107,7 +108,7 @@ lexer_scan_ident(struct defconf_state *state, int lc)
buf[bufind++] = lc;
for (;;) {
if (bufind >= sizeof(buf) - 1) {
- printf("fatal: token exceeds maximum length\n");
+ trace_fatal(state, "token exceeds maximum length\n");
return NULL;
}
@@ -191,6 +192,6 @@ lexer_scan(struct defconf_state *state, struct token *result)
return 0;
}
- printf("fatal: unexpected token '%c'\n", c);
+ trace_fatal(state, "unexpected token '%c'\n", c);
return -1;
}
diff --git a/core/parser.c b/core/parser.c
index e568504..698691e 100644
--- a/core/parser.c
+++ b/core/parser.c
@@ -8,6 +8,7 @@
#include "defconf/token.h"
#include "defconf/data.h"
#include "defconf/emit.h"
+#include "defconf/trace.h"
/* Symbolic token */
#define SYMTOK(TOKSTR) \
@@ -74,12 +75,12 @@ parse_expect(struct defconf_state *state, struct token *tok, tt_t exp)
/* Try to grab the next token */
if ((error = lexer_scan(state, tok)) < 0) {
- printf("fatal: expected '%s', got eof\n", TOKSTR(exp));
+ trace_fatal(state, "expected '%s', got eof\n", TOKSTR(exp));
return error;
}
if (tok->type != exp) {
- printf("fatal: expected '%s', got %s instead\n",
+ trace_fatal(state, "expected '%s', got %s instead\n",
TOKSTR(exp), TOKSTR(tok->type));
return -1;
}
@@ -116,13 +117,13 @@ parse_define(struct defconf_state *state, struct token *tok)
/* Scan the value */
if ((error = lexer_scan(state, tok)) < 0) {
- printf("fatal: expected value, got eof\n");
+ trace_fatal(state, "expected value, got eof\n");
return error;
}
/* Convert token to data */
if ((error = token_to_data(tok, &value)) < 0) {
- printf("fatal: got bad data [%s]\n", TOKSTR(tok->type));
+ trace_fatal(state, "got bad data [%s]\n", TOKSTR(tok->type));
return error;
}
@@ -153,7 +154,7 @@ parse_begin(struct defconf_state *state)
break;
default:
- printf("fatal: got unexpected token: %s\n", TOKSTR(tok.type));
+ trace_fatal(state, "got unexpected token: %s\n", TOKSTR(tok.type));
return -1;
}
}
diff --git a/head/defconf/trace.h b/head/defconf/trace.h
new file mode 100644
index 0000000..30f2184
--- /dev/null
+++ b/head/defconf/trace.h
@@ -0,0 +1,14 @@
+/*
+ * Copyright (c) 2026, Apollo Telephone Laboratories.
+ * Provided under the BSD-3 clause.
+ */
+
+#ifndef DEFCONF_TRACE_H
+#define DEFCONF_TRACE_H 1
+
+#include <stdio.h>
+
+#define trace_fatal(state, fmt, ...) \
+ printf("fatal: " fmt, ##__VA_ARGS__)
+
+#endif /* !DEFCONF_TRACE_H */