嵌入式系统如何通过CGI支持简单asp
来源:互联网 发布:2017新款男鞋推荐知乎 编辑:程序博客网 时间:2024/05/06 16:12
将下面代码,编译成cgi-bin
#include <stdio.h>
#include "cgic.h"
#include <string.h>
#include <stdlib.h>
extern FILE * stdout;
#define MAX_BUF_LINE 1024
#define cgiOut stdout
int runscript(char * script,int newLine)
{
FILE * fp;
char result[512];
int len;
fp = popen(script,"r");
if( fp == NULL )
{
fprintf(cgiOut, "%s error<p>/n",script);
return (-1);
}
while( fgets(result,sizeof(result),fp) != NULL )
{
fputs(result,cgiOut);
if(newLine)
fputs("<p>",cgiOut);
}
pclose(fp);
return 0;
}
int main(int argc ,char * argv[]) {
char * scriptname = getenv("QUERY_STRING");
FILE * fp;
char * script_head = NULL;
char * script_tail = NULL;
char * script = NULL;
int scriptlen = MAX_BUF_LINE;
// char strFileName[256];
char buf[MAX_BUF_LINE];
fprintf(cgiOut, "Content-type: text/html/r/n/r/n");
if( argc == 2 )
{
scriptname = argv[1];
// fprintf(stdout,scriptname);
}
if( scriptname == NULL )
{
fprintf(stdout,"none page is specified</br>");
return 0;
}
getcwd(buf,sizeof(buf));
//snprintf(strFileName,sizeof(strFileName),"%s",scriptname);
fp = fopen(scriptname,"r");
if( fp == NULL )
{
fprintf(stdout,"cannot find page %s in %s</br>",scriptname,buf);
return 0;
}
while( (fgets(buf,sizeof(buf),fp)) != NULL )
{
if( script == NULL )
{
script_head = strstr(buf,"<%");
if( script_head )
{
*script_head++ ='/0';
*script_head++ ='/0';
fputs(buf,stdout);
script = realloc(script,scriptlen);
script[0] = '/0';
}
}
if( script!= NULL )/*header is found*/
{
if(script[0] != '/0') /*<% %> in different line*/
{
script_head = buf;
scriptlen += MAX_BUF_LINE;
script = realloc(script,scriptlen);
}
script_tail = strstr(script_head,"%>");
if(script_tail)
{
*script_tail++ ='/0';
*script_tail++ ='/0';
strcat(script,script_head);
// fprintf(stdout,"$$$$script<%s>",script);
runscript(script,0);
free(script);
script = NULL;
fputs(script_tail,stdout);
}
else
{
strcat(script,script_head); /*add the whole line*/
}
}
else
{
fputs(buf,stdout);
}
}
fclose(fp);
return 0;
}
- 嵌入式系统如何通过CGI支持简单asp
- 嵌入式Linux系统CGI程序设计技术
- 嵌入式Linux系统CGI程序设计技术
- 嵌入式Linux系统CGI程序设计技术
- 嵌入式Linux系统CGI程序设计技术
- 嵌入式Linux系统CGI程序设计技术
- 如何在windows下让apache支持asp,通过iasp
- 如何通过开源软件来学习嵌入式系统?
- 嵌入式系统支持ramdisk文件系统
- 嵌入式web入门:boa服务器移植到简单cgi测试
- 嵌入式web入门:boa服务器移植到简单cgi测试
- 服务器完美支持 asp php cgi jsp mysql
- 如何学习嵌入式系统
- 如何学习嵌入式系统
- 让APACHE支持CGI及简单用C写的CGI示例
- 【LINUX】教你如何构建支持lighttpd + cgi的环境
- 如何区分嵌入式系统和嵌入式操作系统
- 什么是嵌入式 如何理解嵌入式系统开发
- 网站设计
- 将excel数据导入oracle中
- Linux Device Driver开发优秀资源
- Windows Vista IIS 7.0开启方法
- Java模式设计之单例模式, 接上篇【饿汉式,懒汉式】
- 嵌入式系统如何通过CGI支持简单asp
- 简单的3个SQL视图搞定所有SqlServer数据库字典
- Windows Vista 激活程序下载
- windows使用记录
- 嫦娥一号的紫外敏感器
- 使用word删除指定行
- 无组件上传进度条解决方案
- ajax上传(xmlhttp上传文件突破大小限制)
- VC下的一些编译选项