/**********************************************************************
 
	Copyright (C) 2003 Hirohisa MORI <joshua@nichibun.ac.jp>
 
	This program is free software; you can redistribute it 
	and/or modify it under the terms of the GLOBALBASE 
	Library General Public License (G-LGPL) as published by 

	http://www.globalbase.org/
 
	This program is distributed in the hope that it will be 
	useful, but WITHOUT ANY WARRANTY; without even the 
	implied warranty of MERCHANTABILITY or FITNESS FOR A 
	PARTICULAR PURPOSE.

**********************************************************************/

/*
int for_each_file(char *path, int (*func)(char *)){
DIR dd;
struct dirent * d;
int ret;

	ret = 1;
	dd = opendir(path);
	if ( dd == 0 ) {
		fprintf(stderr,"cannot open the path %s\n", path);
		return 0;
	}
	
	for ( ; ; ) {
		d = readdir(dd);
		if ( d == 0 )
			break;
		if ( d->d_ino == 0 )
			continue;
		if ( d->d_name[0] == '.' )
			continue;

		sprintf(file,"%s%s", path, d->d_name);
		if(!func(file)){
			ret = 0;
			break;
		}
	}
	closedir(dd);
	return ret;
}
*/

#ifdef WIN32
#include <windows.h>
int for_each_file(char *path, int (*func)(char *)){
WIN32_FIND_DATA fd;
char pszFilter[MAX_PATH+1];
char pszFullPath[MAX_PATH+1];
HANDLE hFind;
int ret = 1;

	wsprintf(pszFilter, "%s*.*", path);
	hFind = FindFirstFile(pszFilter, &fd);
	if(!hFind)
		return 0;
	while(FindNextFile(hFind, &fd)){
		if(*(fd.cFileName) == '.'){
			continue;
		}
		wsprintf(pszFullPath, "%s%s", path, fd.cFileName);
		if(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY){
			/* subdirectory */
			/*
			cahr psz[MAX_PATH+1];
			wsprintf(psz, "%s/", pszFullPath);
			for_each_file(psz, func);
			*/
			continue;
		}
		
		/*
		//拡張子のチェック
		char *p=(char*)::_mbsrchr((UCHAR*)fd.cFileName, '.');
		if(p && !stricmp(p, pszExt)){
			
		}
		*/
		if(!func(pszFullPath))
			ret = 0;
	}
	FindClose(hFind);
	return ret;
}
#endif

