/*************************************************************************
*	CCI for EDIA
*************************************************************************/

#include	"ccilib.h"
#include	"txdcmd.h"
#include	"txdofs.h"
#include	"edicmd.h"

char   *SysMacro = NULL;	/* システムマクロ	*/
char	SYSMACRO_FN[12] = {'e','d','i','a','.','m','a','c','\0'};
char	MACROKEY_EXPSEARCH_PATH[16] = {'E','x','p','_','s','e','a','r','c','h','_','p','a','t','h','\0'};

#include	"lib.c"
#include	"pcl.c"
#include	"he386.c"
#include	"cciexp.c"
#include	"edi.c"

/*	デフォルト登録ワイルドカード	*/
#define	WILDCARD_TBL_NUM	4
char	*WildCardTbl[WILDCARD_TBL_NUM] = 
{
	"*.*"  ,
	"*.doc *.txt *.man",
	"*.asm *.c   *.cci *.h",
	"*.mml *.h   *.def"
};

#if	0
int		port_test()
{
	int		p0,p1,p2,p3,p4;
	char	tmp[256];

	p0 = MidPortTbl[0] & 0xFF;
	p1 = MidPortTbl[1] & 0xFF;
	p2 = MidPortTbl[2] & 0xFF;
	p3 = MidPortTbl[3] & 0xFF;
	p4 = MidPortTbl[4] & 0xFF;
	sprintf(tmp,"echo %d %d %d %d %d > d:\\a",p0,p1,p2,p3,p4 );
	system(tmp);
}
#endif

/*************************************************************************
*	起動直後の処理
*************************************************************************/

int		EDIA_start()
{
	int		i;
	char	tmp[256];

	/* システムマクロの初期化	*/
	if ( (SysMacro = AMAC_allocWork(0)) != NULL )
	{
		sprintf( tmp, "%s%s", AplGetStartPath(), SYSMACRO_FN );
		AMAC_load( SysMacro, tmp );
		GetAsciiTime( tmp, time(NULL) );
		AMAC_setKey( SysMacro, "Startup_time", tmp );
	}

	/* デフォルトワイルドカードの設定	*/
	for ( i = 0 ; i < WILDCARD_TBL_NUM; ++i )
		FdlSetWildCardList( WildCardTbl[i] );
	SetExpSearchPath();

#ifdef	_RSMIDI
	MidPortTbl[0] = 8;
#endif

	return (0);
}

/*************************************************************************
*	終了時の処理
*************************************************************************/

int		EDIA_term()
{
	char	tmp[256];

	if ( SysMacro )
	{
		GetAsciiTime( tmp, time(NULL) );
		AMAC_setKey( SysMacro, "Exit_time", tmp );

		sprintf( tmp, "%s%s", AplGetStartPath(), SYSMACRO_FN );
		AMAC_save( SysMacro, tmp, "System macro" );
	}
	return (0);
}
