/* Last edited on 2006-08-22 09:50:56 by stolfi */ /* Converts MIME quote-printable encoding to binary bytes. */ #include #include int doit(void); int main(int argc, char **argv) { int res; if (argc != 1) { fprintf(stderr, "unquote-printable: no args please\n"); return(1); } res = doit(); fclose(stdout); return(res); } #define ERROR(msg) \ fprintf(stderr, "unquote-printable: byte %d: %s\n", nc, msg); return(1) int doit(void) { int c, a, b; int nc = 0; int hexval[256]; /* Hexadecimal digit value table */ for (c=0; c<256; c++) { hexval[c] = -1; } for (c='0'; c<= '9'; c++) { hexval[c] = c - '0'; } for (c='A'; c<= 'F'; c++) { hexval[c] = 10 + (c - 'A'); } for (c='a'; c<= 'f'; c++) { hexval[c] = 10 + (c - 'a'); } /* Mapping */ c = getchar(); while (c != EOF) { nc++; if ( c == '=' ) { a = getchar(); if (a == EOF) { ERROR("unexpected EOF"); } nc++; if (a == '\n') { c = '\n'; } else { b = getchar(); if (b == EOF) { ERROR("unexpected EOF"); } nc++; a = hexval[a]; b = hexval[b]; if ((a == -1) || (b == -1)) { ERROR("bad hex digit"); } c = ((a << 4) | b); } } if (putchar(c) == EOF) { ERROR("problem writing stdout"); } c = getchar(); } return(0); }