home *** CD-ROM | disk | FTP | other *** search
- /*
- * INFORM how click-cmd "text" [-x file-to-delete-on-exit]
- *
- * (C) Copyright 1989-1990 by Matthew Dillon, All Rights Reserved.
- *
- * INFORM mail - "You have new mail"
- *
- * Brings up an unobtrusive window saying that you have new mail and waits
- * for the user to hit the close box or double click the title bar. If
- * the title bar is double clicked
- *
- * Multiple runs of the same command with the same 'how' field do not cause
- * further requesters to come up. Note that sendmail also has a lockout
- * mechanism by way of a temporary file which is not deleted until
- * inform exits (the -x option).
- */
-
- #include <exec/types.h>
- #include <exec/ports.h>
- #include <exec/lists.h>
- #include <exec/memory.h>
-
- #include <dos/dos.h>
- #include <dos/exall.h>
- #include <dos/dosasl.h>
-
- #include <intuition/classes.h>
- #include <intuition/intuition.h>
- #include <pragmas/intuition_pragmas.h>
-
- #include <graphics/graphint.h>
- #include <graphics/scale.h>
- #include <pragmas/graphics_pragmas.h>
-
- #define LIBRARIES_MATHFFP_H
- #include <clib/alib_protos.h>
- #undef LIBRARIES_MATHFFP_H
- #include <clib/exec_protos.h>
- #include <clib/dos_protos.h>
- #include <clib/intuition_protos.h>
-
- #include <string.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include "protos.h"
- #include "config.h"
- #include "version.h"
- #include <owndevunit.h>
-
- #define TBFI 0 /* meaningless */
-
- IDENT(".01");
-
- struct Window *Win;
- struct MsgPort *Port;
-
- struct IntuitionBase *IntuitionBase;
- struct GfxBase *GfxBase;
-
- struct NewWindow Nw = {
- 320, 0, TBFI, 10, (unsigned char)-1, (unsigned char)-1,
- CLOSEWINDOW|MOUSEBUTTONS,
- WINDOWCLOSE|BACKDROP|SIMPLE_REFRESH|RMBTRAP|NOCAREREFRESH,
- NULL, NULL, TBFI, NULL, NULL, 0, 0, (unsigned short)-1, (unsigned short)-1, WBENCHSCREEN
- };
-
- static int newXPos = -1; /* MRR, 01-25-91 - user-spec. X coord. */
-
- Local void myexit(void);
- Local int WaitWinAction(void);
-
- char *DelFile;
- struct Library *OwnDevUnitBase;
-
- int
- main(int ac, char **av)
- {
- static char pubname[64];
-
- atexit(myexit);
-
- if ((OwnDevUnitBase = OpenLibrary ((UBYTE *) ODU_NAME, 0)) == NULL) {
- puts("Couldn't open lock library");
- exit(20);
- }
-
-
- {
- short i;
- for (i = 4; i < ac; ++i) {
- char *ptr = av[i];
- if (*ptr == '-') {
- ptr += 2;
- switch(ptr[-1]) {
- case 'x':
- if (*ptr)
- DelFile = ptr;
- else
- DelFile = av[++i];
- break;
- case 'p': /* MRR, 01-25-91 - position <x-coord> */
- /* Form may be -p<x> or -p <x> */
- if (! *ptr) ptr = av[++i];
- newXPos = atoi(ptr); /* MRR - need range checking? */
- }
- }
- }
- }
-
- if (ac < 3) {
- fprintf(stderr, "Inform id clickcmd text\n");
- exit(1);
- }
- sprintf(pubname, "Inform.%s", av[1]);
- LockFile("T:Inform");
- if (FindPort ((UBYTE *) pubname) == NULL)
- Port = CreatePort ((UBYTE *) pubname, 0);
- UnLockFile("T:Inform");
- if (Port) {
- IntuitionBase = (struct IntuitionBase *) OpenLibrary ((UBYTE *) "intuition.library", 0);
- GfxBase = (struct GfxBase *) OpenLibrary ((UBYTE *) "graphics.library", 0);
- if (IntuitionBase && GfxBase) {
- Nw.Width = strlen(av[3]) * 8 + 40;
- Nw.Title = (UBYTE *)av[3];
- if (newXPos >= 0) Nw.LeftEdge = newXPos; /* MRR, 01-25-91 */
- if (Win = OpenWindow (&Nw)) {
- ShowTitle(Win->WScreen, 0);
- if (WaitWinAction()) {
- Execute ((UBYTE *)av [2], 0, 0);
- }
- }
- }
- }
- if (DelFile)
- remove(DelFile);
- exit(0);
- }
-
- Local int
- WaitWinAction()
- {
- short click = 0;
- short notdone = 1;
- struct IntuiMessage *im;
-
- while (notdone) {
- WaitPort(Win->UserPort);
- while (im = (struct IntuiMessage *)GetMsg(Win->UserPort)) {
- switch(im->Class) {
- case MOUSEBUTTONS:
- if (im->Code == SELECTDOWN) {
- click = 1;
- notdone = 0;
- break;
- }
- break;
- case CLOSEWINDOW:
- notdone = 0;
- break;
- }
- ReplyMsg((struct Message *)im);
- }
- }
- CloseWindow(Win);
- Win = NULL;
- return((int)click);
- }
-
- void
- myexit()
- {
- if (Win) {
- CloseWindow(Win);
- Win = NULL;
- }
- if (GfxBase) {
- CloseLibrary ((struct Library *) GfxBase);
- GfxBase = NULL;
- }
- if (IntuitionBase) {
- CloseLibrary ((struct Library *) IntuitionBase);
- IntuitionBase = NULL;
- }
-
- UnLockFiles();
-
- if (OwnDevUnitBase) {
- CloseLibrary(OwnDevUnitBase);
- OwnDevUnitBase = NULL;
- }
-
- if (Port) {
- Forbid();
- DeletePort(Port);
- Permit();
- }
- }
-