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

static int		filecount;
static file_t	out;

void processfile(char *name_in)
{
	void_p *p;
	vboolean name;
	p=tokParseFile(name_in,"&*()-+\\;'\",.<>\t");
	if(!p)
		return;
	filecount++;
	name=false;
	filePrintf(out,";\tNames exported from '%s'\n",name_in);
	while(tokNext(p))
	{
		if(name)
		{
			filePrintf(out,"\t%s\n",tokLast(p));
			name=false;
			continue;
		}
		if(!strcmp(tokLast(p),"V_GLOBAL"))
			name=true;
	}
	tokDestroy(p);
}

void V_CALL scancb(char *name)
{
	char ext[_MAX_EXT];
	fsSplitPath(name,NULL,NULL,ext);
	if(ext[0]=='h' || ext[0]=='H')
		processfile(name);
}

int main(int argc,char *argv[])
{
	char *name_out, defname[]="out.def";
	if(argc>1)
		name_out=argv[1];
	else
		name_out=defname;
	puts("Definition file generator, ver. 1.1");
	puts("Copyright (C) Vladimir A. Smirnov, 2000.");
	filecount=0;
	out=fileOpenWrite(name_out);
	if(!out)
	{
		printf("Can't open %s\n",name_out);
		return -1;
	}
	filePrintf(out,";\tExport file generated by %s\n",argv[0]);
	filePrintf(out,"EXPORTS\n");
	lfsEnumFiles(NULL,scancb,0);
	if(!filecount)
		puts("No *.h* files found !\n");
	else
		printf("Processed %d header file(s).\n",filecount);
	fileClose(out);
	return 0;
}
