aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/upas/unesc/unesc.c
blob: f3b4d652d2ac3e6a28ce99d723090a337652423a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
 *	upas/unesc - interpret =?foo?bar?=char?= escapes
 */

#include <stdio.h>
#include <stdlib.h>

int
hex(int c)
{
	if('0' <= c && c <= '9')
		return c - '0';
	if('A' <= c && c <= 'F')
		return c - 'A' + 10;
	if('a' <= c && c <= 'f')
		return c - 'a' + 10;
	return 0;
}

void
main(int argc, char **argv)
{
	int c;

	while((c=getchar()) != EOF){
		if(c == '='){
			if((c=getchar()) == '?'){
				while((c=getchar()) != EOF && c != '?')
					continue;
				while((c=getchar()) != EOF && c != '?')
					continue;
				while((c=getchar()) != EOF && c != '?'){
					if(c == '='){
						c = hex(getchar()) << 4;
						c |= hex(getchar());
					}
					putchar(c);
				}
				(void) getchar();	/* consume '=' */
			}else{
				putchar('=');
				putchar(c);
			}
		}else
			putchar(c);
	}
	exit(0);
}