diff options
Diffstat (limited to 'err.c')
-rw-r--r-- | err.c | 68 |
1 files changed, 40 insertions, 28 deletions
@@ -56,57 +56,69 @@ static void err_vfprint(const char *fmt, va_list args) { static void err_print_header_(Location where) { if (!where.ctx) - err_fprint("Error (no location available):\n"); + 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); + 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); + err_fprint(TEXT_ERROR("error") " at line %lu of %s:\n", (unsigned long)where.line, where.ctx->filename); #endif + } } static void info_print_header_(Location where) { if (!where.ctx) - err_fprint("Info (no location available):\n"); + 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); + 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); + err_fprint(TEXT_INFO("info") " at line %lu of %s:\n", (unsigned long)where.line, where.ctx->filename); #endif + } } static void warn_print_header_(Location where) { if (!where.ctx) - err_fprint("Warning (no location available):\n"); + 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); + 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); + err_fprint(TEXT_WARN("warning") " at line %lu of %s:\n", (unsigned long)where.line, where.ctx->filename); #endif + } } static void err_print_location_text(Location where) { - const char *text = where.ctx->str + where.pos; - const char *end = strchr(text, '\n'); - int has_newline = end != NULL; - if (!has_newline) - end = strchr(text, '\0'); - assert(end); - err_fprint("\there: --> "); - if (!text[0]) - err_fprint("<end of file>"); - else - err_fwrite(text, 1, (size_t)(end - text)); - err_fprint("\n"); + if (where.ctx) { + const char *text = where.ctx->str + where.pos; + const char *end = strchr(text, '\n'); + int has_newline = end != NULL; + if (!has_newline) + end = strchr(text, '\0'); + assert(end); + err_fprint("\there: --> "); + if (!text[0]) + err_fprint("<end of file>"); + else + err_fwrite(text, 1, (size_t)(end - text)); + err_fprint("\n"); + } else { + err_fprint("\t<no location available>"); + } } static void err_print_footer_(Location where) { ErrCtx *ctx = where.ctx; - err_fprint("\n"); + err_fprint("\n"); err_print_location_text(where); - arr_foreach(ctx->instance_stack, Location, inst) { - err_fprint("While generating the instance of a function\n"); - err_print_location_text(*inst); + if (ctx) { + arr_foreach(ctx->instance_stack, Location, inst) { + err_fprint("While generating the instance of a function\n"); + err_print_location_text(*inst); + } } } @@ -127,7 +139,7 @@ static void err_print_( #endif Location where, const char *fmt, ...) { va_list args; - if (!where.ctx->enabled) return; + if (where.ctx && !where.ctx->enabled) return; #if ERR_SHOW_SOURCE_LOCATION if (file) err_fprint("Generated by line %d of %s:\n", line, file); @@ -145,7 +157,7 @@ static void err_print_( static void info_print(Location where, const char *fmt, ...) { va_list args; - if (!where.ctx->enabled) return; + if (where.ctx && !where.ctx->enabled) return; va_start(args, fmt); info_print_header_(where); err_vfprint(fmt, args); @@ -159,7 +171,7 @@ static void warn_print_( #endif Location where, const char *fmt, ...) { va_list args; - if (!where.ctx->enabled) return; + if (where.ctx && !where.ctx->enabled) return; #if ERR_SHOW_SOURCE_LOCATION if (file) err_fprint("Generated by line %d of %s:\n", line, file); |