void melt2 () { register short i, j, k, r, c; /* Huffman-dependent part */ if(read_header() == EOF) return; StartHuff(N_CHAR2); init(Table2); /* end of Huffman-dependent part */ InitIO(); for (i = 0; i < N2 - F2; i++) text_buf[i] = ' '; r = N2 - F2; for (in_count = 0;; ) { c = DecodeChar(); if (c == ENDOF) break; if (c < 256) { #ifdef DEBUG if (debug) fprintf(stderr, "'%s'\n", pr_char((uc_t)c)); else #endif /* DEBUG */ putchar (c); text_buf[r++] = c; r &= N2 - 1; in_count++; } else { i = (r - DecodePosition() - 1) & (N2 - 1); j = c - 256 + THRESHOLD; #ifdef DEBUG if (debug) fputc('"', stderr); #endif for (k = 0; k < j; k++) { c = text_buf[(i + k) & (N2 - 1)]; #ifdef DEBUG if (debug) fprintf(stderr, "%s", pr_char((uc_t)c)); else #endif putchar (c); text_buf[r++] = c; r &= (N2 - 1); in_count++; } #ifdef DEBUG if (debug) fprintf(stderr, "\"\n"); #endif } INDICATOR } }
void melt1 () { register short i, j, k, r, c; StartHuff(N_CHAR1); init(Table1); InitIO(); for (i = 0; i < N1 - F1; i++) text_buf[i] = ' '; r = N1 - F1; for (in_count = 0;; ) { c = DecodeChar(); if (c == ENDOF) break; if (c < 256) { #ifdef DEBUG if (debug) fprintf(stderr, "'%s'\n", pr_char((uc_t)c)); else #endif /* DEBUG */ putchar (c); text_buf[r++] = c; r &= (N1 - 1); in_count++; } else { i = (r - DecodePOld() - 1) & (N1 - 1); j = c - 256 + THRESHOLD; #ifdef DEBUG if (debug) fputc('"', stderr); #endif for (k = 0; k < j; k++) { c = text_buf[(i + k) & (N1 - 1)]; #ifdef DEBUG if (debug) fprintf(stderr, "%s", pr_char((uc_t)c)); else #endif putchar (c); text_buf[r++] = c; r &= (N1 - 1); in_count++; } #ifdef DEBUG if (debug) fprintf(stderr, "\"\n"); #endif } INDICATOR } }
/* Run the actual formatting. OUTFNC and OUTFNCARG are the output functions. FORMAT is format string ARGSPECS is the parsed format string, ARGSPECS_LEN the number of items in ARGSPECS. VALUETABLE holds the values and may be directly addressed using the position arguments given by ARGSPECS. MYERRNO is used for the "%m" conversion. NBYTES well be updated to reflect the number of bytes send to the output function. */ static int do_format (estream_printf_out_t outfnc, void *outfncarg, const char *format, argspec_t argspecs, size_t argspecs_len, valueitem_t valuetable, int myerrno, size_t *nbytes) { int rc = 0; const char *s; argspec_t arg = argspecs; int argidx = 0; /* Only used for assertion. */ size_t n; value_t value; s = format; while ( *s ) { if (*s != '%') { s++; continue; } if (s != format) { rc = outfnc (outfncarg, format, (n=s-format)); if (rc) return rc; *nbytes += n; } if (s[1] == '%') { /* Note that this code ignores one trailing percent escape - this is however okay as the args parser must have detected this already. */ rc = outfnc (outfncarg, s, 1); if (rc) return rc; *nbytes += 1; s += 2; format = s; continue; } /* Save the next start. */ s += arg->length; format = s; assert (argidx < argspecs_len); argidx++; /* Apply indirect field width and precision values. */ if (arg->width == STAR_FIELD_VALUE) { assert (valuetable[arg->width_pos-1].vt == VALTYPE_INT); arg->width = valuetable[arg->width_pos-1].value.a_int; if (arg->width < 0) { arg->width = -arg->width; arg->flags |= FLAG_LEFT_JUST; } } if (arg->precision == STAR_FIELD_VALUE) { assert (valuetable[arg->precision_pos-1].vt == VALTYPE_INT); arg->precision = valuetable[arg->precision_pos-1].value.a_int; if (arg->precision < 0) arg->precision = NO_FIELD_VALUE; } if (arg->arg_pos == -1 && arg->conspec == CONSPEC_STRERROR) value.a_string = strerror (myerrno); else { assert (arg->vt == valuetable[arg->arg_pos-1].vt); value = valuetable[arg->arg_pos-1].value; } switch (arg->conspec) { case CONSPEC_UNKNOWN: assert (!"bug"); break; case CONSPEC_DECIMAL: case CONSPEC_UNSIGNED: case CONSPEC_OCTAL: case CONSPEC_HEX: case CONSPEC_HEX_UP: rc = pr_integer (outfnc, outfncarg, arg, value, nbytes); break; case CONSPEC_FLOAT: case CONSPEC_FLOAT_UP: case CONSPEC_EXP: case CONSPEC_EXP_UP: case CONSPEC_F_OR_G: case CONSPEC_F_OR_G_UP: case CONSPEC_HEX_EXP: case CONSPEC_HEX_EXP_UP: rc = pr_float (outfnc, outfncarg, arg, value, nbytes); break; case CONSPEC_CHAR: rc = pr_char (outfnc, outfncarg, arg, value, nbytes); break; case CONSPEC_STRING: case CONSPEC_STRERROR: rc = pr_string (outfnc, outfncarg, arg, value, nbytes); break; case CONSPEC_POINTER: rc = pr_pointer (outfnc, outfncarg, arg, value, nbytes); break; case CONSPEC_BYTES_SO_FAR: rc = pr_bytes_so_far (outfnc, outfncarg, arg, value, nbytes); break; } if (rc) return rc; arg++; } /* Print out any trailing stuff. */ n = s - format; rc = n? outfnc (outfncarg, format, n) : 0; if (!rc) *nbytes += n; return rc; }