flate

deflate implementation
git clone git://git.suckless.org/flate
Log | Files | Refs | README

commit bb4c48aacfd66adfdcf9996a01d4c483c34b2eed
parent 38801a4bfd04d88424c4f6e517626df055aeb55f
Author: nsz@tpx <unknown>
Date:   Thu,  6 Aug 2009 10:04:55 +0200

deflate cleaning
Diffstat:
deflate.c | 28+++++++++++++++-------------
1 file changed, 15 insertions(+), 13 deletions(-)

diff --git a/deflate.c b/deflate.c @@ -585,10 +585,18 @@ static int deflate_state(State *s) { int pos = s->pos; int head; + /* messy.. */ switch (s->state) { - do { - /* messy.. */ + for (;;) { if (s->avail < MaxMatch || s->rend - s->rbuf >= RbufSize - 2) { + if (s->avail == 0) { + flushlit(s); + s->lastblock = 1; + s->state = FlateHasOutput; + deflate_block(s, pos - s->blockstart); + putbits(s, 0, 7); + return FlateHasOutput; + } if (pos - s->blockstart > MaxDist || s->rend - s->rbuf >= RbufSize - 2) { flushlit(s); if (prevm.len) { @@ -617,8 +625,7 @@ fprintf(stderr, "avail %d pos %d lastpos %d srcavail %d\n", s->avail, pos, s->po s->state = FlateNeedInput; return FlateNeedInput; case FlateNeedInput: - if (fillwin(s)) - /* tralala */; + fillwin(s); prevm = s->prevm; } pos = s->pos; @@ -645,14 +652,9 @@ fprintf(stderr, "avail %d pos %d srcavail %d\n", s->avail, s->pos, s->srcend - s recordlit(s, s->win[pos]); pos++; s->avail--; - } while (s->avail); - } - flushlit(s); - s->lastblock = 1; - s->state = FlateHasOutput; - deflate_block(s, pos - s->blockstart); - putbits(s, 0, 7); - return FlateHasOutput; + } /* for(;;) */ + } /* switch */ + return FlateError; } static State *alloc_state(void) { @@ -711,7 +713,7 @@ int deflate(FlateStream *stream) { memcpy(stream->out, s->dstbegin, stream->nout); s->dstbegin += stream->nout; } - if (n == FlateOk) { + if (n == FlateOk || n == FlateError) { free(s); stream->state = 0; }