Пример #1
0
void __gxx_log__::LogCreate()
{
	if( !m_bInitPah )
	{
		return;
	}
	
	static DWORD dwTick= GetTickCount();
	if (GetTickCount()-dwTick > (24*1000*3600))
	{
		DeleteHistory();
		dwTick = GetTickCount();
	}

	if( m_hFile != INVALID_HANDLE_VALUE )
	{
		CloseHandle(m_hFile);
		m_hFile = INVALID_HANDLE_VALUE ;
	}
	//创建今天的文件
	SYSTEMTIME stToday;
	GetLocalTime(&stToday);

	WCHAR chBuf[512];
	swprintf(chBuf,L"%s%04d%02d%02d.log",m_chFilePath,stToday.wYear,stToday.wMonth,stToday.wDay);
	
	m_hFile = ::CreateFileW(chBuf,GENERIC_READ|GENERIC_WRITE,FILE_SHARE_READ|FILE_SHARE_WRITE,
		NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
}
TARGETSEQUENCE::~TARGETSEQUENCE()
{
 if (targets)           delete targets;
 if (tree)              delete tree;
 if (dictionary)        delete dictionary;
 /*shidong starts*/
if(debug)  fclose(f);
 /*shidong ends*/

 targets=NULL;
 tree=NULL;
 dictionary=NULL;

 DeleteHistory();
}
int TARGETSEQUENCE::Initialize(int numT )
{
int ret;

 // delete the history of all previous active targets
 DeleteHistory();

 // Load the dictionary file
 try {
  if (Parameter("EnablePrediction") == 0)
     prediction=false;
  else
     prediction=true;

  // load and create all potential targets
  /*shidong starts*/
  NUM_TARGETS = numT;
  ret=LoadPotentialTargets();
  /*plist->GetParamPtr("TargetDefinitionMatrix")->GetNumColumns(),
  plist->GetParamPtr("TargetDefinitionMatrix")->GetNumRows(),
  plist->GetParamPtr("TreeDefinitionMatrix")->GetNumColumns(),
  plist->GetParamPtr("TreeDefinitionMatrix")->GetNumRows()   */

        if(debug) fprintf(f, "After LoadPotentialTargets, ret is %d.\n", ret);

  // possibly replace this with something better
  if (ret == 0)  Application->MessageBox(VCLSTR("Could not load target definition matrix."), VCLSTR("Error"), MB_OK);
  if (ret == -1) Application->MessageBox(VCLSTR("Could not load tree definition matrix."), VCLSTR("Error"), MB_OK);
  if (ret <= 0)  return(0);

        if(debug) fprintf(f, "After App->msgBox, ret is %d.\n", ret);

    /*shidong ends*/
 ret=dictionary->LoadDictionary(Parameter("DictionaryFile").c_str(), true);
        if(debug) fprintf(f, "After LoadDictionary, ret is %d, dic file is %s.\n", ret, Parameter("TargetDefinitionMatrix").c_str() );
  // if there was no error, add the dictionary to the potential targets
  if (ret == 1)
     AddDictionary2PotentialTargets();  /* */
} catch(...) {ret=0;}

 // possibly replace this with something better
 if ((ret == 0) && (prediction))
    Application->MessageBox(VCLSTR("Could not find dictionary file. Wrong directory ?"), VCLSTR("Error"), MB_OK);

 return(ret);
}
Пример #4
0
void __gxx_log__::operator()(const wchar_t *tcszLogFilePath,int nLimitDays/*=-1*/, bool bShowLogType/*=false*/, bool bDetailLog/*=true*/)
{
    EnterCriticalSection(&m_cs);
	if( tcszLogFilePath == NULL )
	{
		LeaveCriticalSection(&m_cs);
		return ;
	}
	int nLen = (int)wcslen(tcszLogFilePath);
	memcpy(m_chFilePath,tcszLogFilePath,nLen*2);
	m_chFilePath[nLen] = L'\0';
	m_bInitPah = TRUE;
	m_nLimitDay = nLimitDays;
	m_bShowLogType = bShowLogType;
	m_bDetailLog = bDetailLog;
	DeleteHistory();
    LeaveCriticalSection(&m_cs);
}
Пример #5
0
void Shell(COMMAND commands[],char *help[])
{
	char cmdline[STRING],argv[MAXCMD],argp[MAXCMD];
	
	int i,opcja,n=0,j,ok,len,count=0,itmp;
	
	while(commands[n].command!=NULL) n++;
	
	for( ; ; )
	{					/* Interactive mode */
		fprintf(stdout,"[%d]MP> ",count); fflush(stdout);
		argv[0]=argp[0]=0; cmdline[0]=0;
		
		if(!fgets(cmdline,sizeof(cmdline)-1,stdin))
		{
			fprintf(stderr,"Read error ! [%s]\n",cmdline);
			return;
		}
		
		i=0;
		while(cmdline[i] && isspace(cmdline[i])) i++;
		(void)sscanf(cmdline+i,"%s",argv);
		
		len=strlen(argv);
		if(len==0) continue;
		i+=len;
		while(cmdline[i] && isspace(cmdline[i])) i++;
		(void)sscanf(cmdline+i,"%[^\n]\n",argp);
		
		AppendHistory(count,argv,argp); count++;
		
		if(strcmp(argv,"history")==0)
		{
			if(strlen(argp)>0)
			{
				itmp=atoi(argp);
				ok=0;
				for(i=0 ; i<CountHist ; i++)
				{
					if(HistTable[i]->count==itmp)
					{
						ok=1;
						strcpy(argv,HistTable[i]->napis);
						strcpy(argp,HistTable[i]->opt);
						fprintf(stdout,"[%d] (HISTORY [%d]) MP> %s %s\n",
							count-1,itmp,argv,argp);
						break;
					}
				}
					
				if(!ok)
				{
					fprintf(stderr,"No such number\n");
					continue;
				}
			}
			else
			{
				fprintf(stdout,"\t\t<<< HISTORY >>>\n");
				
				for(i=0 ; i<CountHist ; i++)
				{
					fprintf(stdout,"[%d] %s %s\n",HistTable[i]->count,
						HistTable[i]->napis,
						HistTable[i]->opt);
				
					if(((i+1)%20)==0) 
						pause();
				}
				
				fprintf(stdout,"\n");
				continue;
			}
		}
		
		if(strcmp(argv,"man")==0)
		{
			fprintf(stdout,"\n\t\t<<< BUILT-IN COMMANDS >>\n"
				"exit        \t\t- leave shell\n"
				"ls          \t\t- current directory listing\n"
				"history [nr]\t\t- display entered commands or execute [nr] if given\n"
				"batch       \t\t- run commands from file\n"
				"!comd       \t\t- run a shell command comd\n"
				"man         \t\t- display all available help\n"
				"sys comd    \t\t- run shell command comd in script\n");
			
			fprintf(stdout,"<<< NEXT - ENTER q - QUIT >>> ");
		
			if(getchar()!='q')
			{
				if(help!=NULL)
					PrintAllHelp(commands,help,n); 
			}
			else 
				(void)getchar();
			
			continue;
		}
		
		if(strcmp(argv,"help")==0 || strcmp(argv,"?")==0 || strcmp(argv,"h")==0)
		{
			ok=0;
			
			if(strlen(argp)>0)
			{
				if(strcmp(argp,"help")==0 || strcmp(argp,"?")==0)
				{
					ok=1;
					fprintf(stderr,"help [arg] or ? [arg] -- info about the arg command\n");
				} 
				else if(strcmp(argp,"batch")==0)
				{
					ok=1;
					fprintf(stderr,"batch file -- run script file\n");
				}	
				else if(strcmp(argp,"sys")==0)
				{
					ok=1;
					fprintf(stderr,"sys comd -- run shell command comd (from a script only)\n");
				}
				else if(strcmp(argp,"ls")==0)
				{
					ok=1;
					fprintf(stderr,"ls adir -- listing of directory adir, regexp allowed\n"); 
				}
				else if(strcmp(argp,"history")==0)
				{
					ok=1;
					fprintf(stderr,"history [nr] -- list entered commands\n"	
						"\t\t or if [nr] given - run command No [nr]\n");
				}
				else
					for(j=0 ; j<n ; j++)
					if(strcmp(commands[j].command,argp)==0)
					{
						ok=1;
						fprintf(stdout,"%-10s - ",commands[j].command);
						if(help!=NULL)
							fprintf(stdout,"%s ",help[j]);
						fprintf(stdout,"\n");
						break;
					}
					if(!ok) 
						fprintf(stdout,"Unknown command : %s\n",argp);
			}
			else
			{ fprintf(stdout,"%s\n",firsthelp); }
			continue;
		}
		
		if(strcmp(argv,"exit")==0) {
			DeleteHistory();
			if(prn==1)
				fprintf(stdout,"<<< LEAVING MP SHELL >>>\n");
			Quit("");
			break;
		}
		
		if(strcmp(argv,"ls")==0)
		{
			ls(argp);
			continue;
		}
		
		if(strcmp(argv,"batch")==0)
		{
			char *newargv[MAXCMD];
			int i,argc;
			
			for(i=0 ; i<MAXCMD ; i++)
				newargv[i]=NULL;
			
			StrToArgv(argp,newargv,&argc);
			if(Batch(commands,newargv[0],newargv)==-1)
				fprintf(stderr,"Missing file %s !\n",argp);
			FreeArgv(newargv,argc);
			continue;
		}
		
		if(strcmp(argv,"!")==0)
		{
			if(system(argp)==-1)
				fprintf(stderr,"Error executing system command !\n");
			continue;
		}
		
		if(argv[0]=='!')
		{
			argv[0]=' ';
			(void)strcat(argv," "); (void)strcat(argv,argp);
			if(system(argv)==-1)
				fprintf(stderr,"Error executing system command !\n");
			continue;
		}
		
		opcja=-1;				/* Opcje zewnetrzne */
		
		for(i=0 ; i<n ; i++)
			if(strcmp(commands[i].command,argv)==0)
			{
				opcja=i;
				(*commands[i].func)(argp);
				break;
			}
			
			if(opcja==-1)
			{
				char name[STRING],*newargv[MAXCMD],buffor[STRING];
				int argc,i;
				
				for(i=0 ; i<MAXCMD ; i++)
					newargv[i]=NULL;
				
				sprintf(buffor,"%s %s",argv,argp);
				StrToArgv(buffor,newargv,&argc);
				
				if(Batch(commands,newargv[0],newargv)==-1)
				{	 /* Polecenia w biezacym katologu */
					int index=0,ok=0;
					
					for( ; ; index++)
					{
						if(makePathName(name,index)==NULL)
							break;
						
						strcat(name,newargv[0]);
						if(Batch(commands,name,newargv)!=-1) {
							ok=1;
							break;
						}
					}

					if(ok==0) 
						fprintf(stderr,"MP: Unknown command %s or bad script path %s\n",
						argv,BatchPath);
				}
				
				FreeArgv(newargv,argc);
			}    
      }
}