readcommand.cpp

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

CPP
223
字号
// readcommand.cpp: implementation of the readcommand class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "richtest.h"
#include "readcommand.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
class mydata;
#include "command.h"
#define NONE 0
#define INFO 1
#define DATASOURCE 2
#define STREAMLINE 4
#define OUTPUT 8
#define MAOHAO 16
#define INFO1 32
#define COMMAND 64
#define DESCRIOTION 128
#define PARAMTYPE 256
#define PARAMCOUNT 512
#define CONSTRUCT 1024
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
unsigned int clearzero(char* pbuffer,int where,int length);
extern CRichtestApp theApp; 
readcommand::readcommand(mydata* pdata,const CRichEditView* peditor,unsigned int streamline_lth)
{
this->peditor=peditor;
this->streamline_lth=streamline_lth;
info.Empty();
b_from_file=FALSE;
this->pdata=pdata;
}

readcommand::~readcommand()
{

}

BOOL readcommand::input()
{

	return search_command();
}

BOOL readcommand::search_command()
{			int id0=-1,j=0;
			int id=-1;	
			char line[1000];
			memset(line,1,1);
			int line_flag;
			CRichEditCtrl& edit=peditor->GetRichEditCtrl();
				unsigned int current_line=edit.GetLineCount();
				unsigned int where=0;
				unsigned int moudle_grade=0;
				unsigned int jump=0;
				for(unsigned int i=0;i<current_line;i+=jump+1)
				{	jump=0;
					unsigned int char_count=edit.GetLine(i,line,1000);
					line_flag=analize_line(line,char_count);
					if(line_flag&INFO)
						{	
						info+=CString(line);
						}
					else if(line_flag&DATASOURCE)
					{
						b_from_file=TRUE;
					}
					else if(line_flag&STREAMLINE)
					{
					
						for(;i+jump+1<current_line;jump++)
						{
							if(line_flag!=NONE)
								if(fill_streamline(moudle_grade,line,char_count,where))
									moudle_grade++;
							if(moudle_grade==PROCESS_CNT)
								break;
							char_count=edit.GetLine(i+jump+1,line,1000);
							line_flag=analize_line(line,char_count);
						}

					}
				}
if(moudle_grade==PROCESS_CNT)	
	return TRUE;
else
	return false;
}

BOOL readcommand::search_conector()
{
return TRUE;
}

BOOL readcommand::searchfor(char* pbuffer ,unsigned int blth,const char* object,unsigned int olth)
{unsigned int j=0;
if(olth>blth)
	return FALSE;
	for(unsigned int i=0;i<blth-olth+1;i++)
	{j=0;
		while(*(pbuffer+i+j)==*(object+j))
		j++;
		if(j>=olth-1)
			return TRUE;
	}
	return FALSE;
}

BOOL readcommand::is_from_file()
{
return b_from_file;
}
int readcommand::analize_line(char* line,unsigned int count)
{static const char maohao[3]=":";
 static const char info[4][9]={"附加信息","文件数据","处理模块","输出文件"};
 unsigned int reallength=clearzero(line,0,count);
 for(unsigned int i=0;i<4;i++)
 if(searchfor(line,reallength,*(info+i),8))
	 return pow(2,i);
if(searchfor(line,reallength,maohao,2)||searchfor(line,reallength,":",1))
	 return MAOHAO;
 return 0;

}
int readcommand::analize_line(char* line,unsigned int count,unsigned int *where)
{static const char maohao[3]=":";
 static const char info[4][9]={"附加信息","文件数据","处理模块","输出文件"};
 
	unsigned 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])||(*(line+i-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-8;
					for(k=0;k<4;k++)
						for(l=0;l<*where-8;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[k][4]==*(line+l+4)&&info[k][l+5]==*(line+l+5)&&info[k][l+6]==*(line+l+6)&&info[k][l+7]==*(line+l+7))

									{	info_flag=TRUE;
										info_flag<<=k;
										return info_flag;
									}
							};
						
				};		
	return info_flag;

}

BOOL readcommand::fill_streamline(unsigned int grade,char* line,unsigned int length,unsigned int where)
{
	unsigned int  real_lth=clearzero(line,0,length);
	if(searchfor(line,real_lth,"空空",4))
	{
		return TRUE;
	}
	DWORD* p=(DWORD*)(theApp.getcmd());//获得模块存储表地址
	command* pcmd=(command*)(*(p+grade));//获得对应级别模块存储指针
	unsigned int cnt=theApp.getcmd_cnt(grade);//获得对应级别模块数量
	for(unsigned int i=0;i<cnt;i++)
	{
		if(searchfor(line,real_lth,(pcmd+i)->cmd_name,(pcmd+i)->name_length))
		{
			for(int j=0;j<(pcmd+i)->conector_cnt;j++)
			{
				if(searchfor(line,real_lth,(pcmd+i)->conector[j].function_name,(pcmd+i)->conector[j].function_length))
				{
					pdata->pcom[grade]=*pcmd;
					conector_id[grade]=j;
					return TRUE;
				}
			}
		}
		
	}

	//command* 
	
return FALSE;
}
unsigned int 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;	
}

unsigned int* readcommand::get_conector()
{
return conector_id;
}

⌨️ 快捷键说明

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