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

📄 project.c

📁 一个minigui 工程框架,需要windows 下的minigui 开发环境
💻 C
📖 第 1 页 / 共 3 页
字号:
#include "const.h"#include "project.h"#include "page.h"#include "button.h"
#include "border.h"
#include "label.h"
#include "image.h"#include "microwin.h"
#include "liaison.h"
#include "resource.h"#include "queue.h"// global val.
WinInfoList gWinInfoList;
Page* g_page = 0;
Page* g_list =0;
int g_list_number= 0;
int				level =0; // 0: page . 1: subpage .
int				subscript = 0; 
Page* page_pointer=0;
Button* button_pointer=0;
Border* border_pointer=0;Image* image_pointer = 0;Label* label_pointer = 0;Line* line_pointer = 0;
Gauge* 	gauge_pointer = 0;
Clock*  clock_pointer = 0;Page* subpage_pointer = 0;Miscii g_miscii;

void Initglobalval()
{
	FreeResource();
	g_page = 0;
	g_list =0;
	g_list_number= 0;
	level =0;
	subscript = 0; 
	page_pointer=0;
	button_pointer=0;
	border_pointer=0;
	image_pointer = 0;
	label_pointer = 0;
	line_pointer = 0;
	subpage_pointer = 0;
	gWinInfoList = 0;
}


int ParselScript(char* filename)
{
	FILE* file ;
	int nobjflag ;
		
	BOOL touch_head ;
	BOOL touch_tail;
	char  objstring[4096];


	touch_head = FALSE;
	touch_tail = FALSE;

	file = fopen(filename,"rt");
	if(file<=0)
	{		
		if(debug_flag)
			printf("Script file open failed!\n");
		return FILE_DESTROY;
	}

	if(debug_flag)
		printf("Parsel Script ...!\n");
	while(fgets(objstring,4096,file)!=NULL)
	{
		nobjflag = GetAtomType(objstring);
		if(nobjflag == -1)
		{
			memset(objstring,0,4096);
			if(debug_flag)
				printf ("ParselScript continue!\n");
			continue;
		}
		if(PAGEVERSION == nobjflag)
			CreatePageVersion(objstring);
		else if(PAGESIZE == nobjflag)	// obj head.
		{
			if(CreatePageSize(objstring))
				touch_head = TRUE;
		}
		else if(PAGEINFO == nobjflag)	// obj page.
		{
			if(!g_page)
			{
				if(debug_flag)
					printf("Script file error!\n");

				return FILE_DESTROY;
			}
			page_pointer = g_page + subscript;
			if(!CreatePageInfo(objstring))
			{
				page_pointer = NULL;
				if(debug_flag)
					printf("Script file error!\n");
				return FILE_DESTROY;
			}			
			subscript ++;
			level = 0;
		}
		else if(PAGESUB == nobjflag)	// obj sub page
		{
			if(!g_page)
			{
				if(debug_flag)
					printf("Script file error!\n");

				return FILE_DESTROY;
			}
			subpage_pointer = g_page + subscript;
			if(!CreatePageSub2(objstring))
			{
				subpage_pointer = NULL;
				if(debug_flag)
					printf("Script file error!\n");
				return FILE_DESTROY;
			}
			subscript ++;
			level = 1; 
		}
		else if(PAGECREATE == nobjflag)	// obj tail.
		{
			if(CreatePageCreate(objstring))
				touch_tail = TRUE;
		}
		else if(PAGEBUTTON == nobjflag)	// obj button.
		{
			if(!CreatePageButton2(objstring,0))			// 0 : general button .
			{
				if(debug_flag)
					printf("Script file error!\n");

				return FILE_DESTROY;
			}
		}
		else if(PAGEBORDER == nobjflag) // obj border
		{
			if(!CreatePageBorder2(objstring))
			{
				if(debug_flag)
					printf("Script file error!\n");

				return FILE_DESTROY;

			}
		}
		else if(PAGECOMMUNICATION == nobjflag)
		{
			if(!CreatePageCommunication(objstring))
			{
				if(debug_flag)
					printf("Script file error!\n");
				return FILE_DESTROY;
			}
		}
		else if(PAGETHEMESTYLE == nobjflag)
		{
			CreatePageThemestyle(objstring);
		}
		else if(PAGETEXT == nobjflag )	// obj text.
		{
			if(!CreatePageText(objstring))
			{
				if(debug_flag)
					printf("Script file error!\n");
				return FILE_DESTROY;
			}
		}
		else if(PAGEIMAGE == nobjflag)
		{
			if(!CreatePageImage(objstring))
			{
				if(debug_flag)
					printf("Script file error!\n");
				return FILE_DESTROY;
			}
		}
		else
		{
			if(debug_flag)
				printf("ignore !!!!!!\n");
		}
		memset(objstring,0,4096);
	}

	if(file) 
		fclose(file);

	if(FALSE == touch_head)
	{
		if(debug_flag)
			printf("Script file error!\n");
		return FILE_DESTROY ;
	}
	if(FALSE == touch_tail)
	{
		if(debug_flag)
			printf("Script file error!\n");		
		return FILE_DESTROY;
	}	return 0;

}int GetAtomType (const char* pStrObj)
{	
	char name [OBJECT_LEN+1];

	if(!pStrObj)
		return -1;

	strncpy(name,pStrObj,OBJECT_LEN);
	name[OBJECT_LEN]='\0';

	if(strstr(name,PageSize))
		return PAGESIZE;
	if(strstr(name,PageInfo))
		return PAGEINFO;
	if(strstr(name,PageSub))
		return PAGESUB;
	if(strstr(name,PageCreate))
		return PAGECREATE;
	if(strstr(name,PageButton))
		return PAGEBUTTON;
	if(strstr(name,PageBorder))
		return PAGEBORDER;
	if(strstr(name,PageImage))
		return PAGEIMAGE;
	if(strstr(name,PageText))
		return PAGETEXT;
	if(strstr(name,PageGauge))
		return PAGEGAUGE;
	if(strstr(name,PageClock))
		return PAGECLOCK;
	if(strstr(name,PageCommunication))
		return PAGECOMMUNICATION;
	if(strstr(name,PageVersion))
		return PAGEVERSION;	if(strstr(name,PageLine))
		return PAGELINE;
	if(strstr(name,PageThemestyle))
		return PAGETHEMESTYLE;
	if(strstr(name,PageThemeExtend))
		return PAGETHEMEEXTEND;

	return -1;
}_INDEX  GetIndexInformation(const char* pStrObj,int* pos)
{
	const char* pCur;
	_INDEX index;
	char length [LENGTH_LEN+1];
	char type   [TYPEEE_LEN+1];
	if(!pStrObj || !pos)
	{
		index._Type = -1;
		return index ;
	}
	*pos =*pos +1;
	pCur = pStrObj + *pos;
	strncpy(length,pCur,LENGTH_LEN);
	length[LENGTH_LEN] = '\0';
	*pos=*pos+LENGTH_LEN;
	pCur = pStrObj + *pos;
	strncpy(type,pCur,TYPEEE_LEN);	
	type[TYPEEE_LEN] = '\0';
	*pos = *pos+TYPEEE_LEN;
	index._Length = atoi(length);
	index._Type = atoi(type);
	return index;
}


long  GetLongVal(const char* pStrObj,int* pos)
{
	const char* pCur;
	char datum [DATUME_LEN+1];
	if(!pos  || !pStrObj)
		return 0;
	*pos =*pos +1;
	pCur = pStrObj + *pos;
	strncpy(datum,pCur,DATUME_LEN);
	datum[DATUME_LEN] = '\0';
	*pos = *pos + DATUME_LEN;

	return atol(datum);
}

float GetFloatVal(const char* pStrObj,int* pos)
{
	const char* pCur;
	char datum [DATUME_LEN+1];
	if(!pStrObj || !pos)
		return (float)0.0;
	*pos =*pos +1;
	pCur = pStrObj + *pos;
	strncpy(datum,pCur,DATUME_LEN);
	datum[DATUME_LEN] = '\0';
	*pos = *pos + DATUME_LEN;

	return (float)atof(datum);
}

char* GetStringVal(const char* pStrObj,int len,int* pos,int* ret)
{
	int ll;
	char* str;
	const char* pCur;
	if(!pStrObj || !pos)
		return 0;
	*pos =*pos +1;
	str = (char*)malloc(sizeof(char)*(len+1) );
	if( 0 == str)
		return 0;
	memset (str ,0,sizeof(char)*(len+1 ));

	ll = 0;
	pCur = pStrObj + *pos;
	memcpy(str,pCur,len);
	str[len] = '\0';

	*pos = *pos + len ;

	if(g_miscii.version >=10)
	{
#ifdef LINUX_V
		if(strstr(str,EMPTYLONG))
		{
			free (str);
			return 0;
		}
#else
		if(strstr(str,EMPTYMIDILL))
		{
			free (str);
			return 0;
		}
#endif
	}
	else if(g_miscii.version >=0)
	{
		if(strstr(str,EMPTY))
		{
			free (str);
			return 0;
		}
	}
	ll = len+1;
	StringReplace((char**)&str,(int*)&ll,(const char*)"\\r",(int)strlen("\\r"),(const char)0x0D);
	StringReplace((char**)&str,(int*)&ll,(const char*)"\\n",(int)strlen("\\n"),(const char)0x0A);
	StringReplace((char**)&str,(int*)&ll,(const char*)"\\t",(int)strlen("\\t"),(const char)0x09);
	HexDisposal ((char**)&str,(int*)&ll);
	if(ret)
		*ret  = ll-1;
	return str;
}
void  HexDisposal(char** pStrObj,int* nLen)
{
	int outlen ; // output len 
	int len;
	int bit;
	char c;
	int pos;
	unsigned char bb,bf,rep;
	char* source = "\\x";
	char* buffer,*buffer1,*tmp2;
	char* tmp1;
	if(!pStrObj || !(*pStrObj) || !nLen)
		return ;
	buffer1= (char*)malloc(*nLen);
	memcpy(buffer1,*pStrObj,*nLen);
	buffer = buffer1;

	outlen = 0;
	pos = 0;
	tmp1 = (char*) malloc(*nLen);
	memset(tmp1,0,*nLen);

	tmp2 = strstr(buffer,source);
	if(!tmp2)
	{
		free(buffer1);
		free(tmp1);
		return;
	}
	while(tmp2!=0)
	{
		bit = 0;
		len = tmp2-buffer;
		if(len+2>=(int)strlen(buffer))
		{
			memcpy(tmp1+outlen,buffer,len+2);
			outlen+=len+2;
			break;
		}
		else
		{
			c = buffer[len+2];
			if((c >='0' && c<='9'))
			{
				bit ++;
				bb = c-0x30;
			}
			else if((c >='a' && c<='f'))
			{
				bit++;
				bb = c-0x57;
			}
			else if((c>='A' && c<='F'))
			{
				bit++;
				bb = c-0x37;
			}
			else
			{
				memcpy(tmp1+outlen,buffer,len+2);
				outlen+=len+2;
				pos +=len+2;
				buffer = tmp2+2;
				goto GOON;
			}
		}
		if(len+3>=(int)strlen(buffer))
			bf = 0;
		else
		{
			c = buffer[len+3];
			if(c>='0' && c<='9')
			{
				bit++;
				bf = c-0x30;
			}
			else if(c>='a' && c<='f')
			{
				bit++;
				bf = c-0x57;
			}
			else if(c>='A' && c<='F')
			{
				bf = c-0x37;
				bit++;
			}
			else
			{
				bf = 0;
			}
		}
		if(bit ==2)
		{
			rep = 0;
			rep = bb & 0xf;
			rep = bb << 4;
			rep|= bf & 0xf;
		}
		else if(bit == 1)
		{
			rep =0;
			rep = bb & 0xf;
		}

		memcpy(tmp1+outlen,buffer,len);
		outlen+=len;
		tmp1[outlen] = rep;
		outlen++;
		pos +=len+2+bit;
		

		buffer = tmp2+2+bit;

GOON:
		tmp2 = strstr(buffer,source);
		if(tmp2==0)
		{
			memcpy(tmp1+outlen,buffer,*nLen-pos-1);
			outlen+=*nLen-pos-1;
		}
		bit = 0;
	}
	if(*pStrObj)
		free(*pStrObj);
	*pStrObj = (char*)malloc(outlen+1);
	memset(*pStrObj,0,outlen+1);
	memcpy(*pStrObj,tmp1,outlen);
	free(tmp1);
	free(buffer1);
	*nLen = outlen+1;
	return;
}


void  StringReplace(char** pStrObj,int* nLen,const char* source,int slen, const char target)
{
	int pos,count ,len,outlen;
	char* tmp1,*tmp2,*buffer,*buffer1;
	
	pos = 0;
	tmp1 = 0;
	tmp2 = 0;
	count = 0;
	len = 0;
	outlen = 0;
	if(!pStrObj || !(*pStrObj) || !nLen)
		return ;
	buffer1= (char*)malloc(*nLen);
	memcpy(buffer1,*pStrObj,*nLen);
	buffer = buffer1;

⌨️ 快捷键说明

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