summaryrefslogtreecommitdiffstats
path: root/match.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2011-10-26 00:20:57 -0400
committerKaz Kylheku <kaz@kylheku.com>2011-10-26 00:20:57 -0400
commit6d7e225fa1dded120dd959074c0d269c38459713 (patch)
treed399065394b3dcf5228e0a253036029125ab5206 /match.c
parent2987f69f690d8433ad3aaa9e9f41949455ada2cb (diff)
downloadtxr-6d7e225fa1dded120dd959074c0d269c38459713.tar.gz
txr-6d7e225fa1dded120dd959074c0d269c38459713.tar.bz2
txr-6d7e225fa1dded120dd959074c0d269c38459713.zip
Fixed lame @(cat) directive, without obsolescence phase.
* match.c (v_cat): Rewritten. * txr.1: Documented.
Diffstat (limited to 'match.c')
-rw-r--r--match.c31
1 files changed, 15 insertions, 16 deletions
diff --git a/match.c b/match.c
index 5fe8782f..4b163af8 100644
--- a/match.c
+++ b/match.c
@@ -2242,25 +2242,24 @@ static val v_set(match_files_ctx c, match_files_ctx *cout)
static val v_cat(match_files_ctx c, match_files_ctx *cout)
{
spec_bind (specline, spec_linenum, first_spec, c.spec);
- val iter;
+ val sym = second(first_spec);
+ val sep_form = third(first_spec);
- for (iter = rest(first_spec); iter; iter = rest(iter)) {
- val sym = first(iter);
+ if (rest(specline))
+ sem_error(spec_linenum, lit("cat: obsolete syntax"));
- if (!bindable(sym)) {
- sem_error(spec_linenum,
- lit("cat: ~s is not a bindable symbol"), sym, nao);
+ if (!bindable(sym)) {
+ sem_error(spec_linenum,
+ lit("cat: ~s is not a bindable symbol"), sym, nao);
+ } else {
+ val existing = assoc(c.bindings, sym);
+ if (existing) {
+ val sep = if3(sep_form,
+ cdr(eval_form(spec_linenum, sep_form, c.bindings)),
+ lit(" "));
+ *cdr_l(existing) = cat_str(flatten(cdr(existing)), sep);
} else {
- val existing = assoc(c.bindings, sym);
- val sep = nil;
-
- if (rest(specline)) {
- val sub = subst_vars(rest(specline), c.bindings, nil);
- sep = cat_str(sub, nil);
- }
-
- if (existing)
- *cdr_l(existing) = cat_str(flatten(cdr(existing)), sep);
+ sem_error(spec_linenum, lit("cat: unbound variable ~s"), sym, nao);
}
}