aboutsummaryrefslogtreecommitdiffstats
path: root/io.c
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2012-07-29 17:13:13 +0300
committerArnold D. Robbins <arnold@skeeve.com>2012-07-29 17:13:13 +0300
commit0eaab9127d090da073a53695583837fcbd2be9d3 (patch)
treed2c34b0df5b4608830fb58f87002f512d3df8e98 /io.c
parent7e649df8a9e0375363a724ce89f78021a4395bf0 (diff)
downloadegawk-0eaab9127d090da073a53695583837fcbd2be9d3.tar.gz
egawk-0eaab9127d090da073a53695583837fcbd2be9d3.tar.bz2
egawk-0eaab9127d090da073a53695583837fcbd2be9d3.zip
Update input_parser interface for RT.
Diffstat (limited to 'io.c')
-rw-r--r--io.c53
1 files changed, 23 insertions, 30 deletions
diff --git a/io.c b/io.c
index 57cdb581..8bc649e6 100644
--- a/io.c
+++ b/io.c
@@ -2700,34 +2700,6 @@ iop_alloc(int fd, const char *name)
return iop;
}
-/* set_RT_to_null --- real function for use by extension API */
-
-void
-set_RT_to_null()
-{
- if (! do_traditional) {
- unref(RT_node->var_value);
- RT_node->var_value = dupnode(Nnull_string);
- }
-}
-
-/* set_RT --- real function **** for use by extension API **** */
-
-void
-set_RT(NODE *n)
-{
- if (do_traditional)
- unref(n);
- else if (RT_node->var_value == n)
- assert(n == Nnull_string); /* do nothing */
- else {
- unref(RT_node->var_value);
- RT_node->var_value = n;
- }
-}
-
-/* macros for speed in default implementation */
-
#define set_RT_to_null() \
(void)(! do_traditional && (unref(RT_node->var_value), \
RT_node->var_value = dupnode(Nnull_string)))
@@ -3097,7 +3069,11 @@ find_longest_terminator:
return REC_OK;
}
-/* get_a_record --- read a record from IOP into out, return length of EOF, set RT. Note that errcode is never NULL, and the caller initializes *errcode to 0. */
+/*
+ * get_a_record --- read a record from IOP into out,
+ * return length of EOF, set RT.
+ * Note that errcode is never NULL, and the caller initializes *errcode to 0.
+ */
static int
get_a_record(char **out, /* pointer to pointer to data */
@@ -3118,9 +3094,26 @@ get_a_record(char **out, /* pointer to pointer to data */
read_timeout = get_read_timeout(iop);
if (iop->public.get_record != NULL) {
- int rc = iop->public.get_record(out, &iop->public, errcode);
+ char *rt_start;
+ size_t rt_len;
+ int rc = iop->public.get_record(out, &iop->public, errcode,
+ &rt_start, &rt_len);
if (rc == EOF)
iop->flag |= IOP_AT_EOF;
+ else if (! do_traditional) {
+ /*
+ * all known extension parsers set RT to "", so probably
+ * not worth optimizing the other case
+ */
+ if (rt_len != 0) {
+ /* should we optimize this? */
+ unref(RT_node->var_value);
+ RT_node->var_value = make_string(rt_start, rt_len);
+ } else if (RT_node->var_value != Nnull_string) {
+ unref(RT_node->var_value);
+ RT_node->var_value = dupnode(Nnull_string);
+ }
+ }
return rc;
}