
#define	SW_MODULE_LISTUPPARAM

#define	LP_MAXENTRY	32768

//		
class LISTUP_PARAM{
	BOOL		m_bInitialized;
	BOOL		m_bImplemented;
	
	TCHAR		m_cCommand[64];
//	char		outpath[_MAX_PATH];
	TCHAR		m_cList[LP_MAXENTRY][64];
	int			entry;
	
public:
	
	BOOL	Func( LPCTSTR _sParamString );
	void	Quit( BOOL _bExit );
	
	LISTUP_PARAM();
	~LISTUP_PARAM();
	
private:
	void	init();
	void	set_list( LPTSTR ptr );
	BOOL	chk_cmd( LPTSTR ptr, BOOL flag );
	void	get_param( LPTSTR ptr );
	
};



LISTUP_PARAM::LISTUP_PARAM()
{
	m_bInitialized = FALSE;
	m_bImplemented = FALSE;
}

LISTUP_PARAM::~LISTUP_PARAM()
{
	
}


//		
void	LISTUP_PARAM::init()
{
	if(m_bInitialized == TRUE)	return;
	m_bInitialized = TRUE;	//	初期済みフラグ
	
	//	一回だけ行う初期化はここで
	entry = 0;
	
}


BOOL	LISTUP_PARAM::chk_cmd( LPTSTR ptr, BOOL flag )
{
	int		ii,jj;
	int		f;
	TCHAR	str[32];
	
	
	while( *ptr > ' ')	ptr--;
	ptr++;
	
	
	jj = 0;
	while( *(ptr+jj) != '('){
		str[jj] = *(ptr+jj);
		jj++;
		if(jj >= 32)	return FALSE;
	}
	str[jj] = 0;
	
	f = 0;
	for(ii=0;ii<STRING_len(str)-STRING_len(m_cCommand)+1;ii++){
		for(jj=0;jj<STRING_len(m_cCommand);jj++)	if(str[ii+jj]!=m_cCommand[jj])break;
		if(jj==STRING_len(m_cCommand)){f=1;break;}
	}
	
	if(f)	return TRUE;
	return FALSE;
}


//		
void	LISTUP_PARAM::set_list( LPTSTR str )
{
	int		ii;
	
	
	for(ii=0 ; ii<entry ; ii++){
		if(STRING_cmp(m_cList[ii],str) == 0)	return;
	}
	
	STRING_cpy(m_cList[entry++],str);
	if(entry >= LP_MAXENTRY)	Message_error( TEXT("LISTUP登録数がオーバーしました") );
	
}


//		
void	LISTUP_PARAM::get_param( LPTSTR ptr )
{
	int		ii,jj;
	TCHAR	str[64];
	
	
	ii = jj = 0;
	while(ptr[ii] != ')'){
		
		str[jj] = ptr[ii];
		jj++;
		ii++;
		if(ptr[ii] == ','){
			str[jj] = 0;
			set_list(str);
			jj = 0;
			ii++;
		}
		
	}
	
	str[jj] = 0;
	set_list(str);
	
}


//		
BOOL	LISTUP_PARAM::Func( LPCTSTR _sParamString )
{
	CSwbParam	cParam( _sParamString );							///< パラメータ処理.
	
	int			ii,len;
	TCHAR		*pMem = NULL;
	LPCTSTR		pPath;
	LPCTSTR		pCmd;
	LPCTSTR		pParam;
	
	pPath  = cParam.GetPath();		///< ターゲットファイル (GetFilePath(0)としても同じ).
	pCmd   = cParam.GetString(1);
	pParam = cParam.GetString(2);	//未使用
	
	
	init();
	
	if( !cParam.IsParam(1) ){
		Message_error( TEXT("検索するコマンドが指定されていません") );
		return FALSE;
	}
	
	len = MEM_TextRead(&pMem, pPath );
	if(len==0)	return FALSE;
	m_bImplemented = TRUE;	//	実行済みフラグ
	
	FILT_ToBig( pMem, len );								//	小文字->大文字
	
	STRING_cpy(m_cCommand, pCmd );
//		STRING_cpy(outpath,outfile);
	
	//	コマンド取得
	ii = 0;
	while(ii < len){
		if(	_ismbblead(*(pMem+ii)) == 1)	ii++;
		else{
			if(	*(pMem+ii) == '(' ){
				if(chk_cmd(pMem+ii,0) == TRUE){
					get_param(pMem+ii+1);
				}
			}
		}
		ii++;
	}
	
	mem_del(pMem);
	
	return TRUE;
}


void	LISTUP_PARAM::Quit( BOOL _bExit )
{
	int		ii,jj;
	TCHAR	str[64];
	
	
	if(m_bImplemented == FALSE)	return;
	m_bImplemented = FALSE;
	m_bInitialized = FALSE;
	
	Message_printf( TEXT("%s[%d] = {"), m_cCommand, entry );
	
	if(entry > 0){
		//	ソート
		for(ii=0 ; ii<entry-1 ; ii++)
			for(jj=ii+1 ; jj<entry ; jj++)
				if(STRING_cmp(m_cList[ii],m_cList[jj]) > 0)
				{
					STRING_cpy( str, m_cList[ii] );
					STRING_cpy( m_cList[ii], m_cList[jj] );
					STRING_cpy( m_cList[jj], str );
				}
		
		for(ii=0 ; ii<entry ; ii++)
			Message_printf( TEXT("	%s,"), m_cList[ii] );
	}
	
	Message_win( TEXT("};\n") );
	
//	for(ii=0 ; ii<entry ; ii++)	DEBUG_printf(outpath,"%s,\n",list[ii]);
	
}

LISTUP_PARAM		*pC_listupparam = NULL;
