summaryrefslogtreecommitdiff
path: root/err.c
diff options
context:
space:
mode:
Diffstat (limited to 'err.c')
-rw-r--r--err.c43
1 files changed, 18 insertions, 25 deletions
diff --git a/err.c b/err.c
index a98a822..764d80e 100644
--- a/err.c
+++ b/err.c
@@ -55,44 +55,37 @@ static void err_vfprint(const char *fmt, va_list args) {
}
static void err_print_header_(Location where) {
- if (!where.ctx)
+ if (!where.first)
err_fprint(TEXT_ERROR("error") ":\n");
else {
-#if ERR_EMACS
- err_fprint("%s:%lu: " TEXT_ERROR("error") ":\n", where.ctx->filename, (unsigned long)where.line);
-#else
- err_fprint(TEXT_ERROR("error") " at line %lu of %s:\n", (unsigned long)where.line, where.ctx->filename);
-#endif
+ SourcePos first_pos = where.first->pos;
+ err_fprint(TEXT_ERROR("error") " at line %lu of %s:\n", (unsigned long)first_pos.line, first_pos.ctx->filename);
}
}
static void info_print_header_(Location where) {
- if (!where.ctx)
+ if (!where.first)
err_fprint(TEXT_INFO("info") ":\n");
else {
-#if ERR_EMACS
- err_fprint("%s:%lu: " TEXT_INFO("info") ":\n", where.ctx->filename, (unsigned long)where.line);
-#else
- err_fprint(TEXT_INFO("info") " at line %lu of %s:\n", (unsigned long)where.line, where.ctx->filename);
-#endif
+ SourcePos first_pos = where.first->pos;
+ err_fprint(TEXT_INFO("info") " at line %lu of %s:\n", (unsigned long)first_pos.line, first_pos.ctx->filename);
}
}
static void warn_print_header_(Location where) {
- if (!where.ctx)
+ if (!where.first)
err_fprint(TEXT_WARN("warning") ":\n");
else {
-#if ERR_EMACS
- err_fprint("%s:%lu: " TEXT_WARN("warning") ":\n", where.ctx->filename, (unsigned long)where.line);
-#else
- err_fprint(TEXT_WARN("warning") " at line %lu of %s:\n", (unsigned long)where.line, where.ctx->filename);
-#endif
+ SourcePos first_pos = where.first->pos;
+ err_fprint(TEXT_WARN("warning") " at line %lu of %s:\n", (unsigned long)first_pos.line, first_pos.ctx->filename);
}
}
static void err_print_location_text(Location where) {
- if (where.ctx) {
- const char *text = where.ctx->str + where.pos;
+ if (where.first) {
+ SourcePos first_pos = where.first->pos;
+ ErrCtx *ctx = first_pos.ctx;
+ const char *text = ctx->str + first_pos.start;
const char *end = strchr(text, '\n');
int has_newline = end != NULL;
if (!has_newline)
@@ -111,7 +104,7 @@ static void err_print_location_text(Location where) {
}
static void err_print_footer_(Location where) {
- ErrCtx *ctx = where.ctx;
+ ErrCtx *ctx = where.first->pos.ctx;
err_fprint("\n");
err_print_location_text(where);
if (ctx) {
@@ -126,7 +119,7 @@ static void err_print_footer_(Location where) {
static void err_vprint(Location where, const char *fmt, va_list args) {
- if (where.ctx && !where.ctx->enabled) return;
+ if (location_is_ctx_disabled(where)) return;
err_print_header_(where);
err_vfprint(fmt, args);
err_print_footer_(where);
@@ -140,7 +133,7 @@ static void err_print_(
Location where, const char *fmt, ...) {
va_list args;
#if ERR_SHOW_SOURCE_LOCATION
- if (where.ctx && !where.ctx->enabled) return;
+ if (location_is_ctx_disabled(where)) return;
if (file)
err_fprint("Generated by line %d of %s:\n", line, file);
#endif
@@ -157,7 +150,7 @@ static void err_print_(
static void info_print(Location where, const char *fmt, ...) {
va_list args;
- if (where.ctx && !where.ctx->enabled) return;
+ if (location_is_ctx_disabled(where)) return;
va_start(args, fmt);
info_print_header_(where);
err_vfprint(fmt, args);
@@ -171,7 +164,7 @@ static void warn_print_(
#endif
Location where, const char *fmt, ...) {
va_list args;
- if (where.ctx && !where.ctx->enabled) return;
+ if (location_is_ctx_disabled(where)) return;
#if ERR_SHOW_SOURCE_LOCATION
if (file)
err_fprint("Generated by line %d of %s:\n", line, file);