/*
 *  urlencode  --  filter from plain text to URL-encoded
 *  
 *  Description: this program reads from standard input and encodes
 *  according to the RFC 3986, sending the result on standard output.
 *  
 *  In this implementation, only ASCII letters and digits are passed
 *  unmodified, any other byte value is encoded as %HH.
 *  
 *  Example: "a b" becomes "a%20b".
 *  
 *  Author: Umberto Salsi <salsi@icosaedro.it>
 *  
 *  Version: 2008-04-27
 *  
 *  Updates: www.icosaedro.it/apache/urlencode.c
 *  
 *  References: Uniform Resource Identifier (URI): Generic Syntax, RFC 3986
 */

#include <stdio.h>


int main()
{
	int c;
	char *hex = "0123456789abcdef";

	while( (c = getchar()) != EOF ){
		if( ('a' <= c && c <= 'z')
		|| ('A' <= c && c <= 'Z')
		|| ('0' <= c && c <= '9') ){
			putchar(c);
		} else {
			putchar('%');
			putchar(hex[c >> 4]);
			putchar(hex[c & 15]);
		}
	}

	return 0;
}

/* The end. */
