From 4ce8dde9cafa8a77a0c623043fded0a751ad4b02 Mon Sep 17 00:00:00 2001
From: Kaz Kylheku <kaz@kylheku.com>
Date: Sun, 25 Sep 2011 10:28:41 -0700
Subject: Filtering feature for variable substitution in output.

* filter.c, filter.h: New files.

* Makefile (OBJS): filter.o added.

* gc.c (mark_obj): Mark new alloc field of string objets.

* hash.c (struct hash): New member, userdata.
(hash_mark): Mark new userdata member of hash.
(make_hash): Initialize userdata.
(get_hash_userdata, set_hash_userdata, hashp): New functions.

* hash.h (get_hash_userdata, set_hash_userdata, hashp): New functions
declared.

* lib.c (getplist, string_extend, cobjp): New functions.
(string_own, string, string_utf8): Initialize new alloc field to nil.
(mkstring, mkustring): Initialize new alloc field to actual size.
(length_str): When length is computed and cached, also compute
and cache alloc.
(init): Call filter_init.

* lib.h (string string): New member, alloc.
(num_fast): Macro converted to inline function.
(getplist, string_extend, cobjp): New functions declared.

* match.c (match_line): Follows change of modifier s-exp syntax.
(format_field): New parameter, filter.
New modifier syntax parsed. Filter retrieved, and applied.
(subst_vars): New parameter, filter. Filter is either applied
in this function or passed to format_field, as needed.
(eval_form): Pass nil to new parameter of subst_vars.
(do_output_line): New parameter, filter. Passed down to subst_vars.
(do_output): New parameter, filter. Passed down to do_output_line.
(match_files): Pass nil filter to subst_vars in cat directive.
Output directive refactored to parse keywords, extract the
filter and pass down to do_output.

* parser.y (regex): Generate (sys:regex regex syntax ...)
instead of (regex syntax ...).
(elem, expr): Updated w.r.t. regex syntax change.
(var): Cases '{' IDENT regex '}' and '{' IDENT NUMBER '}'
are removed. new syntax '{' IDENT exprs '}' to handle these
more generally and allow for keywords.

* txr.1: Updated.
---
 lib.h | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

(limited to 'lib.h')

diff --git a/lib.h b/lib.h
index 7b69cbbf..f72111e4 100644
--- a/lib.h
+++ b/lib.h
@@ -68,6 +68,7 @@ struct string {
   type_t type;
   wchar_t *str;
   val len;
+  val alloc;
 };
 
 struct sym {
@@ -201,6 +202,11 @@ INLINE wchar_t *litptr(val obj)
  return (wchar_t *) ((cnum) obj & ~TAG_MASK);
 }
 
+INLINE val num_fast(cnum n)
+{
+  return (val) ((n << TAG_SHIFT) | TAG_NUM);
+}
+
 #define lit_noex(strlit) ((obj_t *) ((cnum) (L ## strlit) | TAG_LIT))
 #define lit(strlit) lit_noex(strlit)
 
@@ -277,6 +283,7 @@ val atom(val obj);
 val listp(val obj);
 val proper_listp(val obj);
 val length(val list);
+val getplist(val list, val key);
 val num(cnum val);
 cnum c_num(val num);
 val nump(val num);
@@ -298,6 +305,7 @@ val mkstring(val len, val ch);
 val mkustring(val len); /* must initialize immediately with init_str! */
 val init_str(val str, const wchar_t *);
 val copy_str(val str);
+val string_extend(val str, val tail);
 val stringp(val str);
 val lazy_stringp(val str);
 val length_str(val str);
@@ -357,6 +365,7 @@ val length_str_ge(val str, val len);
 val length_str_lt(val str, val len);
 val length_str_le(val str, val len);
 val cobj(mem_t *handle, val cls_sym, struct cobj_ops *ops);
+val cobjp(val obj);
 mem_t *cobj_handle(val cobj, val cls_sym);
 val assoc(val list, val key);
 val acons_new(val list, val key, val value);
@@ -428,7 +437,6 @@ val match(val spec, val data);
   obj_t *CAR = car(c_o_n_s ## CAR ## CDR);      \
   obj_t *CDR = cdr(c_o_n_s ## CAR ## CDR)
 
-#define num_fast(n) ((val) ((n << TAG_SHIFT) | TAG_NUM))
 #define zero num_fast(0)
 #define one num_fast(1)
 #define two num_fast(2)
-- 
cgit v1.2.3