home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 243.lha / WipeDemo_v2.0 / WipeDemo.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-05-10  |  4.1 KB  |  190 lines

  1. struct NewWindow NewWindow = {
  2. 250,160,145,10,
  3. 1,2,
  4. NULL,   /* IDCMP flags ... later CLOSEWINDOW */
  5. WINDOWCLOSE|WINDOWDRAG|SMART_REFRESH|NOCAREREFRESH|WINDOWDEPTH|ACTIVATE,
  6. NULL,
  7. NULL,
  8. (STRPTR) "Demo",
  9. NULL,
  10. NULL,
  11. 0,0,0,0,
  12. WBENCHSCREEN
  13. };
  14.  
  15. struct NewScreen NewScreen = {
  16. 0,0,320,200,5,
  17. 0,1,
  18. NULL,
  19. CUSTOMSCREEN,
  20. NULL,
  21. (STRPTR) "Please wait...",
  22. NULL,
  23. NULL
  24. };
  25.  
  26. struct Screen *Picture;
  27. struct Window *Control;
  28. struct IntuitionBase *IntuitionBase;
  29. struct GfxBase *GfxBase;
  30. struct narrator_rb *TalkCB;
  31. struct timerequest *WaitCB;
  32. FILE *script;
  33.  
  34. main(argc,argv)
  35. int argc;
  36. char **argv;
  37. {
  38. char *get1,*get2,*GetLin(),*scrfln;
  39. static UBYTE chmasks[4] = {3,5,10,12};
  40. static UWORD ptr[4] = {0,0,0,0};
  41. struct narrator_rb *CreateExtIO();
  42. long time();
  43. int wipesel = -1,fadesel = 1;
  44.  
  45.    Check0(IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library",0L));
  46.    Check0(GfxBase = (struct GfxBase *) OpenLibrary("graphics.library",0L));
  47.  
  48.    if (argc == 2)
  49.       scrfln = argv[1];
  50.    else
  51.       scrfln = "WipeDemo.s";
  52.    Check0(script = fopen(scrfln,"r"));
  53.    Check0(Picture = OpenScreen(&NewScreen));
  54.    Check0(Control = OpenWindow(&NewWindow));
  55.    SetPointer(Control,ptr,1L,1L,0L,0L);
  56.    Check0(TalkCB = CreateExtIO(CreatePort(0L,0L),
  57.                   (long) sizeof(struct narrator_rb)));
  58.    srand((unsigned int) time(NULL));
  59.    TalkCB->ch_masks = chmasks;
  60.    TalkCB->nm_masks = 4;
  61.    TalkCB->message.io_Command = CMD_WRITE;
  62.    TalkCB->mouths = 0;
  63.    if (OpenDevice("narrator.device",0L,TalkCB,0L))
  64.       TheEnd();
  65.    Check0(WaitCB = (struct timerequest *) CreateExtIO(CreatePort(0L,0L),(long)
  66.                   sizeof(struct timerequest)));
  67.    WaitCB->tr_node.io_Command = TR_ADDREQUEST;
  68.    WaitCB->tr_time.tv_micro = 0;
  69.    OpenDevice(TIMERNAME,UNIT_VBLANK,WaitCB,0L);
  70.    FOREVER
  71.       {
  72.       get1 = GetLin(script);
  73.       if (!get1)
  74.          break;
  75.       if (*get1 == '#')
  76.          continue;
  77.       for (get2 = get1; *get2 != ' '; get2++)
  78.          if (!(*get2))
  79.             break;
  80.       if (*get2)
  81.          *(get2++) = NULL;
  82.       if (!strcmp(get1,"show"))
  83.          {
  84.          LoadPict(get2,Picture,wipesel,fadesel);
  85.          continue;
  86.          }
  87.       if (!strcmp(get1,"say"))
  88.          {
  89.          Say(get2);
  90.          continue;
  91.          }
  92.       if (!strcmp(get1,"wait"))
  93.          {
  94.          Sit(get2);
  95.          continue;
  96.          }
  97.       if (!strcmp(get1,"loop"))
  98.          {
  99.          fseek(script,0L,0);
  100.          continue;
  101.          }
  102.       if (!strcmp(get1,"random"))
  103.          {
  104.          wipesel = -1;
  105.          continue;
  106.          }
  107.       if (!strcmp(get1,"select"))
  108.          {
  109.          wipesel = atoi(get2);
  110.          continue;
  111.          }
  112.       if (!strcmp(get1,"fades"))
  113.          {
  114.          if (!strcmp(get2,"off"))
  115.             fadesel = 0;
  116.          else
  117.             fadesel = 1;
  118.          continue;
  119.          }
  120.       break;
  121.       }
  122.    TheEnd();
  123. }
  124.  
  125. TheEnd()
  126. {
  127.    if (WaitCB && WaitCB->tr_node.io_Device)
  128.       CloseDevice(WaitCB);
  129.    if (TalkCB && TalkCB->message.io_Device)
  130.       CloseDevice(TalkCB);
  131.    if (TalkCB)
  132.       DeleteExtIO(TalkCB,(long) sizeof(struct narrator_rb));
  133.    if (WaitCB)
  134.       DeleteExtIO(WaitCB,(long) sizeof(struct timerequest));
  135.    if (Control)
  136.       CloseWindow(Control);
  137.    if (Picture)
  138.       CloseScreen(Picture);
  139.    if (script)
  140.       fclose(script);
  141.    if (GfxBase)
  142.       CloseLibrary(GfxBase);
  143.    if (IntuitionBase)
  144.       CloseLibrary(IntuitionBase);
  145.    Exit(0L);
  146. }
  147.  
  148. Say(whattosay)
  149. char *whattosay;
  150. {
  151.    TalkCB->message.io_Data = (APTR) whattosay;
  152.    TalkCB->message.io_Length = strlen(whattosay);
  153.    DoIO(TalkCB);
  154. }
  155.  
  156. Sit(howstr)
  157. char *howstr;
  158. {
  159. int secs;
  160. struct Message *Mess;
  161.  
  162.    ModifyIDCMP(Control,CLOSEWINDOW);
  163.    secs = atoi(howstr);
  164.    WaitCB->tr_time.tv_secs = secs;
  165.    SendIO(WaitCB);
  166.    Wait((1L << WaitCB->tr_node.io_Message.mn_ReplyPort->mp_SigBit) |
  167.         (1L << Control->UserPort->mp_SigBit));
  168.    if (Mess = GetMsg(Control->UserPort))
  169.       {
  170.       AbortIO(WaitCB);
  171.       ReplyMsg(Mess);
  172.       TheEnd();
  173.       }
  174.    GetMsg(WaitCB->tr_node.io_Message.mn_ReplyPort);
  175.    ModifyIDCMP(Control,0L);
  176. }
  177.  
  178. char *GetLin(handle)
  179. FILE *handle;
  180. {
  181. static char buf[90];
  182.  
  183. if (fgets(buf,90,handle) == NULL)
  184.    return(NULL);
  185.  
  186. buf[strlen(buf)-1] = NULL;
  187.  
  188. return(buf);
  189. }
  190.