summaryrefslogtreecommitdiff
path: root/colm/input.c
diff options
context:
space:
mode:
authorAdrian Thurston <thurston@complang.org>2011-12-31 20:55:10 +0000
committerAdrian Thurston <thurston@complang.org>2011-12-31 20:55:10 +0000
commit863bead07680b832a07221f08291f19266a2397f (patch)
tree982e4ae2ddf04dfc4f09b88c71f29c07bd385434 /colm/input.c
parent127782c33740f49cac09317d1136dcc77a02d97c (diff)
downloadcolm-863bead07680b832a07221f08291f19266a2397f.tar.gz
Bringing back the connection between fsm runs and input streams. This allows us
to clear the buffered data only when we need to. refs #341.
Diffstat (limited to 'colm/input.c')
-rw-r--r--colm/input.c24
1 files changed, 18 insertions, 6 deletions
diff --git a/colm/input.c b/colm/input.c
index 20a8944b..250c7d7d 100644
--- a/colm/input.c
+++ b/colm/input.c
@@ -525,7 +525,7 @@ void unsetEof( InputStream *is )
}
}
-int getData( InputStream *is, int skip, char *dest, int length, int *copied )
+int getData( FsmRun *fsmRun, InputStream *is, int skip, char *dest, int length, int *copied )
{
int ret = 0;
*copied = 0;
@@ -543,6 +543,8 @@ int getData( InputStream *is, int skip, char *dest, int length, int *copied )
Stream *stream = (Stream*)buf->tree;
int type = stream->in->funcs->getData( stream->in, skip, dest, length, copied );
+ attachInput2( fsmRun, stream->in );
+
if ( type == INPUT_EOD && is->eof ) {
ret = INPUT_EOF;
break;
@@ -592,6 +594,8 @@ int getData( InputStream *is, int skip, char *dest, int length, int *copied )
buf = buf->next;
}
+ attachInput1( fsmRun, is );
+
#if DEBUG
switch ( ret ) {
case INPUT_DATA:
@@ -663,13 +667,18 @@ int consumeData( InputStream *is, int length )
return consumed;
}
-int undoConsumeData( InputStream *is, const char *data, int length )
+int undoConsumeData( FsmRun *fsmRun, InputStream *is, const char *data, int length )
{
debug( REALM_INPUT, "undoing consume of %ld bytes\n", length );
if ( isSourceStream( is ) ) {
Stream *stream = (Stream*)is->queue->tree;
- return stream->in->funcs->undoConsumeData( stream->in, data, length );
+ int len = stream->in->funcs->undoConsumeData( stream->in, data, length );
+
+ if ( stream->in->attached2 != 0 )
+ detachInput2( stream->in->attached2, stream->in );
+
+ return len;
}
else {
RunBuf *newBuf = newRunBuf();
@@ -677,6 +686,9 @@ int undoConsumeData( InputStream *is, const char *data, int length )
memcpy( newBuf->data, data, length );
inputStreamPrepend2( is, newBuf );
+ if ( is->attached1 != 0 )
+ detachInput1( is->attached1, is );
+
return length;
}
}
@@ -718,7 +730,7 @@ struct LangEl *consumeLangEl( InputStream *is, long *bindId, char **data, long *
return stream->in->funcs->consumeLangEl( stream->in, bindId, data, length );
}
else {
- return 0;
+ assert( false );
}
}
@@ -729,7 +741,7 @@ void undoConsumeLangEl( InputStream *is )
return stream->in->funcs->undoConsumeLangEl( stream->in );
}
else {
- assert(false);
+ assert( false );
}
}
@@ -774,7 +786,7 @@ Tree *undoPrependData( InputStream *is, int length )
int have = 0;
while ( have < length ) {
int res = 0;
- getData( is, 0, tmp, length-have, &res );
+ getData( 0, is, 0, tmp, length-have, &res );
have += res;
}
return 0;