void mutt_decoder_push (DECODER *d, void *_buff, size_t blen, size_t *taken)
{
+ struct decoder_buff *b;
+
if (!_buff || !blen)
{
_process_data (d, 1);
return;
}
-
- if ((*taken = MIN(blen, d->in.size - d->in.used)))
+
+ /* shortcut the identity mapping and save one copying pass */
+
+ if (d->just_take_id)
+ b = &d->out;
+ else
+ b = &d->in;
+
+ if ((*taken = MIN(blen, b->size - b->used)))
{
- memcpy (d->in.buff + d->in.used, _buff, *taken);
- d->in.used += *taken;
+ memcpy (b->buff + b->used, _buff, *taken);
+ b->used += *taken;
}
}
+int mutt_decoder_push_one (DECODER *d, char c)
+{
+ struct decoder_buff *b;
+
+ if (d->just_take_id)
+ b = &d->out;
+ else
+ b = &d->in;
+
+ if (b->used == b->size)
+ return -1;
+
+ b->buff[b->used++] = c;
+ return 0;
+}
void mutt_decoder_pop (DECODER *d, void *_buff, size_t blen, size_t *popped)
{
{
char tmp[DECODER_BUFFSIZE];
size_t i, l;
-
- do
+
+ if (s->prefix)
+ {
+ do
+ {
+ mutt_decoder_pop (d, tmp, sizeof (tmp), &l);
+ for (i = 0; i < l; i++)
+ state_prefix_putc (tmp[i], s);
+ }
+ while (l > 0);
+ }
+ else
{
- mutt_decoder_pop (d, tmp, sizeof (tmp), &l);
- for (i = 0; i < l; i++)
- state_prefix_putc (tmp[i], s);
+ do
+ {
+ mutt_decoder_pop (d, tmp, sizeof (tmp), &l);
+ fwrite (tmp, l, 1, s->fpout);
+ }
+ while (l > 0);
}
- while (l > 0);
}
/* this is where things actually happen */
{
if (force) d->forced = 1;
- if (d->just_take_id)
+ if (!d->just_take_id)
{
- size_t l = MIN (d->out.size - d->out.used, d->in.used);
- memmove (d->out.buff + d->out.used, d->in.buff, l);
- memmove (d->in.buff, d->in.buff + l, d->in.used - l);
- d->in.used -= l;
- d->out.used += l;
+ if (d->src_is_utf8)
+ _process_data_utf8 (d);
+ else
+ _process_data_8bit (d);
}
- else if (d->src_is_utf8)
- _process_data_utf8 (d);
- else
- _process_data_8bit (d);
}
/* This one is currently lacking utf-8 support */
{
long len = b->length;
int c, ch;
- char cc;
- size_t l;
+ int l = 0;
if (istext)
{
ungetc(ch, s->fpin);
}
- cc = c;
- mutt_decoder_push (dec, &cc, 1, &l);
- mutt_decoder_pop_to_state (dec, s);
-
+ mutt_decoder_push_one (dec, c);
+ if (l++ == 1024)
+ {
+ mutt_decoder_pop_to_state (dec, s);
+ l = 0;
+ }
}
-
+
mutt_decoder_push (dec, NULL, 0, NULL);
mutt_decoder_pop_to_state (dec, s);
{
long len = b->length;
int ch;
- char cc;
- size_t l;
+ int l = 0;
state_set_prefix(s);
if(ch != EOF)
{
- cc = ch;
- mutt_decoder_push (dec, &cc, 1, &l);
- mutt_decoder_pop_to_state (dec, s);
+ mutt_decoder_push_one (dec, ch);
+ if (l++ == 1024)
+ {
+ mutt_decoder_pop_to_state (dec, s);
+ l = 0;
+ }
}
}
long len = b->length;
char buf[5];
int c1, c2, c3, c4, ch, cr = 0, i;
- char cc;
- size_t l;
+ size_t l = 0;
buf[4] = 0;
if (cr && ch != '\n')
{
- cc = '\r';
- mutt_decoder_push (dec, &cc, 1, &l);
+ mutt_decoder_push_one (dec, '\r');
}
cr = 0;
cr = 1;
else
{
- cc = ch;
- mutt_decoder_push (dec, &cc, 1, &l);
+ mutt_decoder_push_one (dec, ch);
}
if (buf[2] == '=')
if (cr && ch != '\n')
{
- cc = ch;
- mutt_decoder_push (dec, &cc, 1, &l);
+ mutt_decoder_push_one (dec, ch);
}
cr = 0;
cr = 1;
else
{
- cc = ch;
- mutt_decoder_push (dec, &cc, 1, &l);
+ mutt_decoder_push_one (dec, ch);
}
if (buf[3] == '=') break;
if (cr && ch != '\n')
{
- cc = ch;
- mutt_decoder_push (dec, &cc, 1, &l);
+ mutt_decoder_push_one (dec, ch);
}
cr = 0;
cr = 1;
else
{
- cc = ch;
- mutt_decoder_push (dec, &cc, 1, &l);
+ mutt_decoder_push_one (dec, ch);
}
- mutt_decoder_pop_to_state (dec, s);
+ if ((l += 3) >= 1024)
+ {
+ mutt_decoder_pop_to_state (dec, s);
+ l = 0;
+ }
}
mutt_decoder_push (dec, NULL, 0, NULL);
mutt_decoder_pop_to_state (dec, s);
char linelen, c, l, out;
char *pt;
long len = b->length;
- size_t dummy;
-
+
if(istext)
state_set_prefix(s);
out = decode_byte (*pt) << l;
pt++;
out |= (decode_byte (*pt) >> (6 - l));
- mutt_decoder_push (dec, &out, 1, &dummy);
+ mutt_decoder_push_one (dec, out);
c++;
if (c == linelen)
break;