diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2009-11-02 13:58:30 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2009-11-02 13:58:30 -0800 |
commit | 6191fbb2ca7a9ac339dd3994bdea8273ceb0a24d (patch) | |
tree | 3ddb47f26c66c5e4d09dd87f4518468f489f84a3 /match.c | |
parent | 4b493073a6deafa6b4ac6386a0eab034e0e20082 (diff) | |
download | txr-6191fbb2ca7a9ac339dd3994bdea8273ceb0a24d.tar.gz txr-6191fbb2ca7a9ac339dd3994bdea8273ceb0a24d.tar.bz2 txr-6191fbb2ca7a9ac339dd3994bdea8273ceb0a24d.zip |
Start of implementation for freestyle matching.
Lazy strings implemented, incompletely.
Changed string function to implicitly strdup; non-strdup
version changed to string_own. Fixed wrong uses of strdup
rather than chk_strdup.
Functions added to regex module to provide regex matching
as a state machine to which characters are fed.
Diffstat (limited to 'match.c')
-rw-r--r-- | match.c | 35 |
1 files changed, 31 insertions, 4 deletions
@@ -902,7 +902,7 @@ obj_t *match_files(obj_t *spec, obj_t *files, return nil; } else if (errno != 0) file_err(nil, "could not open ~a (error ~a/~a)", name, - num(errno), string(strdup(strerror(errno))), nao); + num(errno), string(strerror(errno)), nao); else file_err(nil, "could not open ~a", name, nao); return nil; @@ -983,6 +983,33 @@ repeat_spec_same_data: return cons(new_bindings, cons(data, num(data_lineno))); return nil; } + } else if (sym == freeform) { + if ((spec = rest(spec)) == nil) { + sem_error(spec_linenum, + "freeform must be followed by a query line", nao); + } else { + obj_t *ff_specline = rest(first(spec)); + obj_t *ff_dataline = lazy_str(data); + + cons_bind (new_bindings, success, + match_line(bindings, ff_specline, ff_dataline, zero, + spec_linenum, num(data_lineno), first(files))); + + if (!success) { + debuglf(spec_linenum, "freeform match failure", nao); + return nil; + } + + if (nump(success)) + data = lazy_str_get_trailing_list(ff_dataline, success); + + bindings = new_bindings; + } + + if ((spec = rest(spec)) == nil) + break; + + goto repeat_spec_same_data; } else if (sym == block) { obj_t *name = first(rest(first_spec)); if (rest(specline)) @@ -1027,7 +1054,7 @@ repeat_spec_same_data: if (eq(first(source), nothrow)) push(nil, &source); else if (eq(first(source), args)) { - obj_t *input_name = string(strdup("args")); + obj_t *input_name = string("args"); cons_bind (new_bindings, success, match_files(spec, cons(input_name, files), bindings, files, one)); @@ -1378,7 +1405,7 @@ repeat_spec_same_data: form, nao); nt = eq(second(new_style_dest), nothrow); - dest = or2(cdr(val), string(strdup("-"))); + dest = or2(cdr(val), string("-")); } } @@ -1393,7 +1420,7 @@ repeat_spec_same_data: return nil; } else if (errno != 0) { file_err(nil, "could not open ~a (error ~a/~a)", dest, - num(errno), string(strdup(strerror(errno))), nao); + num(errno), string(strerror(errno)), nao); } else { file_err(nil, "could not open ~a", dest, nao); } |