summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@colm.net>2019-05-23 09:30:12 -0400
committerAdrian Thurston <thurston@colm.net>2019-05-23 09:30:12 -0400
commit984e6fb6cf25eee7dafe59db2be6b31b3c7c4b26 (patch)
treed89e8f6a4b61395c21f4197b6f10de047c3d3cfd /src
parent11bcbbea88466f75990314f58dcc66cbf76ab75b (diff)
downloadcolm-984e6fb6cf25eee7dafe59db2be6b31b3c7c4b26.tar.gz
added a get option to retrieve auto_trim from bytecode
Diffstat (limited to 'src')
-rw-r--r--src/bytecode.c11
-rw-r--r--src/ctinput.cc8
-rw-r--r--src/input.c24
-rw-r--r--src/input.h6
-rw-r--r--src/stream.c21
5 files changed, 44 insertions, 26 deletions
diff --git a/src/bytecode.c b/src/bytecode.c
index fbb94646..c5f8f313 100644
--- a/src/bytecode.c
+++ b/src/bytecode.c
@@ -209,10 +209,12 @@ static word_t stream_append_text( program_t *prg, tree_t **sp, input_t *dest, tr
assert(false);
}
else {
+ int auto_trim = impl->funcs->get_option( prg, impl, 0 );
+
/* Collect the tree data. */
str_collect_t collect;
init_str_collect( &collect );
- colm_print_tree_collect( prg, sp, &collect, input, ((struct input_impl_seq*)impl)->auto_trim );
+ colm_print_tree_collect( prg, sp, &collect, input, auto_trim );
/* Load it into the input. */
impl->funcs->append_data( prg, impl, collect.data, collect.length );
@@ -2327,7 +2329,8 @@ again:
stream_t *stream = vm_pop_stream();
struct stream_impl *si = stream_to_impl( stream );
- si->funcs->print_tree( prg, sp, si, to_send, false );
+ int auto_trim = si->funcs->get_option( prg, si, 0 );
+ si->funcs->print_tree( prg, sp, si, to_send, auto_trim );
vm_push_stream( stream );
colm_tree_downref( prg, sp, to_send );
break;
@@ -2517,7 +2520,7 @@ again:
value_t auto_trim = vm_pop_value();
struct stream_impl *si = stream->impl;
- si->funcs->auto_trim( prg, si, (long) auto_trim );
+ si->funcs->set_option( prg, si, 0, (long) auto_trim );
vm_push_stream( stream );
break;
@@ -2529,7 +2532,7 @@ again:
value_t auto_trim = vm_pop_value();
struct input_impl *ii = input->impl;
- ii->funcs->auto_trim( prg, ii, (long) auto_trim );
+ ii->funcs->set_option( prg, ii, 0, (long) auto_trim );
vm_push_input( input );
break;
diff --git a/src/ctinput.cc b/src/ctinput.cc
index a18a7ffb..2adf2a94 100644
--- a/src/ctinput.cc
+++ b/src/ctinput.cc
@@ -270,12 +270,12 @@ input_funcs_ct pat_funcs =
0, 0, 0, 0, 0, 0, /* prepend funcs. */
0, 0, 0, 0, 0, 0, /* append funcs */
- 0,
-
&ct_set_eof_mark,
&ct_transfer_loc_seq,
&ct_destructor,
+
+ 0, 0
};
@@ -489,12 +489,12 @@ input_funcs_ct repl_funcs =
0, 0, 0, 0, 0, 0, /* prepend. */
0, 0, 0, 0, 0, 0, /* append. */
- 0,
-
&ct_set_eof_mark,
&ct_transfer_loc_seq,
&ct_destructor,
+
+ 0, 0
};
void pushBinding( pda_run *pdaRun, parse_tree_t *parseTree )
diff --git a/src/input.c b/src/input.c
index 4a7d9124..ba4643ee 100644
--- a/src/input.c
+++ b/src/input.c
@@ -196,18 +196,11 @@ static void input_stream_seq_prepend( struct input_impl_seq *is, struct seq_buf
}
}
-static void input_auto_trim( struct colm_program *prg, struct input_impl_seq *ii, int auto_trim )
-{
- ii->auto_trim = auto_trim ? 1 : 0;
-}
-
-
void input_set_eof_mark( struct colm_program *prg, struct input_impl_seq *si, char eof_mark )
{
si->eof_mark = eof_mark;
}
-
static void input_destructor( program_t *prg, tree_t **sp, struct input_impl_seq *si )
{
struct seq_buf *buf = si->queue.head;
@@ -244,6 +237,16 @@ static void input_destructor( program_t *prg, tree_t **sp, struct input_impl_seq
free( si );
}
+static int input_get_option( struct colm_program *prg, struct input_impl_seq *ii, int option )
+{
+ return ii->auto_trim;
+}
+
+static void input_set_option( struct colm_program *prg, struct input_impl_seq *ii, int option, int value )
+{
+ ii->auto_trim = value ? 1 : 0;
+}
+
static int input_get_parse_block( struct colm_program *prg, struct input_impl_seq *is, int *pskip, char **pdp, int *copied )
{
@@ -693,14 +696,15 @@ struct input_funcs_seq input_funcs =
&input_append_stream,
&input_undo_append_stream,
- /* Trimming */
- &input_auto_trim,
-
/* EOF */
&input_set_eof_mark,
&input_transfer_loc,
&input_destructor,
+
+ /* Trimming */
+ &input_get_option,
+ &input_set_option,
};
struct input_impl *colm_impl_new_generic( char *name )
diff --git a/src/input.h b/src/input.h
index 58f0e2ae..285ba6a1 100644
--- a/src/input.h
+++ b/src/input.h
@@ -76,10 +76,11 @@ struct input_funcs \
struct colm_tree *(*undo_append_tree)( struct colm_program *prg, struct _input_impl *si ); \
void (*append_stream)( struct colm_program *prg, struct _input_impl *si, struct colm_stream *stream ); \
struct colm_tree *(*undo_append_stream)( struct colm_program *prg, struct _input_impl *si ); \
- void (*auto_trim)( struct colm_program *prg, struct _input_impl *si, int auto_trim ); \
void (*set_eof_mark)( struct colm_program *prg, struct _input_impl *si, char eof_mark ); \
void (*transfer_loc)( struct colm_program *prg, struct colm_location *loc, struct _input_impl *si ); \
void (*destructor)( struct colm_program *prg, struct colm_tree **sp, struct _input_impl *si ); \
+ int (*get_option)( struct colm_program *prg, struct _input_impl *si, int option ); \
+ void (*set_option)( struct colm_program *prg, struct _input_impl *si, int option, int value ); \
}
#define DEF_STREAM_FUNCS( stream_funcs, _stream_impl ) \
@@ -94,13 +95,14 @@ struct stream_funcs \
struct colm_str_collect *(*get_collect)( struct colm_program *prg, struct _stream_impl *si ); \
void (*flush_stream)( struct colm_program *prg, struct _stream_impl *si ); \
void (*close_stream)( struct colm_program *prg, struct _stream_impl *si ); \
- void (*auto_trim)( struct colm_program *prg, struct _stream_impl *si, int auto_trim ); \
void (*print_tree)( struct colm_program *prg, struct colm_tree **sp, \
struct _stream_impl *impl, struct colm_tree *tree, int trim ); \
struct stream_impl *(*split_consumed)( struct colm_program *prg, struct _stream_impl *si ); \
int (*append_data)( struct colm_program *prg, struct _stream_impl *si, const char *data, int len ); \
int (*undo_append_data)( struct colm_program *prg, struct _stream_impl *si, int length ); \
void (*destructor)( struct colm_program *prg, struct colm_tree **sp, struct _stream_impl *si ); \
+ int (*get_option)( struct colm_program *prg, struct _stream_impl *si, int option ); \
+ void (*set_option)( struct colm_program *prg, struct _stream_impl *si, int option, int value ); \
}
DEF_INPUT_FUNCS( input_funcs, input_impl );
diff --git a/src/stream.c b/src/stream.c
index 56ea3612..0af80fcf 100644
--- a/src/stream.c
+++ b/src/stream.c
@@ -390,18 +390,23 @@ static void data_close_stream( struct colm_program *prg, struct stream_impl_data
}
}
-static void data_auto_trim( struct colm_program *prg, struct stream_impl_data *si, int auto_trim )
+static int data_get_option( struct colm_program *prg, struct stream_impl_data *si, int option )
{
- si->auto_trim = auto_trim ? 1 : 0;
+ return si->auto_trim;
+}
+
+static void data_set_option( struct colm_program *prg, struct stream_impl_data *si, int option, int value )
+{
+ si->auto_trim = value ? 1 : 0;
}
static void data_print_tree( struct colm_program *prg, tree_t **sp,
struct stream_impl_data *si, tree_t *tree, int trim )
{
if ( si->file != 0 )
- colm_print_tree_file( prg, sp, (struct stream_impl*)si, tree, si->auto_trim );
+ colm_print_tree_file( prg, sp, (struct stream_impl*)si, tree, trim );
else if ( si->collect != 0 )
- colm_print_tree_collect( prg, sp, si->collect, tree, si->auto_trim );
+ colm_print_tree_collect( prg, sp, si->collect, tree, trim );
}
static int data_get_parse_block( struct colm_program *prg, struct stream_impl_data *ss, int *pskip, char **pdp, int *copied )
@@ -598,13 +603,15 @@ struct stream_funcs_data file_funcs =
&data_get_collect,
&data_flush_stream,
&data_close_stream,
- &data_auto_trim,
&data_print_tree,
&data_split_consumed,
&data_append_data,
&data_undo_append_data,
&data_destructor,
+
+ &data_get_option,
+ &data_set_option,
};
struct stream_funcs_data accum_funcs =
@@ -620,13 +627,15 @@ struct stream_funcs_data accum_funcs =
&data_get_collect,
&data_flush_stream,
&data_close_stream,
- &data_auto_trim,
&data_print_tree,
&data_split_consumed,
&data_append_data,
&data_undo_append_data,
&data_destructor,
+
+ &data_get_option,
+ &data_set_option,
};
static void si_data_init( struct stream_impl_data *is, char *name )