#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)
{
	vsize_t len;
	vhandle_t in,out;
	void_p in_base;
	in = vfsCreateFile(name);
	len = fileSize(in);
	if(len)
	{
		out = lfsCreateFile(name,file_mode_write);
		fileControl(in,pctl_map_ispace,&in_base);
		fileWrite(out,in_base,len);
		fileClose(out);
		conPrintf("Wrote '%s'(%u bytes)\n",name,len);
	}
	fileClose(in);
}

/*
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(".",NULL,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		
	vfsShutdown();
	
	memPrintMemStats();
	memPrintObjStats();
	
	return 0;
}
