#include <../source/TAL/objbase.h>
#include <../source/vfs/iobase.h>
#include <../source/vfs/fbase.h>
#include <../source/vfs/fsbase.h>
#include <../source/vfs/mbase.h>

void	V_CALL
vfsDumpTree(FILE *out);

void	V_CALL vfs_to_lfs(char *name)
{
	file_t in,out;
	void_p in_base;
	in=vfsCreateFile(name);
	out=lfsCreateFile(name,filemode_write);
	fileControl(in,pctl_map_ispace,&in_base);
	fileWrite(out,in_base,fileSize(in));
	fileClose(in);
	fileClose(out);
	printf("written '%s'...\n",name);
}

void 	V_CALL print_dir(char *name)
{
	printf("DIR:  [%s]\n",name);
}

void 	V_CALL print_file(char *name)
{
	printf("FILE: [%s]\n",name);
}

int main()
{
	logStartConsoleLog();
	logUpperLevel(LOG_TRACE);
	fsInit();
	vfsEnumFiles(".",print_dir,vfs_to_lfs,true);
/*	vfsEnumFiles(".",print_dir,print_file,true); */
#if 0
	{
		vhandle_t in;
		char buffer[256];
		memZero(buffer,256);
		in = fileOpenRead("$INFO");
		if(!in)
			return 0;
		fileRead(in,buffer,255); /* preserve trailing zero */
		fileClose(in);
		puts(buffer);
	}
#endif		
	/*
	vfsEnumFiles(".",print_dir,vfs_to_lfs,true);
	
	vfsEnumFiles("maps",print_dir,vfs_to_lfs,true);
	vfsEnumFiles(".",print_dir,print_file,true);
	*/
	vfsShutdown();
	
	memPrintMemStats();
	memPrintObjStats();
	
	return 0;
}
