/*
 * urldecode.c
 *
 * Read from stdin until encounter EOF.
 * For each line that is read, decode any URL encoding found,
 * and print the decoded line to stdout.  
 * Limits:
 * - Only ASCII chars with value <= 127 are decoded.
 * - Each line is assumed to be at most 1023 characters.
 */

#include <stdio.h>
int main()
{
	char buf[1024];
	while (fgets(buf, 1023, stdin) != NULL)
	{
		char *write_pos = buf;
		char *read_pos = buf;
		while (*read_pos)
		{
			if (*read_pos == '%')
			{
				char c[3];
				int i;
				read_pos++;
				c[0] = *read_pos++;
				c[1] = *read_pos;
				c[2] = 0;
				sscanf(c, "%x", &i);
				if (i < 128)
					*write_pos++ = (char)i;
				else {
					*write_pos++ = '%';
					*write_pos++ = c[0];
					*write_pos++ = c[1];
				}
			}
			else
			{
				*write_pos++ = *read_pos;
			}
			read_pos++;
		}
		*write_pos = 0;
		printf("%s", buf);
	}
	return 0;
}

