summaryrefslogtreecommitdiff
path: root/src/input.c
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@colm.net>2018-07-08 16:48:49 +0800
committerAdrian Thurston <thurston@colm.net>2018-07-08 16:48:49 +0800
commitfca843990f60312d6e6c1b8774988cc624364d42 (patch)
tree5da69c25666f41f49766dcd02729db04dcd6c265 /src/input.c
parentdeb9efc408109ad13846d2d6d3b1fe0e2f62ddf2 (diff)
downloadcolm-fca843990f60312d6e6c1b8774988cc624364d42.tar.gz
separating the input from stream type
Diffstat (limited to 'src/input.c')
-rw-r--r--src/input.c54
1 files changed, 40 insertions, 14 deletions
diff --git a/src/input.c b/src/input.c
index a20cd8f2..8a9bf769 100644
--- a/src/input.c
+++ b/src/input.c
@@ -163,6 +163,15 @@ void colm_close_stream_file( FILE *file )
}
}
+void colm_input_destroy( program_t *prg, tree_t **sp, struct_t *s )
+{
+ input_t *input = (input_t*) s;
+ struct input_impl *si = input->impl;
+
+ if ( !input->not_owner )
+ si->funcs->destructor( prg, sp, si );
+}
+
void colm_stream_destroy( program_t *prg, tree_t **sp, struct_t *s )
{
stream_t *stream = (stream_t*) s;
@@ -1275,23 +1284,23 @@ struct stream_impl *colm_impl_new_collect( char *name )
return (struct stream_impl*)ss;
}
-struct stream_impl *colm_impl_new_generic( char *name )
+struct input_impl *colm_impl_new_generic( char *name )
{
struct stream_impl_seq *ss = (struct stream_impl_seq*)malloc(sizeof(struct stream_impl_seq));
init_stream_impl_seq( ss, name );
ss->funcs = (struct stream_funcs*)&stream_funcs;
- return (struct stream_impl*)ss;
+ return (struct input_impl*)ss;
}
-stream_t *colm_stream_new_struct( program_t *prg )
+input_t *colm_input_new_struct( program_t *prg )
{
- size_t memsize = sizeof(struct colm_stream);
- struct colm_stream *stream = (struct colm_stream*) malloc( memsize );
- memset( stream, 0, memsize );
- colm_struct_add( prg, (struct colm_struct *)stream );
- stream->id = prg->rtd->struct_stream_id;
- stream->destructor = &colm_stream_destroy;
- return stream;
+ size_t memsize = sizeof(struct colm_input);
+ struct colm_input *input = (struct colm_input*) malloc( memsize );
+ memset( input, 0, memsize );
+ colm_struct_add( prg, (struct colm_struct *)input );
+ input->id = prg->rtd->struct_input_id;
+ input->destructor = &colm_input_destroy;
+ return input;
}
stream_t *colm_stream_open_fd( program_t *prg, char *name, long fd )
@@ -1337,14 +1346,26 @@ stream_t *colm_stream_open_file( program_t *prg, tree_t *name, tree_t *mode )
return stream;
}
-stream_t *colm_stream_new( program_t *prg )
+input_t *colm_input_new( program_t *prg )
{
- struct stream_impl *impl = colm_impl_new_generic( colm_filename_add( prg, "<internal>" ) );
- struct colm_stream *stream = colm_stream_new_struct( prg );
- stream->impl = impl;
+ struct input_impl *impl = colm_impl_new_generic( colm_filename_add( prg, "<internal>" ) );
+ struct colm_input *input = colm_input_new_struct( prg );
+ input->impl = impl;
+ return input;
+}
+
+stream_t *colm_stream_new_struct( program_t *prg )
+{
+ size_t memsize = sizeof(struct colm_stream);
+ struct colm_stream *stream = (struct colm_stream*) malloc( memsize );
+ memset( stream, 0, memsize );
+ colm_struct_add( prg, (struct colm_struct *)stream );
+ stream->id = prg->rtd->struct_stream_id;
+ stream->destructor = &colm_stream_destroy;
return stream;
}
+
str_t *collect_string( program_t *prg, stream_t *s )
{
str_collect_t *collect = s->impl->funcs->get_collect( prg, s->impl );
@@ -1370,3 +1391,8 @@ struct stream_impl *stream_to_impl( stream_t *ptr )
{
return ptr->impl;
}
+
+struct input_impl *input_to_impl( input_t *ptr )
+{
+ return ptr->impl;
+}