
#import "Webster.h"

@implementation Webster

    static NXDefaultsVector vector = {
        {"DictionaryOpen", "YES"},
        {"ExactMatch", "YES"},
        {"FontSize", "12"},
        {"Frames", "0 0 536 391 0 0 956 768 "},
        {"FullWordIndex", "NO"},
        {"ThesaurusOpen", "NO"},
        {NULL,NULL}
    };


- setupBenchmark
{
	int flag;
	char buf[MAXPATHLEN+1];

	/* remove the webster defaults */
	NXWriteDefaults("Webster",vector);

	if(!webster){
		webster = [[Speaker alloc] init];
		[webster setSendPort:NXPortFromName("Webster",NULL)];
	}
	[webster openFile:"gnu" ok:&flag];

	memset(buf,0,sizeof(buf));
	if(![[NXBundle mainBundle] getPath:buf forResource:"UserWordList" ofType:0]){
		NXRunAlertPanel(0,"Can't open UserWordList",0,0,0);
		flist = 0;
		return nil;
	}
	flist = fopen(buf,"r");
		
	return self;

}


- benchmark
{
	while(flist && !feof(flist)){
		char	buf[MAXPATHLEN+1];
		int	flag;

		buf[0] = 0;
		fgets(buf,sizeof(buf),flist);
		if(!buf[0]) break;
		[webster openFile:buf ok:&flag];
		if(NXUserAborted()) break;
	}
	if(flist) fclose(flist);
	return self;
}

- shutdownBenchmark
{
	char	buf[256];


	[userCell setDoubleValue:wallTime];
	sprintf(buf,"Webster benchmark: %g",wallTime);
	[self	logResults:buf];
	return self;
}	



@end
