
#import "Tree.h"
#import "LispFilter.h"

extern id createLispTree(NXStream *stream, Properties *props, NXZone *zone);

@implementation LispFilter

+ filterWithProps:(Properties *)props inZone:(NXZone *)aZone
{
	const char *localDirectory;
	const char *const *localFiles;
	char buffer[MAXPATHLEN];
	id openpanel = [OpenPanel new];
	NXStream *aStream;
	const char *const *fileTypes = {NULL};
	id result;

	if([openpanel runModalForTypes:fileTypes]){
		localDirectory = [openpanel directory];
		localFiles = [openpanel filenames];
		strcpy(buffer,localDirectory);
		strcat(buffer,"/");
		strcat(buffer,*localFiles);
		if((aStream = NXMapFile(buffer, NX_READONLY)) == NULL){
			NXRunAlertPanel(NULL, "File %s could not be opened for reading.", NULL, NULL, NULL, buffer);
			return nil;
		}
		result = createLispTree(aStream, props, aZone);
		NXCloseMemory(aStream, NX_FREEBUFFER);
		return result;
	}
	return nil;
}

@end
