home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d9xx / d955 / muroloutil.lha / MuroloUtil / Button.c < prev    next >
C/C++ Source or Header  |  1993-11-01  |  3KB  |  126 lines

  1. /*
  2.  
  3.                                   ButtonC
  4.   Apre un gadget temporizzato, restituendo dei valori al CLI 0 o 5 a seconda
  5.                       di quale bottone e' stato cliccato
  6.  
  7.                          (c) 1993 by Felice Murolo
  8.                    2:335/206@fidonet - 39:102/5@amiganet
  9.                   +39 (0)89 756281 - Max BBS - 24h - HST
  10.                             Finito il 06.03.93
  11.  
  12. Esempio d'uso da CLI
  13.  
  14. Button "Carico il WorkBench ?" 5
  15.  
  16. temporizza per 5 secondi la scritta specificata, in attesa di eventuali click
  17. di bottoni YES o NO
  18.  
  19.                      Il codice ed il sorgente sono PD.
  20. */
  21.  
  22. #include <intuition/intuition.h>
  23. #include <dos/dosextens.h>
  24.  
  25. #define PRGNAME         "Button"
  26. UBYTE   *VERSION       ="$VER: "PRGNAME" 1.0";
  27. #define DEFAULTGADTITLE PRGNAME" (c) 1993 by Felice Murolo"
  28. #define DEFAULTTEXT     "No Operation text was specified"
  29. #define DEFAULTGADTEXT   "Yes|No"
  30. #define DEFAULTSEC      3
  31.  
  32. struct Library          *IntuitionBase=NULL;
  33. struct Window           *win=NULL;
  34. struct MsgPort          *tp  =NULL;
  35. struct timerequest      *tim =NULL;
  36. struct EasyStruct       eas =
  37. {
  38. sizeof(struct EasyStruct),
  39. 0,
  40. "",
  41. "",
  42. ""
  43. };
  44.  
  45. char version[10];
  46.  
  47. void CleanUp(char *,ULONG);
  48.  
  49.  
  50. /* Programma principale */
  51. main(int argc, char *argv[])
  52. {
  53. int ret=0,ibit=0,tbit=0,sec=DEFAULTSEC,signal=0;
  54.  
  55. sprintf(version,"%s",VERSION+6+strlen(PRGNAME)+1);
  56.  
  57. printf("%s v%s\n(c) 1993 by Felice Murolo\n\n",PRGNAME,version);
  58.  
  59. eas.es_Title=DEFAULTGADTITLE;
  60. eas.es_TextFormat=DEFAULTTEXT;
  61. eas.es_GadgetFormat=DEFAULTGADTEXT;
  62. if (argc>1)
  63.    {
  64.    if (strncmp(argv[1],"?",1)==NULL)
  65.       {
  66.       printf("Usage: %s [gadget text (80 chars)] [numero secondi]\n",PRGNAME);
  67.       CleanUp("",RETURN_OK);
  68.       }
  69.    argv[1][80]=0;
  70.    eas.es_TextFormat=argv[1];
  71.    if (argc>2)
  72.       {
  73.       ret=atoi(argv[2]);
  74.       if (ret>0) sec=ret;
  75.       }
  76.    }
  77.  
  78. if (IntuitionBase=(struct Library *)OpenLibrary("intuition.library",37))
  79.    {
  80.    if (tp=(struct MsgPort *)CreatePort(NULL,NULL))
  81.       {
  82.       tbit=1<<tp->mp_SigBit;
  83.       if (tim=(struct timerequest *)CreateExtIO(tp,sizeof(struct timerequest)))
  84.          {
  85.          if (!OpenDevice(TIMERNAME,UNIT_VBLANK,tim,0))
  86.             {
  87.             if (win=(struct window *)BuildEasyRequest(NULL,&eas,NULL,NULL))
  88.                {
  89.                ibit=1<<win->UserPort->mp_SigBit;
  90.                tim->tr_node.io_Command=TR_ADDREQUEST;
  91.                tim->tr_time.tv_secs   =sec;
  92.                tim->tr_time.tv_micro  =0;
  93.                SendIO(tim);
  94.                while ((ret=SysReqHandler(win,NULL,FALSE))==-2 && signal==0) signal=Wait(tbit | ibit);
  95.                if (signal & tbit) GetMsg(tp);
  96.                }
  97.             else CleanUp("Can't open requester",RETURN_FAIL);
  98.             }
  99.          else CleanUp("Can't open timer.device",RETURN_FAIL);
  100.          }
  101.       else CleanUp("Cant create Timerequest",RETURN_FAIL);
  102.       }
  103.    else CleanUp("Can't open MsgPort",RETURN_FAIL);
  104.    }
  105. else CleanUp("Can't open intuition.library",RETURN_FAIL);
  106. if (ret<0) ret=0;
  107. CleanUp("",ret*5);
  108. }
  109.  
  110. /* Esce in modo pulito */
  111. void CleanUp(char *s,ULONG a)
  112. {
  113. if (win)             FreeSysRequest(win);
  114. if (tim)
  115.    {
  116.    AbortIO(tim);
  117.    if (tim->tr_node.io_Device) CloseDevice(tim);
  118.    DeleteExtIO(tim);
  119.    }
  120. if (tp)              DeletePort(tp);
  121. if (IntuitionBase)   CloseLibrary(IntuitionBase);
  122. if (*s)               printf("%s\n",s);
  123. exit(a);
  124. }
  125.  
  126.