⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test.c

📁 用C写的CGI测试程序
💻 C
字号:

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

typedef struct 
{
	char name[20];
	char val[20];
} entry;

void getword(char *word, char *line, char stop);
char x2c(char *what);
void unescape_url(char *url);
void plustospace(char *str);



main(int argc, char *argv[]) 
{
	entry entries[5];
	register int x,m=0;
	char *cl;

	printf("Content-type: text/html%c%c",10,10);

	if(strcmp(getenv("REQUEST_METHOD"),"GET")) 
	{
		printf("This script should be referenced with a METHOD of GET.\n");
		exit(1);
	}

	cl = getenv("QUERY_STRING");

	if(cl == NULL) 
	{
		printf("No query information to decode.\n");
		exit(1);
	}
	for(x=0;cl[0] != '\0';x++) 
	{
		m=x;
		getword(entries[x].val,cl,'&');
		plustospace(entries[x].val);
		unescape_url(entries[x].val);
		getword(entries[x].name,entries[x].val,'=');
	}

	printf("<H1>CGI 测试</H1>");
	printf("您 输 入 的 信 息 如 下 ∶ <p>%c",10);
	printf("<ul>%c",10);

	for(x=0; x <= m; x++)
	{
		printf("<li> <code>%s = %s</code>%c",entries[x].name,entries[x].val,10);
		printf("</ul>%c",10);
	}
}


	void getword(char *word, char *line, char stop) 
	{
		int x = 0,y;

		for(x=0;((line[x]) && (line[x] != stop));x++)
		word[x] = line[x];

		word[x] = '\0';
		if(line[x]) ++x;
		y=0;

		while(line[y++] = line[x++]);
	}

	char x2c(char *what) 
	{
		register char digit;

		digit = (what[0] >= 'A' ? ((what[0] & 0xdf) - 'A')+10 : (what[0] - '0'));
		digit *= 16;
		digit += (what[1] >= 'A' ? ((what[1] & 0xdf) - 'A')+10 : (what[1] - '0'));
		return(digit);
	}

	void unescape_url(char *url) 
	{
		register int x,y;

		for(x=0,y=0;url[y];++x,++y) 
		{
			if((url[x] = url[y]) == '%') 
			{
				url[x] = x2c(&url[y+1]);
				y+=2;
			}
		}
		url[x] = '\0';
	}

	void plustospace(char *str) 
	{
		register int x;

		for(x=0;str[x];x++) 
		if(str[x] == '+') 
		{
			str[x] = ' ';
		}
	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -