blob: 1698b4186f1119fcda0312b5bc8ef0d57df6b63e (
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
49
50
51
52
|
/*
* upas/unesc - interpret =?foo?bar?=char?= escapes
*/
#include <u.h>
#include <libc.h>
#include <bio.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(void)
{
int c;
Biobuf bin, bout;
Binit(&bin, 0, OREAD);
Binit(&bout, 1, OWRITE);
while((c = Bgetc(&bin)) != Beof)
if(c != '=')
Bputc(&bout, c);
else if((c = Bgetc(&bin)) != '?'){
Bputc(&bout, '=');
Bputc(&bout, c);
} else {
while((c = Bgetc(&bin)) != Beof && c != '?')
continue; /* consume foo */
while((c = Bgetc(&bin)) != Beof && c != '?')
continue; /* consume bar */
while((c = Bgetc(&bin)) != Beof && c != '?'){
if(c == '='){
c = hex(Bgetc(&bin)) << 4;
c |= hex(Bgetc(&bin));
}
Bputc(&bout, c);
}
c = Bgetc(&bin); /* consume '=' */
if (c != '=')
Bungetc(&bin);
}
Bterm(&bout);
exits(0);
}
|