#include <stdio.h>
#include <X10/Xlib.h>
#include "Xtlib.h"

char *	GetAskForString();
Window	theBox;

main()
{

	XOpenDisplay();
	XtInitialize();

	theBox = MakeAskFor( RootWindow, "File name:", "", 250, 250 );
	XMapWindow( theBox );
	
	while(1)
	{
	XEvent ev;

		XNextEvent(&ev);
		(void) XtDispatchEvent(&ev);
	}
}

static void ButtonAction(tag)
	char * tag;
{
  char * filename;

  if( !strcmp(tag,"Input From File") ) {
    filename = GetAskForString(theBox);
    if (fork() == 0) {
      execlp("/usr/athena/ispell",filename,(char *) 0);
      _exit();
    }
  }
    else if( !strcmp(tag,"Interactive") )
	{
	  if (fork() == 0) {
	    execlp("/usr/bin/X10/xterm","xterm","=80x10+50+50","-e","/usr/athena/ispell","-a",(char *) 0);
            _exit();
	  }
	}
	else if( !strcmp(tag,"Cancel") )
	{
		XtSendDestroyNotify( theBox );
		XDestroyWindow( theBox );
		exit();
	}
}

Window
MakeAskFor( parent, prompt, initval, x, y )
	Window parent;
	char *prompt;
	char *initval;
	int	x,y;
{
Window w;

	w = XtDialogCreate( parent, prompt, initval, NULL, 0 );
	XtDialogAddButton( w, "Input From File", ButtonAction, "Input From File" );
	XtDialogAddButton( w, "Interactive", ButtonAction, "Interactive" );
	XtDialogAddButton( w, "Cancel", ButtonAction, "Cancel" );
	XMoveWindow( w, x, y );
	return w;
}

char *
GetAskForString( w )
	Window w;
{
	return XtDialogGetValueString(w);
}


