#include
#include
#include
int htoi(char *);
main()
{
int i,n;
char c;
printf (″Contenttype: text/plain\n\n″);
n=0;
if (getenv(″CONTENT-LENGTH″))
n=atoi(getenv(″CONTENT-LENGTH″));
for (i=0; i
int is-eq=0;
c=getchar();
switch (c){
case ′&′:
c=′\n′;
break;
case ′+′:
c=′ ′;
break;
case ′%′:{
char s[3];
s[0]=getchar();
s[1]=getchar();
s[2]=0;
c=htoi(s);
i+=2;
}
break;
case ′=′:
c=′:′;
is-eq=1;
break;
};
putchar(c);
if (is-eq) putchar(′ ′);
}
putchar (′\n′);
fflush(stdout);
}
/* convert hex string to int */
int htoi(char *s)
{
char *digits=″0123456789ABCDEF″;
if (islower (s[0])) s[0]=toupper(s[0]);
if (islower (s[1])) s[1]=toupper(s[1]);
return 16 * (strchr(digits, s[0]) -strchr (digits,′0′)
)
+(strchr(digits,s[1])-strchr(digits,′0′));
}
|
上面的程序首先输出一个MIME头信息给Web服务器,检查输入中的字符数,并循环检查每一个字符。当发现字符为&时,意味着一个名字/值对的结束,程序输出一个空行;当发现字符为+时,将它转换成空格; 当发现字符为%时,意味着一个两字符的十六进制值的开始,调用htoi()函数将随后的两个字符转换为相应的ASCII字符;当发现字符为=时,意味着一个名字/值对的名字部分的结束,并将它转换成字符:。最后将转换后的字符输出给Web服务器。
<<上一页
1
2
3
4
5
下一页>>
|