From dcaab6dd8a28be8885ccc508c49b962a61ab09fe Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Sat, 20 Dec 2014 19:56:44 +0200 Subject: Start at non-fatal output via PROCINFO. --- builtin.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 'builtin.c') diff --git a/builtin.c b/builtin.c index 21c6ed5c..b3f3f333 100644 --- a/builtin.c +++ b/builtin.c @@ -130,9 +130,12 @@ wrerror: gawk_exit(EXIT_FATAL); /* otherwise die verbosely */ - fatal(_("%s to \"%s\" failed (%s)"), from, - rp ? rp->value : _("standard output"), - errno ? strerror(errno) : _("reason unknown")); + if ((rp->flag & RED_NON_FATAL) != 0) { + update_ERRNO_int(errno); + } else + fatal(_("%s to \"%s\" failed (%s)"), from, + rp ? rp->value : _("standard output"), + errno ? strerror(errno) : _("reason unknown")); } /* do_exp --- exponential function */ @@ -1633,7 +1636,7 @@ do_printf(int nargs, int redirtype) FILE *fp = NULL; NODE *tmp; struct redirect *rp = NULL; - int errflg; /* not used, sigh */ + int errflg = 0; NODE *redir_exp = NULL; if (nargs == 0) { @@ -1660,6 +1663,10 @@ do_printf(int nargs, int redirtype) rp = redirect(redir_exp, redirtype, & errflg); if (rp != NULL) fp = rp->output.fp; + else if (errflg) { + update_ERRNO_int(errflg); + return; + } } else if (do_debug) /* only the debugger can change the default output */ fp = output_fp; else @@ -2072,7 +2079,7 @@ void do_print(int nargs, int redirtype) { struct redirect *rp = NULL; - int errflg; /* not used, sigh */ + int errflg = 0; FILE *fp = NULL; int i; NODE *redir_exp = NULL; @@ -2087,6 +2094,10 @@ do_print(int nargs, int redirtype) rp = redirect(redir_exp, redirtype, & errflg); if (rp != NULL) fp = rp->output.fp; + else if (errflg) { + update_ERRNO_int(errflg); + return; + } } else if (do_debug) /* only the debugger can change the default output */ fp = output_fp; else @@ -2142,7 +2153,7 @@ do_print_rec(int nargs, int redirtype) FILE *fp = NULL; NODE *f0; struct redirect *rp = NULL; - int errflg; /* not used, sigh */ + int errflg = 0; NODE *redir_exp = NULL; assert(nargs == 0); @@ -2162,6 +2173,11 @@ do_print_rec(int nargs, int redirtype) if (! field0_valid) (void) get_field(0L, NULL); /* rebuild record */ + if (errflg) { + update_ERRNO_int(errflg); + return; + } + f0 = fields_arr[0]; if (do_lint && (f0->flags & NULL_FIELD) != 0) -- cgit v1.2.3 From 15a1d8d213380bd99b5dfe7f4cafcd6dedb8f0dc Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Sat, 27 Dec 2014 21:20:47 +0200 Subject: Make nonfatal work with stdout & stderr. Update doc more. --- builtin.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'builtin.c') diff --git a/builtin.c b/builtin.c index b3f3f333..e80d46d4 100644 --- a/builtin.c +++ b/builtin.c @@ -129,8 +129,10 @@ wrerror: if (fp == stdout && errno == EPIPE) gawk_exit(EXIT_FATAL); + /* otherwise die verbosely */ - if ((rp->flag & RED_NON_FATAL) != 0) { + if ( (rp != NULL && (rp->flag & RED_NON_FATAL) != 0) + || is_non_fatal_std(fp)) { update_ERRNO_int(errno); } else fatal(_("%s to \"%s\" failed (%s)"), from, -- cgit v1.2.3 From 2f9c84e82632cbce017a6d342acb3dede5e59e12 Mon Sep 17 00:00:00 2001 From: "Arnold D. Robbins" Date: Sun, 8 Feb 2015 19:45:44 +0200 Subject: Reset non-fatal-io to 31 December, add fixes from Andrew Schorr. --- builtin.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'builtin.c') diff --git a/builtin.c b/builtin.c index e80d46d4..aa8caf09 100644 --- a/builtin.c +++ b/builtin.c @@ -131,10 +131,9 @@ wrerror: /* otherwise die verbosely */ - if ( (rp != NULL && (rp->flag & RED_NON_FATAL) != 0) - || is_non_fatal_std(fp)) { + if ((rp != NULL) ? is_non_fatal_redirect(rp->value) : is_non_fatal_std(fp)) update_ERRNO_int(errno); - } else + else fatal(_("%s to \"%s\" failed (%s)"), from, rp ? rp->value : _("standard output"), errno ? strerror(errno) : _("reason unknown")); @@ -1649,7 +1648,7 @@ do_printf(int nargs, int redirtype) redir_exp = TOP(); if (redir_exp->type != Node_val) fatal(_("attempt to use array `%s' in a scalar context"), array_vname(redir_exp)); - rp = redirect(redir_exp, redirtype, & errflg); + rp = redirect(redir_exp, redirtype, & errflg, true); DEREF(redir_exp); decr_sp(); } @@ -1662,7 +1661,7 @@ do_printf(int nargs, int redirtype) redir_exp = PEEK(nargs); if (redir_exp->type != Node_val) fatal(_("attempt to use array `%s' in a scalar context"), array_vname(redir_exp)); - rp = redirect(redir_exp, redirtype, & errflg); + rp = redirect(redir_exp, redirtype, & errflg, true); if (rp != NULL) fp = rp->output.fp; else if (errflg) { @@ -2093,7 +2092,7 @@ do_print(int nargs, int redirtype) redir_exp = PEEK(nargs); if (redir_exp->type != Node_val) fatal(_("attempt to use array `%s' in a scalar context"), array_vname(redir_exp)); - rp = redirect(redir_exp, redirtype, & errflg); + rp = redirect(redir_exp, redirtype, & errflg, true); if (rp != NULL) fp = rp->output.fp; else if (errflg) { @@ -2161,7 +2160,7 @@ do_print_rec(int nargs, int redirtype) assert(nargs == 0); if (redirtype != 0) { redir_exp = TOP(); - rp = redirect(redir_exp, redirtype, & errflg); + rp = redirect(redir_exp, redirtype, & errflg, true); if (rp != NULL) fp = rp->output.fp; DEREF(redir_exp); @@ -2169,17 +2168,17 @@ do_print_rec(int nargs, int redirtype) } else fp = output_fp; + if (errflg) { + update_ERRNO_int(errflg); + return; + } + if (fp == NULL) return; if (! field0_valid) (void) get_field(0L, NULL); /* rebuild record */ - if (errflg) { - update_ERRNO_int(errflg); - return; - } - f0 = fields_arr[0]; if (do_lint && (f0->flags & NULL_FIELD) != 0) -- cgit v1.2.3