diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2016-01-01 23:44:08 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2016-01-01 23:44:08 -0800 |
commit | eb7ec6f6bb7ba84fa294bc6ab6dd1c03c65264e4 (patch) | |
tree | 9a79e635e069e40dc8a6ecaf547c903e68ffba93 /match.c | |
parent | 25a723161aa450c2f2e699c73f4ba34c98b36ea1 (diff) | |
download | txr-eb7ec6f6bb7ba84fa294bc6ab6dd1c03c65264e4.tar.gz txr-eb7ec6f6bb7ba84fa294bc6ab6dd1c03c65264e4.tar.bz2 txr-eb7ec6f6bb7ba84fa294bc6ab6dd1c03c65264e4.zip |
Handle nothrow semantics down in complex_open.
* match.c (file_err): Static function removed.
(complex_open): New argument, nothrow.
Catch exceptions derived from error only if
nothrow is true.
(v_output, open_data_source): Pass nothrow flag down to
complex_open. Eliminate unnecessary error checking.
Diffstat (limited to 'match.c')
-rw-r--r-- | match.c | 49 |
1 files changed, 12 insertions, 37 deletions
@@ -102,21 +102,6 @@ static void sem_error(val form, val fmt, ...) abort(); } -static void file_err(val form, val fmt, ...) -{ - va_list vl; - val stream = make_string_output_stream(); - - va_start (vl, fmt); - if (form) - format(stream, lit("(~a) "), source_loc_str(form, colon_k), nao); - (void) vformat(stream, fmt, vl); - va_end (vl); - - uw_throw(file_error_s, get_string_from_stream(stream)); - abort(); -} - static void typed_error(val type, val form, val fmt, ...) { va_list vl; @@ -1544,7 +1529,7 @@ static val txeval_allow_ub(val spec, val form, val bindings) return do_txeval(spec, form, bindings, t); } -static val complex_open(val name, val output, val append) +static val complex_open(val name, val output, val append, val nothrow) { val fc = car(name); val result = nil; @@ -1553,7 +1538,7 @@ static val complex_open(val name, val output, val append) uw_throwf(query_error_s, lit("cannot output to directory: ~a"), name, nao); - uw_catch_begin (cons(error_s, nil), exc_sym, exc); + uw_catch_begin (if2(nothrow, cons(error_s, nil)), exc_sym, exc); if (fc == chr('-')) { result = output ? std_output : std_input; @@ -3213,21 +3198,14 @@ static val v_output(match_files_ctx *c) return next_spec_k; } - stream = complex_open(dest, t, append); + stream = complex_open(dest, t, append, nothrow); debuglf(specline, lit("opening data sink ~a"), dest, nao); if (!stream) { - if (nothrow) { - debuglf(specline, lit("could not open ~a: " - "treating as failed match due to nothrow"), dest, nao); - return nil; - } else if (errno != 0) { - file_err(specline, lit("could not open ~a (error ~d/~s)"), dest, - num(errno), string_utf8(strerror(errno)), nao); - } else { - file_err(specline, lit("could not open ~a"), dest, nao); - } + debuglf(specline, lit("could not open ~a: " + "treating as failed match due to nothrow"), dest, nao); + return nil; } else { do_output(c->bindings, specs, filter, stream); flush_stream(stream); @@ -3843,7 +3821,9 @@ static void open_data_source(match_files_ctx *c) if (c->data == t && c->files) { val source_spec = first(c->files); - val name = consp(source_spec) ? cdr(source_spec) : source_spec; + val ss_consp = consp(source_spec); + val name = ss_consp ? cdr(source_spec) : source_spec; + val nothrow = tnil(ss_consp && car(source_spec) == nothrow_k); if (stringp(name)) { val stream = complex_open(name, nil, nil); @@ -3857,17 +3837,12 @@ static void open_data_source(match_files_ctx *c) "directive."), name, nao); } else { val spec = first(c->spec); + debuglf(spec, lit("opening data source ~a"), name, nao); if (!stream) { - if (consp(source_spec) && car(source_spec) == nothrow_k) - debuglf(spec, lit("could not open ~a: " - "treating as failed match due to nothrow"), name, nao); - else if (errno != 0) - file_err(spec, lit("could not open ~a (error ~d/~s)"), name, - num(errno), string_utf8(strerror(errno)), nao); - else - file_err(spec, lit("could not open ~a"), name, nao); + debuglf(spec, lit("could not open ~a: " + "treating as failed match due to nothrow"), name, nao); c->data = nil; return; } |