diff options
author | Adrian Thurston <thurston@complang.org> | 2013-04-06 09:40:52 -0400 |
---|---|---|
committer | Adrian Thurston <thurston@complang.org> | 2013-04-06 09:40:52 -0400 |
commit | df6297d0abaecdd0eb96dd41e51e9f50bd18de22 (patch) | |
tree | 9180e1ced6afd3ef2e787412933e25b3b2625cda /colm | |
parent | 52ac774a4c4dcc6beb0b87e708e738efbe0e915d (diff) | |
download | colm-df6297d0abaecdd0eb96dd41e51e9f50bd18de22.tar.gz |
track progress through a stream
We need this so we can send data back to a tree of streams and end up with
streams contents identical to original forms.
Diffstat (limited to 'colm')
-rw-r--r-- | colm/input.c | 7 | ||||
-rw-r--r-- | colm/input.h | 2 |
2 files changed, 7 insertions, 2 deletions
diff --git a/colm/input.c b/colm/input.c index 19fe5b18..e12772df 100644 --- a/colm/input.c +++ b/colm/input.c @@ -295,6 +295,7 @@ int fdConsumeData( StreamImpl *ss, int length ) length -= slen; updatePosition( ss, buf->data + buf->offset, slen ); buf->offset += slen; + ss->consumed += slen; } } @@ -315,6 +316,7 @@ int fdUndoConsumeData( StreamImpl *ss, const char *data, int length ) memcpy( newBuf->data, data, length ); sourceStreamPrepend( ss, newBuf ); undoPosition( ss, data, length ); + ss->consumed -= length; return length; } @@ -652,6 +654,7 @@ static int _consumeData( StreamImpl *is, int length ) consumed += slen; length -= slen; buf->offset += slen; + is->consumed += slen; } } @@ -671,10 +674,9 @@ static int _undoConsumeData( StreamImpl *is, const char *data, int length ) { //debug( REALM_INPUT, "undoing consume of %ld bytes\n", length ); - if ( isSourceStream( is ) ) { + if ( is->consumed == 0 && isSourceStream( is ) ) { Stream *stream = (Stream*)is->queue->tree; int len = stream->in->funcs->undoConsumeData( stream->in, data, length ); - return len; } else { @@ -682,6 +684,7 @@ static int _undoConsumeData( StreamImpl *is, const char *data, int length ) newBuf->length = length; memcpy( newBuf->data, data, length ); inputStreamPrepend( is, newBuf ); + is->consumed -= length; return length; } diff --git a/colm/input.h b/colm/input.h index 44db61be..00f674c8 100644 --- a/colm/input.h +++ b/colm/input.h @@ -153,6 +153,8 @@ struct _StreamImpl struct PatternItem *patItem; struct Constructor *constructor; struct ConsItem *consItem; + + int consumed; }; StreamImpl *newSourceStreamPat( struct Pattern *pattern ); |