/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*    unqp [-+options]   ......                                                 *
*                                                                              *
* This is a filter that decodes "quoted-printable" text, replacing the = signs *
* and the hex codes after them with the original characters.                   *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include "V.h"

#define hexval(x) (('0'<=x && x<='9')?(x-'0'):('A'<=x && x<='F')?(10+x-'A'):('a'<=x && x<='f')?(10+x-'a'):0)

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*/
main(ac,av)
	char**av;
{	int   a, r=0;	/* Arg index, return value */
	int   c0, c1, c2;
:1	ac = Vinit(ac,av);
	for (a=1; a<ac; a++) {
		switch(c0=av[a][0]) {
		  case '-':
		  case '+':
			switch (c1=av[a][1]) {
:1			  case 'd':
:1			  case 'D':
:1				Vopt(av[a]+2);
:1				break;
			  default:
:1				P1 "%s\tOption \"%s\" unknown, ignored.",pname,av[a] D;
				break;
			}
			break;
		  default:
:1			P1 "%s\tOption \"%s\" unknown, ignored.",pname,av[a] D;
			break;
		}
	}
	while ((c0 = getchar()) != EOF) {
		Switch(c0) {
		case '=':
			c1 = getchar();
			Switch(c1) {
				case '\n':
					break;
				case '0':
				case '1': case '2': case '3':
				case '4': case '5': case '6':
				case '7': case '8': case '9':
				case 'A': case 'a': case 'B': case 'b':
				case 'C': case 'c': case 'D': case 'd':
				case 'E': case 'e': case 'F': case 'f':
					c2 = getchar();
					putchar((hexval(c1) << 4) | hexval(c2));
					break;
				default:
					putchar(c0);
					putchar(c1);
			}
			break;
		default:
			putchar(c0);
		}
	}
	Exit(r);
}
