/* This is a program to show a small clock on the workbench screen telling you what to do during the day. This is totally public domain; do as you wish with the source and executable. Would you pay money for it? */ struct NewWindow newwin = { 100,30, /* window XY origin relative to TopLeft of screen */ 460,11, /* window width and height */ 0,1, /* detail and block pens */ CLOSEWINDOW+ACTIVEWINDOW+INACTIVEWINDOW, /* IDCMP flags */ WINDOWCLOSE+RMBTRAP+WINDOWDRAG +NOCAREREFRESH+SMART_REFRESH, /* other window flags */ NULL, /* first gadget in gadget list */ NULL, /* custom CHECKMARK imagery */ NULL, /* window title */ NULL, /* custom screen pointer */ NULL, /* custom bitmap */ 5,5, /* minimum width and height */ 640,256, /* maximum width and height */ WBENCHSCREEN /* destination screen type */ }; struct MsgPort *timeport; struct timerequest timereq; void *IntuitionBase, *GfxBase; struct IntuiMessage *msg; struct Window *window; struct RastPort *rp; ULONG class; struct { int min,stop; } start,mtea,lunch,atea,quit; main() { readfile(); IntuitionBase = OpenLibrary("intuition.library",0); GfxBase = OpenLibrary("graphics.library",0); window = OpenWindow(&newwin); rp = window->RPort; SetWindowTitles(window,(void *)-1,"The Public Servant's Clock V1.0 by Michael Warner"); SetDrMd(rp,JAM1); drawtime(); timeport = CreatePort("clk_timeport",0); OpenDevice("timer.device",0,&timereq,0); timereq.tr_node.io_Message.mn_ReplyPort = timeport; timereq.tr_node.io_Command=TR_ADDREQUEST; timereq.tr_node.io_Flags=0; timereq.tr_node.io_Error=0; timereq.tr_time.tv_secs = 60; timereq.tr_time.tv_micro = 0; SendIO(&timereq); FOREVER { Wait(1<UserPort->mp_SigBit|1<mp_SigBit); if (msg=GetMsg(window->UserPort)) { class=msg->Class; ReplyMsg(msg); switch (class) { case ACTIVEWINDOW: case INACTIVEWINDOW: drawtime(); break; case CLOSEWINDOW: die("bye"); break; } } else { WaitIO(&timereq); drawtime(); timereq.tr_time.tv_secs = 60; timereq.tr_time.tv_micro = 0; SendIO(&timereq); } } } die(str) char *str; { if (strlen(str)) puts(str); if (timeport) { if (!CheckIO(&timereq)) { AbortIO(&timereq); WaitIO(&timereq); } CloseDevice(&timereq); DeletePort(timeport); } if (window) CloseWindow(window); exit(0); } readfile() { FILE *file; int p1,p2,p3,p4; char ch,str[80]; file = fopen("s:PublicService.dat","r"); if (!file) die("Couldn't find s:PublicService.dat"); while (!feof(file)) { fgets(str,80,file); sscanf(str,"%s %d.%d %d.%d\n",&ch,&p1,&p2,&p3,&p4); p1 = p1*60+p2; p2 = p3*60+p4; /* convert to minutes */ switch (ch) { case 'S': start.min=p1;break; case 'M': mtea.min=p1; mtea.stop=p2; break; case 'L': lunch.min=p1; lunch.stop=p2; break; case 'A': atea.min=p1; atea.stop=p2; break; case 'Q': quit.min=p1; break; } } fclose(file); } drawtime() /* draw time in window */ { int min; static struct DateStamp ds; static char str[160]; DateStamp((long *)&ds); min = ds.ds_Minute; str[0]=0; if (min1) strcat(str,"s"); } if (min) { if (hr) strcat(str," and "); if (min<20) { strcat(str,units[min]); } else { strcat(str,tens[min/10]); if (min%10) { strcat(str,"-"); strcat(str,units[min%10]); } } strcat(str," minute"); if (min>1) strcat(str,"s"); } }