home *** CD-ROM | disk | FTP | other *** search
-
- /* This program is PD. Do with it as you will... */
-
-
- struct TextAttr topaz8 = {"topaz.font",8,0x00,0x01};
-
- UBYTE *labels[] = {
- (UBYTE *)"Disabled",
- (UBYTE *)"1 minute",
- (UBYTE *)"5 minutes",
- (UBYTE *)"15 minutes",
- (UBYTE *)"1 hour",
- NULL
- };
-
-
- APTR IntuitionBase,GadToolsBase,IconBase;
-
- void run_script(char *script)
- {
- char cmd[80];
- ULONG out;
-
- /* out = Open("CON:0/0/200/50/Output",MODE_NEWFILE);
- if (!out) return; */
- strcpy(cmd,"run <NIL: >NIL: sys:rexxc/rx "); strcat(cmd,script);
- /* Execute(cmd,0,out); */
- system(cmd);
- Delay(20);
- /* Close(out); */
- }
-
- struct NewGadget ng;
- struct timerequest timereq;
- struct Window *win;
- struct VisualInfo *vi;
- struct Gadget *glist,*gad;
- struct DiskObject *dob;
- struct MsgPort *timeport;
-
- void notify(char *str)
- {
- struct EasyStruct es;
-
- es.es_StructSize = sizeof(struct EasyStruct);
- es.es_Flags = 0;
- es.es_Title = "Aladdin Autosave";
- es.es_TextFormat = str;
- es.es_GadgetFormat = "OK";
- EasyRequest(win,&es,NULL,NULL);
- }
-
- void die(char *str)
- {
- if (str) notify(str);
- if (dob) FreeDiskObject(dob);
- if (win) CloseWindow(win);
- if (glist) FreeGadgets(glist);
- if (vi) FreeVisualInfo(vi);
- if (timereq.tr_node.io_Device) {
- if (timereq.tr_node.io_Command)
- if (!CheckIO(&timereq)) {
- AbortIO(&timereq); WaitIO(&timereq);
- }
- CloseDevice(&timereq);
- }
- if (timeport) DeletePort(timeport);
- if (GadToolsBase) CloseLibrary(GadToolsBase);
- if (IntuitionBase) CloseLibrary(IntuitionBase);
- exit(str?10:0);
- }
-
- void start_timer(int mins)
- {
- timereq.tr_time.tv_secs = mins?10*mins:-1;
- SendIO(&timereq);
- }
-
- void main(int argc, char *argv[])
- {
- extern struct WBStartup *WBenchMsg;
-
- struct IntuiMessage *msg; ULONG class; UWORD code;
- int mins=15,active;
- char *timestr,*script,*title;
-
- if (argc>0) exit(0); /* abort if CLI */
-
- IconBase = OpenLibrary("icon.library",0);
- if (dob=GetDiskObject(WBenchMsg->sm_ArgList->wa_Name)) {
- if (timestr=FindToolType(dob->do_ToolTypes,"MINUTES")) {
- mins = atoi(timestr);
- if (mins!=0 && mins!=1 && mins!=5 && mins!=15 && mins!=60) mins=15;
- }
- if (!(script=FindToolType(dob->do_ToolTypes,"SCRIPT"))) {
- script = "rexx:AutoSave.rexx";
- }
- if (!(title=FindToolType(dob->do_ToolTypes,"TITLE"))) {
- title = "AutoSave";
- }
- }
-
- IntuitionBase = OpenLibrary("intuition.library",0);
- GadToolsBase = OpenLibrary("gadtools.library",0);
-
- /* open window */
-
- vi = GetVisualInfo(LockPubScreen(NULL),TAG_DONE);
-
- gad = CreateContext(&glist);
- ng.ng_VisualInfo = vi; ng.ng_TextAttr = &topaz8;
- ng.ng_LeftEdge = 10; ng.ng_TopEdge = 15;
- ng.ng_Flags = PLACETEXT_RIGHT;
- ng.ng_TextAttr = &topaz8;
-
- switch (mins) {
- case 0: active=0; break;
- case 1: active=1; break;
- case 5: active=2; break;
- case 15: active=3; break;
- case 60: active=4; break;
- }
-
- gad = CreateGadget(MX_KIND,gad,&ng,
- GTMX_Labels,labels, GTMX_Spacing,2L, GTMX_Active,active, TAG_DONE);
- if (!gad) die("Couldn't create gadgets");
-
- win = OpenWindowTags(NULL,
- WA_Left,200L, WA_Top,50L, WA_Width,200L, WA_Height,70L,
- WA_IDCMP,MXIDCMP|CLOSEWINDOW,
- WA_Title,title,
- WA_Gadgets, glist,
- WA_ScreenTitle,"Autosave by Michael Warner 1992",
- WA_Flags,WINDOWCLOSE|WINDOWDRAG|WINDOWDEPTH|SMART_REFRESH|NOCAREREFRESH,
- WA_PubScreen,NULL, TAG_DONE
- );
- if (!win) die("Couldn't open window");
- GT_RefreshWindow(win,NULL);
-
- /* start timer */
-
- timeport = CreatePort(0,0);
- if (OpenDevice("timer.device",0,&timereq,0)) die("Couldn't open timer device");
- timereq.tr_node.io_Message.mn_ReplyPort = timeport;
- timereq.tr_node.io_Command=TR_ADDREQUEST;
- start_timer(mins);
-
- FOREVER {
- Wait(1L<<win->UserPort->mp_SigBit|1L<<timeport->mp_SigBit);
- if (CheckIO(&timereq)) { /* timer expired? */
- WaitIO(&timereq); run_script(script);
- start_timer(mins);
- }
- if (msg=GT_GetIMsg(win->UserPort)) {
- class = msg->Class; code = msg->Code; GT_ReplyIMsg(msg);
- switch (class) {
- case CLOSEWINDOW: die(NULL); break;
- case GADGETDOWN:
- switch (code) {
- case 0: mins=0; break;
- case 1: mins=1; break;
- case 2: mins=5; break;
- case 3: mins=15; break;
- case 4: mins=60; break;
- }
- if (!CheckIO(&timereq)) { /* timer still pending? */
- AbortIO(&timereq); WaitIO(&timereq);
- }
- start_timer(mins);
- break;
- }
- }
- }
- }
-
-