home *** CD-ROM | disk | FTP | other *** search
- /***************************************************************************
- ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
- CommandReq -- Command File Requester
- Copyright 1987 Jay Johnson and Sam Morse
- ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
- Written by Jay Johnson and Sam Morse
- Version 1.0 July 17th 1987
- ***************************************************************************
- This program is public domain. The authors assume no liability for missuse
- of this program and are not liable for any damage incurred during use. Use
- at your own risk.
-
- This program may be used in commercial software ONLY with the written consent
- of the original authors.
-
- Please send modifications of this code to the below address so that we may
- better control the evalution and insure that the best revisions are included
- in updates.
- ****************************************************************************/
-
- #include <intuition/intuitionbase.h>
- #include <graphics/display.h>
- #include <graphics/text.h>
- #include <ctype.h>
-
- #define SEL_TIMEOUT 5
-
- extern char toupper();
-
- char def_font[] ="topaz.font";
-
- struct MsgPort *myTimerPort;
- struct IOStdReq *myTimerMsg;
-
- struct TextAttr TxtAt_Plain = { (UBYTE *)def_font, 8,
- FS_NORMAL, FPF_ROMFONT};
-
- USHORT midwb_img_dat[]= {
- 0xffff,
- 0xffff, 0xffff, 0xffff, 0xf800, 0x8000, 0x0000, 0x0000, 0x0000,
- 0x0800, 0x8000, 0x0000, 0x0000, 0x0000, 0x0800, 0x8000, 0x0000,
- 0x0000, 0x0000, 0x0800, 0x8000, 0x0000, 0x0000, 0x0000, 0x0800,
- 0x8000, 0x0000, 0x0000, 0x0000, 0x0800, 0x8000, 0x0000, 0x0000,
- 0x0000, 0x0800, 0x8000, 0x0000, 0x0000, 0x0000, 0x0800, 0x8000,
- 0x0000, 0x0000, 0x0000, 0x083c, 0x8000, 0x0000, 0x0000, 0x0000,
- 0x0800, 0x8000, 0x0000, 0x0000, 0x0000, 0x0a00, 0x8000, 0x0000,
- 0x0000, 0x0000, 0x0800, 0x8000, 0x0000, 0x0000, 0x0000, 0x0800,
- 0x8000, 0x0000, 0x0000, 0x0000, 0x0800, 0x8000, 0x0000, 0x0000,
- 0x0000, 0x0800, 0xffff, 0xffff, 0xffff, 0xffff, 0xf800, 0x0000,
- 0x0000, 0x0000, 0x0000, 0x0400, 0x3fff, 0xffff, 0xffff, 0xffff,
- 0xf400, 0x3fff, 0xffff, 0xffff, 0xffff, 0xf466, 0x3fff, 0xffff,
- 0xffff, 0xffff, 0xf760, 0x3fff, 0xffff, 0xffff, 0xffff, 0xf600,
- 0x3fff, 0xffff, 0xffff, 0xffff, 0xf400, 0x3fff, 0xffff, 0xffff,
- 0xffff, 0xf400, 0x3fff, 0xffff, 0xffff, 0xffff, 0xf400, 0x3fff,
- 0xffff, 0xffff, 0xffff, 0xf400, 0x3fff, 0xffff, 0xffff, 0xffff,
- 0xf400, 0x3fff, 0xffff, 0xffff, 0xffff, 0xf4e3, 0x3fff, 0xffff,
- 0xffff, 0xffff, 0xf400, 0x3fff, 0xffff, 0xffff, 0xffff, 0xf618,
- 0x3fff, 0xffff, 0xffff, 0xffff, 0xf400, 0x3fff, 0xffff, 0xffff,
- 0xffff, 0xf400, 0x0000, 0x0000, 0x0000, 0x0000, 0x0400, 0x0001,
-
- };
-
-
-
- struct Image midwb_img = {
- 0, 0,70, 16,2,(USHORT *)&midwb_img_dat,0xff,0x00, NULL};
-
-
- #include "commandreq.h"
-
- struct IntuitionBase *IntuitionBase;
- struct GfxBase *GfxBase;
- struct Window *cw;
-
- reqcommand(default_value)
- int default_value;
- {
-
- ULONG MessageClass,window_sigbit,timer_sigbit,actual_sigbit;
- USHORT code;
- SHORT gadgetID;
- APTR address;
- struct IntuiMessage *cwmess;
- BOOL go = TRUE;
- int retcode;
-
-
- if (!(cw = (struct Window *)OpenWindow(&commandreqwin)))
- exit(20);
-
- Request(&commandreq,cw);
-
- window_sigbit = (1 << (cw->UserPort->mp_SigBit));
- timer_sigbit = 0;
- if (default_value) {
- timer_sigbit = (1 << (myTimerPort->mp_SigBit));
- myTimerMsg->io_Command = TR_ADDREQUEST;
- myTimerMsg->io_Actual = default_value;
- myTimerMsg->io_Length = 0;
- SendIO(myTimerMsg);
- }
-
- do
- {
- actual_sigbit = Wait(window_sigbit | timer_sigbit);
- if (actual_sigbit & timer_sigbit) {
- GetMsg(myTimerPort);
- retcode = SEL_TIMEOUT;
- go = FALSE;
- }
- if (actual_sigbit & window_sigbit) {
- cwmess = (struct IntuiMessage *)GetMsg(cw->UserPort);
-
- MessageClass = cwmess->Class;
- code = cwmess->Code;
- address = cwmess->IAddress;
- ReplyMsg(cwmess);
-
- switch (MessageClass)
- {
- case GADGETUP:
- gadgetID = (((struct Gadget *) address)->GadgetID);
- switch (gadgetID)
- {
- case YES:
- case STOP:
- case NO:
- case FUNCT:
- retcode = GadgetID;
- go = FALSE;
- break;
- default:break;
- };
- break;
- default: break;
- };
- }
- } while(go);
- if (default_value)
- AbortIO(myTimerMsg);
- EndRequest(&commandreq,cw);
- CloseWindow(cw);
-
- return(retcode);
-
- }
-
- main(argc,argv)
- LONG argc;
- char *argv[];
- {
- int returncode,default_time,default_cmd,cmd_value;
-
- IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library",0);
- GfxBase = (struct GfxBase *)OpenLibrary("graphics.library",0);
- if (IntuitionBase == NULL || GfxBase == NULL) {
- printf("Can't open a Library!\n");
- exit(20);
- }
-
- if ((argc < 2) || (argc > 4)) {
- printf("Format: ExeReq 'Command' [default(yes/no/stop)] [seconds]\n");
- cl_libs();
- exit(20);
- }
-
- default_time = 0;
- default_cmd = 0;
- if (argc > 2) {
- default_time = 10;
- if (strcmpU(argv[2],"YES") == 0) default_cmd = YES;
- if (strcmpU(argv[2],"NO") == 0) default_cmd = NO;
- if (strcmpU(argv[2],"STOP") == 0) default_cmd = STOP;
- if (default_cmd == 0) {
- printf("Default Command Paramater Error.\n");
- cl_libs();
- exit(20);
- }
- }
- if (argc > 3) {
- default_time = atoi(argv[3]);
- if (default_time < 1 || default_time > 600) {
- printf("Default Timeout Paramater Error.\n");
- cl_libs();
- exit(20);
- }
- }
- if (default_time) {
- myTimerPort = CreatePort(0,0);
- if (myTimerPort == 0) {
- cl_libs();
- exit(20);
- }
- myTimerMsg = CreateStdIO(myTimerPort);
- if (myTimerMsg == 0) {
- DeletePort(myTimerPort);
- cl_libs();
- exit(20);
- }
- if (OpenDevice(TIMERNAME,UNIT_VBLANK,myTimerMsg,0) != 0) {
- DeleteStdIO(myTimerMsg);
- DeletePort(myTimerPort);
- cl_libs();
- exit(20);
- }
- }
- strcpy(command_sbuf_1,argv[1]);
- returncode = reqcommand(default_time);
-
- if (returncode == SEL_TIMEOUT) returncode = default_cmd;
- cmd_value = TRUE;
- if (returncode == YES || returncode == FUNCT)
- cmd_value = Execute(command_sbuf_1,0,0);
- if (default_time) {
- CloseDevice(myTimerMsg);
- DeleteStdIO(myTimerMsg);
- DeletePort(myTimerPort);
- }
- cl_libs();
- if (returncode == STOP || cmd_value == FALSE) exit(20);
- if (returncode == NO) exit(0);
- }
-
- cl_libs()
- {
- CloseLibrary(GfxBase);
- CloseLibrary(IntuitionBase);
- }
- strcmpU(s,t)
- char s[], t[];
- {
- int i;
-
- i = 0;
- while(toupper(s[i]) == toupper(t[i])) {
- if (s[i++] == '\0') return 0;
- }
- return toupper(s[i]) - toupper(t[i]);
- }
-
-