/************************************************************************
		X-Window 	サンプルプログラム

		FILE ( OPEN/CLOSE )

 ************************************************************************/

#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include "ToolBox.h"
#include "External.h"
#include "MenuRes.h"
#include "Prototype.h"


#define		TRUE	1		/* 真である	*/
#define		FALSE	0		/* 偽である	*/


static	char	CGX_name[1024];		/* 読み込む CGX FILE NAME */
static	char	path_name[1024];	/* 読み込む COL FILE NAME */
static	char	MD7_name[1024];		/* 読み込む MD7 FILE NAME */
static	char	BMP_name[1024];		/* 読み込む BMP FILE NAME */

extern int iskanji(code)
int code;
{
        return(0);
}

/************************************************************************
		キャラクターファイルをオープンする
 ************************************************************************/
CGXfilter(entry,status)
struct	dirent	*entry;
struct	stat	*status;
{
	int	namlen = strlen(entry->d_name);

	if	(status -> st_mode & S_IFDIR )				return	(TRUE);
	if	(namlen < 4 )								return  (FALSE);
	if	(!strcmp(&entry->d_name[namlen-4],".cgx"))	return	(TRUE);
	if	(!strcmp(&entry->d_name[namlen-4],".CGX"))	return	(TRUE);
	return(FALSE);

}

extern void CGXOpen(item)
MItemPtr	item;
{

		int	pos_x = 30;
		int	pos_y = 30;

		if ( SelectInputFile(pos_x,pos_y,CGX_name,CGXfilter)){
			SetDataCharacter(CGX_name);
		}

}
/************************************************************************
		モード７( VRAMすいあげデータ ) ファイルをオープンする
 ************************************************************************/

MD7filter(entry,status)
struct	dirent	*entry;
struct	stat	*status;
{

	int	namlen = strlen(entry->d_name);

	if	(status -> st_mode & S_IFDIR )				return	(TRUE);
	if	(namlen < 4 )								return  (FALSE);
	if	(!strcmp(&entry->d_name[namlen-4],".md7"))	return	(TRUE);
	if	(!strcmp(&entry->d_name[namlen-4],".MD7"))	return	(TRUE);
	return(FALSE);

}

extern void MD7Open(item)
MItemPtr	item;
{

		int	pos_x = 30;
		int	pos_y = 30;

		if ( SelectInputFile(pos_x,pos_y,MD7_name,MD7filter)){
			SetDataMode7(MD7_name);
		}

}



/************************************************************************
		モード７( VRAMすいあげbitmapデータ ) ファイルをオープンする
 ************************************************************************/

BMPfilter(entry,status)
struct	dirent	*entry;
struct	stat	*status;
{

	int	namlen = strlen(entry->d_name);

	if	(status -> st_mode & S_IFDIR )				return	(TRUE);
	if	(namlen < 4 )								return  (FALSE);
	if	(!strcmp(&entry->d_name[namlen-4],".bmp"))	return	(TRUE);
	if	(!strcmp(&entry->d_name[namlen-4],".BMP"))	return	(TRUE);
	return(FALSE);

}

extern void BMPOpen(item)
MItemPtr	item;
{

		int	pos_x = 30;
		int	pos_y = 30;

		if ( SelectInputFile(pos_x,pos_y,BMP_name,BMPfilter)){
			SetDataBitmap(BMP_name);
		}

}



/************************************************************************
		カラーファイルをオープンする
 ************************************************************************/
filter_func(entry,status)
struct	dirent	*entry;
struct	stat	*status;
{

	int	namlen = strlen(entry->d_name);

	if	(status -> st_mode & S_IFDIR )				return	(TRUE);
	if	(namlen < 4 )								return  (FALSE);
	if	(!strcmp(&entry->d_name[namlen-4],".col"))	return	(TRUE);
	if	(!strcmp(&entry->d_name[namlen-4],".COL"))	return	(TRUE);
	return(FALSE);

}


extern void COLOpen(item)
MItemPtr	item;
{

		int	pos_x = 30;
		int	pos_y = 30;

		if ( SelectInputFile(pos_x,pos_y,path_name,filter_func)){
			SetDataColor(path_name);
		}

}

