readmoduleinfo.cpp

来自「故障诊断工作涉及的领域相当广泛」· C++ 代码 · 共 431 行

CPP
431
字号
// readmoduleinfo.cpp: implementation of the readmoduleinfo class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "richtest.h"
#include "readmoduleinfo.h"
#define MAXLINECNT 1024
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
	#define NONE 0
	#define LANGUAGE 1
	#define NAME 2
	#define TYPE 4
	#define SIT 8
	#define GRADE 16
	#define INFO 32
	#define COMMAND 64
	#define DESCRIOTION 128
	#define PARAMTYPE 256
	#define PARAMCOUNT 512
	#define CONSTRUCT 1024

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
int atoi16(char* bag,int cnt)
{int i,j=0,k=0;
	//char* sss=new char[cnt];
	//memset(sss,0,cnt);
	for(i=0;i<cnt;i++)
	{if(*(bag+i)>='0'&&*(bag+i)<='9')
		k=k*16+*(bag+i)-'0';
	else if(*(bag+i)>='A'&&*(bag+i)<='F')
		k=k*16+*(bag+i)-'A'+10;
	}
return k;			
}
readmoduleinfo::readmoduleinfo(command* pcmd,unsigned int id)
{
this->pcmd=pcmd;
this->pcmd->cmd_id=id;
}

readmoduleinfo::~readmoduleinfo()
{

}
int readmoduleinfo::analize_line(char* line,int count,int *where)
{static const char maohao[3]=":";
static const char info[11][5]={"语言","名称","接口","位置","级别","信息","命令","描述","类型","数量","构造"};
 
	int i=0,j,k,l;
	BOOL mao_hao_flag=FALSE;
	int info_flag=0;
	*where=0;
			while(++i<count-1)
				{
					if(*(line+i-1)==maohao[0]&&*(line+i)==maohao[1])
					{
						mao_hao_flag=TRUE;
						*where=i;
					}
				};
		if(!mao_hao_flag)
			{i=0;
				while(++i<count-1)
				{
					if(*(line+i-1)==':')
					{
						mao_hao_flag=TRUE;
						*where=i-1;
					}
				};
			};
			if(mao_hao_flag)
				{
					j=i-4;
					for(k=0;k<11;k++)
						for(l=0;l<*where-4;l++)
							{
								if(info[k][l]==*(line+l)&&info[k][l+1]==*(line+l+1)&&info[k][l+2]==*(line+l+2)&&info[k][l+3]==*(line+l+3))
									{	info_flag=TRUE;
										info_flag<<=k;
										return info_flag;
									}
							};
						
				};		
	return info_flag;

}
int readmoduleinfo::InputData()
{	// int con_cnt=0;
	 int func_count=0;
	 int i;
	 int line_flag=0;
	 int line_flag_last=0;
	static CString filename,line;
	filename.Empty();
CFileDialog	dlg(TRUE);
if(IDOK==dlg.DoModal())
{filename=dlg.GetFileName();
	pcmd->name_length=filename.GetLength();
	pcmd->cmd_name=new char[pcmd->name_length+1];
	for(i=0;i<pcmd->name_length;i++)
pcmd->cmd_name[i]=filename.GetAt(i);
pcmd->cmd_name[pcmd->name_length]='\0';
}
else 
	return -1;
pcmd->conector_cnt=0;
if(!filename.IsEmpty())
{static char* bag0,*bag;
CFile* filebin=new CFile(filename,CFile::modeRead);
if(filebin!=NULL)
{   	
	CArchive ar(filebin,CArchive::load);
	int file_length=filebin->GetLength();
	int count=0;
	bag0=new char[file_length];
	bag=bag0;
	char* pbuffer=new char[MAXLINECNT];
	do{
		for(i=0;i<MAXLINECNT;i++)
		{	count++;
			ar>>*(pbuffer+i);
			if(*(pbuffer+i)=='\n'||count>=file_length)
			break;
		}
		
		if(i==MAXLINECNT)
			return FALSE;
		int where;
	//	line_flag_last=line_flag;
		line_flag=analize_line(pbuffer,i,&where);
		if(line_flag&LANGUAGE)
		{	if(!line_flag_last&LANGUAGE)
			{line_flag_last|=LANGUAGE;
			if(search(pbuffer,i,"中文",sizeof("中文")-1))
				pcmd->cmd_lan=chinese;
			else
				pcmd->cmd_lan=english;
			}
			else return FALSE;
			memset(pbuffer,0,MAXLINECNT);
		}
		else if(line_flag&NAME)
			{	int l=0;
				if(!(line_flag_last&NAME))
				{line_flag_last|=NAME;
				int real_length=clearzero(pbuffer,where+1,i);
				 pcmd->name_length=real_length;
				 pcmd->cmd_name=new char[real_length+1];
					for(l=0;l<real_length;l++)
					{
					 pcmd->cmd_name[l]=pbuffer[l];
					}
					pcmd->cmd_name[real_length]='\0';
				}			
				else return FALSE;
				memset(pbuffer,0,MAXLINECNT);
			}
		else if(line_flag&TYPE)
			{	if(!(line_flag_last&TYPE))
				{line_flag_last|=TYPE;
				if(search(pbuffer,i,"组件",sizeof("组件")-1))
				{if(search(pbuffer,i,"标准",sizeof("标准")-1))
					pcmd->cmd_type=com_std;
				 else
					pcmd->cmd_type=com_disp;
				}
				else
					pcmd->cmd_type=function;
				}			
				else return FALSE;
				memset(pbuffer,0,MAXLINECNT);
			}
		else if(line_flag&SIT)
			{int j=0,l=0;
				if(!(line_flag_last&SIT))
				{line_flag_last|=SIT;
		//	int real_length;//=clearzero(pbuffer,where,i);
				while(*(pbuffer+j++)!='{');
				while(*(pbuffer+j+l++)!='}');
				 pcmd->where_length=l;
				
				 pcmd->cmd_where=new char[l+1];
				  l=0;
					for(int u=j+l;pbuffer[u]!='}';u++)
					{
					 pcmd->cmd_where[l++]=pbuffer[u];
					}
				}
			else return FALSE;
			pcmd->cmd_where[l]='\0';
			memset(pbuffer,0,MAXLINECNT);
			}
		else if(line_flag&GRADE)
			{	if(!(line_flag_last&GRADE))
				{
					line_flag_last|=SIT;
					if(search(pbuffer,i,"应用",sizeof("应用")-1))
						pcmd->level=special;
					else if(search(pbuffer,i,"预处理",sizeof("预处理")-1))
						pcmd->level=prepare;
					else if(search(pbuffer,i,"基础",sizeof("基础")-1))
						pcmd->level=base;
					else if(search(pbuffer,i,"处理",sizeof("处理")-1))
						pcmd->level=proccess;
					else if(search(pbuffer,i,"阶段零",sizeof("阶段零")-1))
						pcmd->level=base;
					else if(search(pbuffer,i,"阶段一",sizeof("阶段一")-1))
						pcmd->level=prepare;
					else if(search(pbuffer,i,"阶段二",sizeof("阶段二")-1))
						pcmd->level=proccess;
					else if(search(pbuffer,i,"阶段三",sizeof("阶段三")-1))
						pcmd->level=special;
					else if(search(pbuffer,i,"阶段四",sizeof("阶段四")-1))
						pcmd->level=stage4;
					else if(search(pbuffer,i,"阶段五",sizeof("阶段五")-1))
						pcmd->level=stage5;
					else if(search(pbuffer,i,"阶段六",sizeof("阶段六")-1))
						pcmd->level=stage6;
				}
				else return FALSE;
				memset(pbuffer,0,MAXLINECNT);
			}
		else if(line_flag&INFO)
			{	pcmd->cmd_info=new char[i+1];
				pcmd->info_length=i;
					for(int l=where+1;l<i;l++)					
					 pcmd->cmd_info[l-where-1]=pbuffer[l];
					pcmd->cmd_info[l-where]='\0';
					memset(pbuffer,0,MAXLINECNT);
			}
		else if(line_flag&COMMAND)
			{	line_flag_last|=COMMAND;
				int real_length=clearzero(pbuffer,where+1,i);
				 (pcmd->conector+pcmd->conector_cnt)->function_name=new char[real_length+1];
				 (pcmd->conector+pcmd->conector_cnt)->function_length=real_length+1;
					for(int l=0;l<real_length;l++)
					{
					 (pcmd->conector+pcmd->conector_cnt)->function_name[l]=pbuffer[l];
					}
						(pcmd->conector+pcmd->conector_cnt)->function_name[l]='\0';
				memset(pbuffer,0,MAXLINECNT);
			}
			else if(line_flag&DESCRIOTION)
			{	
				if(line_flag_last&COMMAND)
				{line_flag_last|=DESCRIOTION;
				int u=0,w=0,y=0;
					while(*(pbuffer+u++)!='{');
					while(*(pbuffer+u+y++)!='}');
					(pcmd->conector+pcmd->conector_cnt)->description_length=y;
					(pcmd->conector+pcmd->conector_cnt)->description=new char[y+1];
					while(*(pbuffer+u)!='}')
					{
						if(*(pbuffer+u)!=' ')
						(pcmd->conector+pcmd->conector_cnt)->description[w++]=*(pbuffer+u++);
					}
				(pcmd->conector+pcmd->conector_cnt)->description[w]='\0';	
				}
				else
				{AfxMessageBox("模块接口描述无命令支持");
				return FALSE;
				}
				memset(pbuffer,0,MAXLINECNT);
			}
		else if(line_flag&PARAMTYPE)
		{
			if(line_flag_last&DESCRIOTION)
				{line_flag_last|=PARAMTYPE;
					if(search(pbuffer,i,"矩阵",4))
						(pcmd->conector+pcmd->conector_cnt)->type_in=type_mw;
					else if(search(pbuffer,i,"整数",4))
						(pcmd->conector+pcmd->conector_cnt)->type_in=type_int;
					else if(search(pbuffer,i,"小数",4))
						(pcmd->conector+pcmd->conector_cnt)->type_in=type_dou;
					else 
						(pcmd->conector+pcmd->conector_cnt)->type_in=type_var;
				}
				else
				{AfxMessageBox("接口参数无接口支持");
				return FALSE;
				}
				memset(pbuffer,0,MAXLINECNT);
		}
		else if(line_flag&PARAMCOUNT)
		{
			if(line_flag_last&PARAMTYPE)
				{line_flag_last|=PARAMCOUNT;
					char bag[3]="ab",u=0;
					static const char douhao[3]=",";
					for(int w=where;!(pbuffer[w]==',')|!(pbuffer[w]==',');w++)
					{
						if(pbuffer[w]>='0'&&pbuffer[w]<='9')
						{	
							bag[u++]=pbuffer[w];
							if(u>2)
							{AfxMessageBox("输出参数数量太多,最多4个");
							return FALSE;
							}
						}
					}
					u=0;
					(pcmd->conector+pcmd->conector_cnt)->out_param_cnt=atoi(bag);
					for(;w<i;w++)
					{
						if(pbuffer[w]>='0'&&pbuffer[w]<='9')
						{	
							bag[u++]=pbuffer[w];
							if(u>2)
							{AfxMessageBox("输入参数数量太大多,最多16个");
							return FALSE;
							}
						}
					}				
					(pcmd->conector+pcmd->conector_cnt++)->in_param_cnt=atoi(bag);
					line_flag_last&=0x1F;
				}
				else
				{AfxMessageBox("参数数量无参数类型支持");
				return FALSE;
				}
				memset(pbuffer,0,MAXLINECNT);
		}
		else if(line_flag&CONSTRUCT)
			{
				if(line_flag_last>0x1F)
				{AfxMessageBox("不完整的接口描述");
				return FALSE;
				}
				else if(line_flag_last&CONSTRUCT)
				{
					AfxMessageBox("重复的构造参数IID");
				return FALSE;
				}
				line_flag_last|=CONSTRUCT;
				memset(pbuffer,0,MAXLINECNT);
				
		}
		else if(line_flag==NONE)
		{
			if(line_flag_last&CONSTRUCT)
			{
				if(search(pbuffer,i,"IID_I",4))
				get_uuid(&(pcmd->iid),pbuffer,i);
				else if(search(pbuffer,i,"CLSID_",6))
				get_uuid(&(pcmd->clsid),pbuffer,i);
				else if(search(pbuffer,i,"LIBID_",6))
				get_uuid(&(pcmd->libid),pbuffer,i);
			}
			memset(pbuffer,0,MAXLINECNT);
		}
	}while(count<file_length);
ar.Close();
filebin->Close();	
delete []pbuffer;
}

}
return TRUE; 
};

int readmoduleinfo::clearzero(char* pbuffer,int where,int length)
{int j=0;
	for(int i=where;i<length;i++)
	{if(*(pbuffer+i)!=' ')
	*(pbuffer+j++)=*(pbuffer+i);
	}
	return j;	
}

BOOL readmoduleinfo::search(char *pbuffer,int blth, char *object, int olth)
{
for(int i=0;i<blth-olth;i++)
	for(int j=0;j<olth;j++)
	{if(*(pbuffer+i+j)!=*(object+j))
		break;
		if(j==olth-1)
			return TRUE;
	}
	return FALSE;
}

void readmoduleinfo::get_uuid(IID *here, char* pbuffer, int cnt)
{int j=0,k=0;char bag[11];
	memset(bag,0,11);
	while(*(pbuffer+j++)!='=');
	j++;
	while(*(pbuffer+(j))!=',')
	{
		if((*(pbuffer+j)>='0'&&*(pbuffer+j)<='9')||(*(pbuffer+j)>='A'&&*(pbuffer+j)<='F')||*(pbuffer+j)>='x')
			*(bag+k++)=*(pbuffer+j++);
	}
	here->Data1=atoi16(bag,k);
	memset(bag,0,11);
	k=0;j++;
	while(*(pbuffer+(j))!=',')
	{
		if((*(pbuffer+j)>='0'&&*(pbuffer+j)<='9')||(*(pbuffer+j)>='A'&&*(pbuffer+j)<='F')||*(pbuffer+j)>='x')
			*(bag+k++)=*(pbuffer+j++);
	}
	here->Data2=atoi16(bag,k);
	memset(bag,0,11);
	k=0;j++;
	while(*(pbuffer+(j))!=',')
	{
		if((*(pbuffer+j)>='0'&&*(pbuffer+j)<='9')||(*(pbuffer+j)>='A'&&*(pbuffer+j)<='F')||*(pbuffer+j)>='x')
			*(bag+k++)=*(pbuffer+j++);
	}
	here->Data3=atoi16(bag,k);
	memset(bag,0,11);
	k=0;j+=2;;
	for(int w=0;w<8;w++)
	{while((*(pbuffer+(j))!=',')&&*(pbuffer+(j))!='}')
		{
		if((*(pbuffer+j)>='0'&&*(pbuffer+j)<='9')||(*(pbuffer+j)>='A'&&*(pbuffer+j)<='F')||*(pbuffer+j)>='x')
			*(bag+k++)=*(pbuffer+j++);
		}
	here->Data4[w]=atoi16(bag,k);
	memset(bag,0,11);
	k=0;j++;
	}
}

⌨️ 快捷键说明

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