diff options
Diffstat (limited to 'msg.c')
-rw-r--r-- | msg.c | 53 |
1 files changed, 41 insertions, 12 deletions
@@ -33,21 +33,19 @@ static const char *srcfile = NULL; static int srcline; jmp_buf fatal_tag; -int fatal_tag_valid = FALSE; +bool fatal_tag_valid = false; /* err --- print an error message with source line and file and record */ /* VARARGS2 */ void -err(const char *s, const char *emsg, va_list argp) +err(bool isfatal, const char *s, const char *emsg, va_list argp) { char *file; const char *me; (void) fflush(output_fp); me = myname; - if (strncmp(me, "dgawk", 5) == 0) - me = &myname[1]; (void) fprintf(stderr, "%s: ", me); #ifdef GAWKDEBUG if (srcfile != NULL) { @@ -64,6 +62,21 @@ err(const char *s, const char *emsg, va_list argp) (void) fprintf(stderr, "%d: ", sourceline); } + +#ifdef HAVE_MPFR + if (FNR_node && is_mpg_number(FNR_node->var_value)) { + NODE *val; + val = mpg_update_var(FNR_node); + assert((val->flags & MPZN) != 0); + if (mpz_sgn(val->mpg_i) > 0) { + file = FILENAME_node->var_value->stptr; + (void) putc('(', stderr); + if (file) + (void) fprintf(stderr, "FILENAME=%s ", file); + (void) mpfr_fprintf(stderr, "FNR=%Zd) ", val->mpg_i); + } + } else +#endif if (FNR > 0) { file = FILENAME_node->var_value->stptr; (void) putc('(', stderr); @@ -71,10 +84,18 @@ err(const char *s, const char *emsg, va_list argp) (void) fprintf(stderr, "FILENAME=%s ", file); (void) fprintf(stderr, "FNR=%ld) ", FNR); } + (void) fprintf(stderr, "%s", s); vfprintf(stderr, emsg, argp); (void) fprintf(stderr, "\n"); (void) fflush(stderr); + + if (isfatal) { +#ifdef GAWKDEBUG + abort(); +#endif + gawk_exit(EXIT_FATAL); + } } /* msg --- take a varargs error message and print it */ @@ -84,7 +105,7 @@ msg(const char *mesg, ...) { va_list args; va_start(args, mesg); - err("", mesg, args); + err(false, "", mesg, args); va_end(args); } @@ -95,7 +116,7 @@ warning(const char *mesg, ...) { va_list args; va_start(args, mesg); - err(_("warning: "), mesg, args); + err(false, _("warning: "), mesg, args); va_end(args); } @@ -104,7 +125,7 @@ error(const char *mesg, ...) { va_list args; va_start(args, mesg); - err(_("error: "), mesg, args); + err(false, _("error: "), mesg, args); va_end(args); } @@ -127,12 +148,8 @@ r_fatal(const char *mesg, ...) { va_list args; va_start(args, mesg); - err(_("fatal: "), mesg, args); + err(true, _("fatal: "), mesg, args); va_end(args); -#ifdef GAWKDEBUG - abort(); -#endif - gawk_exit(EXIT_FATAL); } /* gawk_exit --- longjmp out if necessary */ @@ -144,5 +161,17 @@ gawk_exit(int status) exit_val = status; longjmp(fatal_tag, 1); } + + final_exit(status); +} + +/* final_exit --- run extension exit handlers and exit */ + +void +final_exit(int status) +{ + /* run any extension exit handlers */ + run_ext_exit_handlers(status); + exit(status); } |