struct NewWindow NewWindow = {
250,160,145,10,
1,2,
NULL,   /* IDCMP flags ... later CLOSEWINDOW */
WINDOWCLOSE|WINDOWDRAG|SMART_REFRESH|NOCAREREFRESH|WINDOWDEPTH|ACTIVATE,
NULL,
NULL,
(STRPTR) "Demo",
NULL,
NULL,
0,0,0,0,
WBENCHSCREEN
};

struct NewScreen NewScreen = {
0,0,320,200,5,
0,1,
NULL,
CUSTOMSCREEN,
NULL,
(STRPTR) "Please wait...",
NULL,
NULL
};

struct Screen *Picture;
struct Window *Control;
struct IntuitionBase *IntuitionBase;
struct GfxBase *GfxBase;
struct narrator_rb *TalkCB;
struct timerequest *WaitCB;
FILE *script;

main(argc,argv)
int argc;
char **argv;
{
char *get1,*get2,*GetLin(),*scrfln;
static UBYTE chmasks[4] = {3,5,10,12};
static UWORD ptr[4] = {0,0,0,0};
struct narrator_rb *CreateExtIO();
long time();
int wipesel = -1,fadesel = 1;

   Check0(IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library",0L));
   Check0(GfxBase = (struct GfxBase *) OpenLibrary("graphics.library",0L));

   if (argc == 2)
      scrfln = argv[1];
   else
      scrfln = "WipeDemo.s";
   Check0(script = fopen(scrfln,"r"));
   Check0(Picture = OpenScreen(&NewScreen));
   Check0(Control = OpenWindow(&NewWindow));
   SetPointer(Control,ptr,1L,1L,0L,0L);
   Check0(TalkCB = CreateExtIO(CreatePort(0L,0L),
                  (long) sizeof(struct narrator_rb)));
   srand((unsigned int) time(NULL));
   TalkCB->ch_masks = chmasks;
   TalkCB->nm_masks = 4;
   TalkCB->message.io_Command = CMD_WRITE;
   TalkCB->mouths = 0;
   if (OpenDevice("narrator.device",0L,TalkCB,0L))
      TheEnd();
   Check0(WaitCB = (struct timerequest *) CreateExtIO(CreatePort(0L,0L),(long)
                  sizeof(struct timerequest)));
   WaitCB->tr_node.io_Command = TR_ADDREQUEST;
   WaitCB->tr_time.tv_micro = 0;
   OpenDevice(TIMERNAME,UNIT_VBLANK,WaitCB,0L);
   FOREVER
      {
      get1 = GetLin(script);
      if (!get1)
         break;
      if (*get1 == '#')
         continue;
      for (get2 = get1; *get2 != ' '; get2++)
         if (!(*get2))
            break;
      if (*get2)
         *(get2++) = NULL;
      if (!strcmp(get1,"show"))
         {
         LoadPict(get2,Picture,wipesel,fadesel);
         continue;
         }
      if (!strcmp(get1,"say"))
         {
         Say(get2);
         continue;
         }
      if (!strcmp(get1,"wait"))
         {
         Sit(get2);
         continue;
         }
      if (!strcmp(get1,"loop"))
         {
         fseek(script,0L,0);
         continue;
         }
      if (!strcmp(get1,"random"))
         {
         wipesel = -1;
         continue;
         }
      if (!strcmp(get1,"select"))
         {
         wipesel = atoi(get2);
         continue;
         }
      if (!strcmp(get1,"fades"))
         {
         if (!strcmp(get2,"off"))
            fadesel = 0;
         else
            fadesel = 1;
         continue;
         }
      break;
      }
   TheEnd();
}

TheEnd()
{
   if (WaitCB && WaitCB->tr_node.io_Device)
      CloseDevice(WaitCB);
   if (TalkCB && TalkCB->message.io_Device)
      CloseDevice(TalkCB);
   if (TalkCB)
      DeleteExtIO(TalkCB,(long) sizeof(struct narrator_rb));
   if (WaitCB)
      DeleteExtIO(WaitCB,(long) sizeof(struct timerequest));
   if (Control)
      CloseWindow(Control);
   if (Picture)
      CloseScreen(Picture);
   if (script)
      fclose(script);
   if (GfxBase)
      CloseLibrary(GfxBase);
   if (IntuitionBase)
      CloseLibrary(IntuitionBase);
   Exit(0L);
}

Say(whattosay)
char *whattosay;
{
   TalkCB->message.io_Data = (APTR) whattosay;
   TalkCB->message.io_Length = strlen(whattosay);
   DoIO(TalkCB);
}

Sit(howstr)
char *howstr;
{
int secs;
struct Message *Mess;

   ModifyIDCMP(Control,CLOSEWINDOW);
   secs = atoi(howstr);
   WaitCB->tr_time.tv_secs = secs;
   SendIO(WaitCB);
   Wait((1L << WaitCB->tr_node.io_Message.mn_ReplyPort->mp_SigBit) |
        (1L << Control->UserPort->mp_SigBit));
   if (Mess = GetMsg(Control->UserPort))
      {
      AbortIO(WaitCB);
      ReplyMsg(Mess);
      TheEnd();
      }
   GetMsg(WaitCB->tr_node.io_Message.mn_ReplyPort);
   ModifyIDCMP(Control,0L);
}

char *GetLin(handle)
FILE *handle;
{
static char buf[90];

if (fgets(buf,90,handle) == NULL)
   return(NULL);

buf[strlen(buf)-1] = NULL;

return(buf);
}
