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

📄 ws_load_web.h~

📁 it is about embeded system
💻 H~
字号:
/***************************************************  Copyright(C), 2008 , JUST  File name: ws_load_web.h  Author: StevenZ      Version: 0.9        Date: 080901  Description: 点划式网页浏览器载入网页数据功能  History:     080901  添加网页下载,分析函数 ***************************************************/#ifndef _WS_LOAD_WEB_H#define _WS_LOAD_WEB_H#include "ws_share_func.h"//公用的相关函数int block_number(char ct[]);void del_block_type(char ct[]);int text_types(char ct[]);void load_blank_struct(char **wtltptr);void web_data_struct_load(struct Web_Data *wd);/*得到字符串开始的空格数*/int block_number(char ct[]){	int i=0,n=0;	while(1)	{			if(ct[i]=='\0')			break;		if(ct[i]=='_'||ct[i]=='T'||ct[i]=='L'||ct[i]=='B')			break;		i++;	}	if(ct[i]=='\0')		return 0;	else		for(;;i++,n++)		{			if(ct[i]!='_')				return n;		}}/*删除开始的空格和格式标记*/void del_block_type(char ct[]){	int i=0;	char *cptr,ctemp[1024];	while(1)	{		if(ct[i]=='\0')			break;		if(ct[i]=='|')			break;		i++;	}	if(ct[i]=='\0')	{		strcpy(ct,"江苏科技大学");	}		else	{		cptr=&ct[i+1];		strcpy(ctemp,cptr);		strcpy(ct,ctemp);	}}/*判断正文类型:普通正文,链接,表单,submit等*/int text_types(char ct[]){	//	int i,j=0;	i=block_number(ct);	while(1)	{		if(ct[j]=='\0')			break;		if(ct[j]=='_'||ct[j]=='T'||ct[j]=='L'||ct[j]=='B')			break;		j++;	}	switch(ct[j+i])	{	case 'T':		if(ct[j+i+1]=='|')			return TEXT_D;	case 'L':		if(ct[j+i+1]=='|')			return IP_PORT_D;	case 'B':		if(ct[j+i+1]=='|')			return BLANK_D;	}	return -4;}/*装载blank结构体*/void load_blank_struct(char **wtltptr){	BLANK *pblk;	char ctemp[256],*cptr,*tptr=*wtltptr;	int i,j,k;	pblk=(BLANK *)malloc(sizeof(BLANK));	blank_init(pblk);	if(pblk==NULL)		printf("blank mem error!\n");		/*获取action*/	for(i=0;;i++)	{		if(tptr[i]==TEXT_SEP_CHAR)			break;		ctemp[i]=tptr[i];	}	ctemp[i]='\0';	i++;	pblk->action=(char *)malloc(strlen(ctemp)+1);	if(pblk)		strcpy(pblk->action,ctemp);	else printf("blank action men error!\n");	DPRINTF("pblk->action=%s\n",pblk->action);	/*获取method*/	for(j=0;;i++,j++)	{		if(tptr[i]==TEXT_SEP_CHAR)			break;		pblk->method[j]=tptr[i];	}	pblk->method[j]='\0';	i++;	DPRINTF("pblk->method=%s\n",pblk->method);	/*获取input总数*/	j=i;	for(;;j++)	{		if(tptr[j]=='\0')			break;		if(tptr[j]==TEXT_SEP_CHAR)			pblk->input_num++;	}	DPRINTF("pblk->input_num=%d\n",pblk->input_num);	pblk->input_num=(pblk->input_num+1)/4;	DPRINTF("pblk->input_num=%d\n",pblk->input_num);	/*分配空间填写type,name,value*/	pblk->type_h=(char **)malloc(sizeof(char *)*pblk->input_num);	if(pblk->type_h==NULL)		printf("pblk->type_h mem error!\n");	pblk->name_h=(char **)malloc(sizeof(char *)*pblk->input_num);	if(pblk->name_h==NULL)		printf("pblk->name_h mem error!\n");	pblk->value_h=(char **)malloc(sizeof(char *)*pblk->input_num);	if(pblk->value_h==NULL)		printf("pblk->value_h mem error!\n");	pblk->note_h=(char **)malloc(sizeof(char *)*pblk->input_num);	if(pblk->note_h==NULL)		printf("pblk->note_h mem error!\n");	for(j=0;j<pblk->input_num;j++)	{		//取type		for(k=0;;i++,k++)		{			if(tptr[i]==TEXT_SEP_CHAR)				break;			ctemp[k]=tptr[i];		}		ctemp[k]='\0';		i++;		cptr=(char *)malloc(strlen(ctemp)+1);		if(cptr==NULL)			printf("type mem error!\n");		strcpy(cptr,ctemp);		(pblk->type_h)[j]=cptr;		DPRINTF("cptr=%s\n",cptr);		DPRINTF("(pblk->type_h)[%d]=%s\n",j,(pblk->type_h)[j]);		//取name		for(k=0;;i++,k++)		{			if(tptr[i]==TEXT_SEP_CHAR)				break;			ctemp[k]=tptr[i];		}		ctemp[k]='\0';		i++;		cptr=(char *)malloc(strlen(ctemp)+1);		if(cptr==NULL)			printf("name mem error!\n");		strcpy(cptr,ctemp);		(pblk->name_h)[j]=cptr;		DPRINTF("cptr=%s\n",cptr);		DPRINTF("(pblk->name_h)[%d]=%s\n",j,(pblk->name_h)[j]);		//取value		for(k=0;;i++,k++)		{			if(tptr[i]==TEXT_SEP_CHAR)				break;			ctemp[k]=tptr[i];		}		ctemp[k]='\0';		i++;		cptr=(char *)malloc(strlen(ctemp)+1);		if(cptr==NULL)			printf("value mem error!\n");		strcpy(cptr,ctemp);		(pblk->value_h)[j]=cptr;		DPRINTF("cptr=%s\n",cptr);		DPRINTF("(pblk->value_h)[%d]=%s\n",j,(pblk->value_h)[j]);		//取note		for(k=0;;i++,k++)		{			if(tptr[i]==TEXT_SEP_CHAR||tptr[i]=='\0')				break;			ctemp[k]=tptr[i];		}		ctemp[k]='\0';		i++;		cptr=(char *)malloc(strlen(ctemp)+1);		if(cptr==NULL)			printf("note mem error!\n");		strcpy(cptr,ctemp);		(pblk->note_h)[j]=cptr;		DPRINTF("cptr=%s\n",cptr);		DPRINTF("(pblk->note_h)[%d]=%s\n",j,(pblk->note_h)[j]);	}		/*获取submit总数*/	for(i=0;i<pblk->input_num;i++)	{		if(strcmp((pblk->type_h)[i],"submit")==0)			pblk->submit_num++;	}		/*text指向BLANK结构体*/	DPRINTF("tptr=%d\n",tptr);	if(tptr)	{		DPRINTF("free tptr\n");		free(tptr);	}	DPRINTF("tptr=%d\n",tptr);	DPRINTF("pblk=%d\n",pblk);	*wtltptr=(void *)pblk;	DPRINTF("*wtltptr=%d\n",*wtltptr);}/*装载分析过后的网页数据*/void web_data_struct_load(struct Web_Data *wd){	char ctemp[1024],ctemp2[255];	char c;	//int gb_flg=0;	int wd_fd,i,gb_flg=0,brk_flg=0;	struct web_text_list *tcurrent,*wtlptr;	BLANK *pblk;	/*释放原Web_Data数据*/		if(wd->ip_port)		strcpy(ctemp,wd->ip_port);	free_web_data(wd);	init_web_data(wd);	wd->ip_port=(char *)malloc(strlen(ctemp)+1);	strcpy(wd->ip_port,ctemp);	wd_fd=open(WEB_DATA_FILE_NAME_A,O_RDONLY);	DPRINTF("wd_fd=%d\n",wd_fd);	/*读出网页标题,链接地址*/	for(i=0;;i++)	{		read(wd_fd,&ctemp[i],1);		if(ctemp[i]=='\0')		{			wd->title=(char *)malloc(strlen(ctemp)+1);			strcpy(wd->title,ctemp);			break;		}	}	DPRINTF("Welcom to %s\n",wd->title);	//	strcpy(ctemp2,"欢迎进入");	strcat(ctemp2,wd->title);	strcat(ctemp2,".请点划选择");#ifdef TTSTTS	T2S_t2s(ctemp2);#endif	/*读出网页地址*/	DPRINTF("%s\n",wd->ip_port);	/*for(i=0;;i++)	{		read(wd_fd,&ctemp[i],1);		if(ctemp[i]=='\0')		{			wd->ip_port=(char *)malloc(strlen(ctemp)+1);			strcpy(wd->ip_port,ctemp);			break;		}	}*/	DPRINTF("ip_port=%s\n",wd->ip_port);	/*读出text数据结构*/	i=0;	while(read(wd_fd,&ctemp[i],1))	{		int bn,flag,i_bf;		if(brk_flg)		{			ctemp[2+brk_flg-1]=ctemp[0];			ctemp[0+brk_flg-1]='T';			ctemp[1+brk_flg-1]='|';			for(i_bf=0;i_bf<brk_flg-1;i_bf++)			{				ctemp[i_bf]='_';			}			brk_flg=0;			i=2+brk_flg-1;		}		for(;;)/*读出一串字符串*/		{			if(ctemp[i]=='\0')			{				brk_flg=0;				//gb_flg=0;				break;			}			/*如果gb码则gb_flg+1*/			else if(ctemp[i]&0x80!=0)			{				//gb_flg++;				i++;				read(wd_fd,&ctemp[i],1);			}						/*如果大于500个字符,开始断句*/			if(i>800)			{				ctemp[i+1]='\0';				brk_flg=1;				gb_flg=0;				break;			}			i++;			read(wd_fd,&ctemp[i],1);		}		if(ctemp[0]=='\0') continue;		//sleep(1);		DPRINTF("i=%d,string=%s\n",i,ctemp);		//sleep(1);		bn=block_number(ctemp); /*计算字符串开始有几个空格*/		if(brk_flg)		{			brk_flg=bn+1;		}		wtlptr=(struct web_text_list *)malloc(sizeof(struct web_text_list));		if(wtlptr==NULL)			DPRINTF("mem error!!\n");		init_web_text_list(wtlptr);		wtlptr->tflag=text_types(ctemp);/*判断正文类型:普通正文,链接,表单,submit等*/		del_block_type(ctemp); /*去掉字符串开始的空格和类型*/				//sleep(1);		wtlptr->text=(char *)malloc(strlen(ctemp)+1);		if(wtlptr->text==NULL)			DPRINTF("mem error!!\n");		strcpy(wtlptr->text,ctemp);		DPRINTF("wtlptr->tflag=%d\n",wtlptr->tflag);		if(wtlptr->tflag==BLANK_D)		{			load_blank_struct((char **)&(wtlptr->text));			DPRINTF("wtlptr->text=%d\n",wtlptr->text);			pblk=(BLANK *)wtlptr->text;			DPRINTF("wtlptr->text->action=%s\n",pblk->action);			DPRINTF("wtlptr->text->method=%s\n",pblk->method);		}		tcurrent=wd->text_list_head;		tcurrent->tflag++;		DPRINTF("tcurrent->tflag=%d\n",tcurrent->tflag);		/*移至next,prev链表最后一个*/		for(;;)		{			if(tcurrent->next==NULL)				break;			tcurrent=tcurrent->next;		}		DPRINTF("tcurrent->next=%d\n",tcurrent->next);		flag=1;		for(i=0;i<bn;i++)		{			if(tcurrent->child==NULL)			{				if(i+1<bn)					DPRINTF("wtl load error!!!\n");				tcurrent->child=wtlptr;				wtlptr->parent=tcurrent;				DPRINTF("add string=%s\n",wtlptr->text);				flag=0;				break;			}			else			{				tcurrent=tcurrent->child;				for(;;)				{/*移至next,prev链表最后一个*/					if(tcurrent->next==NULL)						break;					tcurrent=tcurrent->next;				}			}		}		if(flag)		{			tcurrent->next=wtlptr;			wtlptr->prev=tcurrent;			DPRINTF("add string=%s\n",wtlptr->text);		}		i=0;		DPRINTF("wd->text_list_head->next->text=%s\n",wd->text_list_head->next->text);	}	if(wd->text_list_head->next)		wd->current=wd->text_list_head->next;	close(wd_fd);}#endif

⌨️ 快捷键说明

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