home *** CD-ROM | disk | FTP | other *** search
/ back2roots/padua / padua.7z / padua / uucp / duucp-1.17 / AU-117b4-src.lha / src / util / inform.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-24  |  4.3 KB  |  198 lines

  1. /*
  2.  *  INFORM how click-cmd "text" [-x file-to-delete-on-exit]
  3.  *
  4.  *  (C) Copyright 1989-1990 by Matthew Dillon,    All Rights Reserved.
  5.  *
  6.  *  INFORM mail - "You have new mail"
  7.  *
  8.  *  Brings up an unobtrusive window saying that you have new mail and waits
  9.  *  for the user to hit the close box or double click the title bar.  If
  10.  *  the title bar is double clicked
  11.  *
  12.  *  Multiple runs of the same command with the same 'how' field do not cause
  13.  *  further requesters to come up.  Note that sendmail also has a lockout
  14.  *  mechanism by way of a temporary file which is not deleted until
  15.  *  inform exits (the -x option).
  16.  */
  17.  
  18. #include <exec/types.h>
  19. #include <exec/ports.h>
  20. #include <exec/lists.h>
  21. #include <exec/memory.h>
  22.  
  23. #include <dos/dos.h>
  24. #include <dos/exall.h>
  25. #include <dos/dosasl.h>
  26.  
  27. #include <intuition/classes.h>
  28. #include <intuition/intuition.h>
  29. #include <pragmas/intuition_pragmas.h>
  30.  
  31. #include <graphics/graphint.h>
  32. #include <graphics/scale.h>
  33. #include <pragmas/graphics_pragmas.h>
  34.  
  35. #define LIBRARIES_MATHFFP_H
  36. #include <clib/alib_protos.h>
  37. #undef    LIBRARIES_MATHFFP_H
  38. #include <clib/exec_protos.h>
  39. #include <clib/dos_protos.h>
  40. #include <clib/intuition_protos.h>
  41.  
  42. #include <string.h>
  43. #include <stdio.h>
  44. #include <stdlib.h>
  45. #include "protos.h"
  46. #include "config.h"
  47. #include "version.h"
  48. #include <owndevunit.h>
  49.  
  50. #define TBFI    0   /*    meaningless */
  51.  
  52. IDENT(".01");
  53.  
  54. struct Window    *Win;
  55. struct MsgPort    *Port;
  56.  
  57. struct IntuitionBase *IntuitionBase;
  58. struct GfxBase         *GfxBase;
  59.  
  60. struct NewWindow Nw = {
  61.     320, 0, TBFI, 10, (unsigned char)-1, (unsigned char)-1,
  62.     CLOSEWINDOW|MOUSEBUTTONS,
  63.     WINDOWCLOSE|BACKDROP|SIMPLE_REFRESH|RMBTRAP|NOCAREREFRESH,
  64.     NULL, NULL, TBFI, NULL, NULL, 0, 0, (unsigned short)-1, (unsigned short)-1, WBENCHSCREEN
  65. };
  66.  
  67. static int    newXPos = -1;        /* MRR, 01-25-91 - user-spec. X coord. */
  68.  
  69. Local void myexit(void);
  70. Local int WaitWinAction(void);
  71.  
  72. char *DelFile;
  73. struct Library *OwnDevUnitBase;
  74.  
  75. int
  76. main(int ac, char **av)
  77. {
  78.     static char pubname[64];
  79.  
  80.     atexit(myexit);
  81.  
  82.     if ((OwnDevUnitBase = OpenLibrary ((UBYTE *) ODU_NAME, 0)) == NULL) {
  83.     puts("Couldn't open lock library");
  84.     exit(20);
  85.     }
  86.  
  87.  
  88.     {
  89.     short i;
  90.     for (i = 4; i < ac; ++i) {
  91.         char *ptr = av[i];
  92.         if (*ptr == '-') {
  93.         ptr += 2;
  94.         switch(ptr[-1]) {
  95.         case 'x':
  96.             if (*ptr)
  97.             DelFile = ptr;
  98.             else
  99.             DelFile = av[++i];
  100.             break;
  101.         case 'p':               /* MRR, 01-25-91 - position <x-coord> */
  102.             /* Form may be -p<x> or -p <x> */
  103.             if (! *ptr) ptr = av[++i];
  104.             newXPos = atoi(ptr); /* MRR - need range checking? */
  105.         }
  106.         }
  107.     }
  108.     }
  109.  
  110.     if (ac < 3) {
  111.     fprintf(stderr, "Inform id clickcmd text\n");
  112.     exit(1);
  113.     }
  114.     sprintf(pubname, "Inform.%s", av[1]);
  115.     LockFile("T:Inform");
  116.     if (FindPort ((UBYTE *) pubname) == NULL)
  117.     Port = CreatePort ((UBYTE *) pubname, 0);
  118.     UnLockFile("T:Inform");
  119.     if (Port) {
  120.     IntuitionBase = (struct IntuitionBase *) OpenLibrary ((UBYTE *) "intuition.library", 0);
  121.     GfxBase       = (struct GfxBase *) OpenLibrary ((UBYTE *) "graphics.library", 0);
  122.     if (IntuitionBase && GfxBase) {
  123.         Nw.Width = strlen(av[3]) * 8 + 40;
  124.         Nw.Title = (UBYTE *)av[3];
  125.         if (newXPos >= 0) Nw.LeftEdge = newXPos; /* MRR, 01-25-91 */
  126.         if (Win = OpenWindow (&Nw)) {
  127.         ShowTitle(Win->WScreen, 0);
  128.         if (WaitWinAction()) {
  129.             Execute ((UBYTE *)av [2], 0, 0);
  130.         }
  131.         }
  132.     }
  133.     }
  134.     if (DelFile)
  135.     remove(DelFile);
  136.     exit(0);
  137. }
  138.  
  139. Local int
  140. WaitWinAction()
  141. {
  142.     short click = 0;
  143.     short notdone = 1;
  144.     struct IntuiMessage *im;
  145.  
  146.     while (notdone) {
  147.     WaitPort(Win->UserPort);
  148.     while (im = (struct IntuiMessage *)GetMsg(Win->UserPort)) {
  149.         switch(im->Class) {
  150.         case MOUSEBUTTONS:
  151.         if (im->Code == SELECTDOWN) {
  152.             click = 1;
  153.             notdone = 0;
  154.             break;
  155.         }
  156.         break;
  157.         case CLOSEWINDOW:
  158.         notdone = 0;
  159.         break;
  160.         }
  161.         ReplyMsg((struct Message *)im);
  162.     }
  163.     }
  164.     CloseWindow(Win);
  165.     Win = NULL;
  166.     return((int)click);
  167. }
  168.  
  169. void
  170. myexit()
  171. {
  172.     if (Win) {
  173.     CloseWindow(Win);
  174.     Win = NULL;
  175.     }
  176.     if (GfxBase) {
  177.     CloseLibrary ((struct Library *) GfxBase);
  178.     GfxBase = NULL;
  179.     }
  180.     if (IntuitionBase) {
  181.     CloseLibrary ((struct Library *) IntuitionBase);
  182.     IntuitionBase = NULL;
  183.     }
  184.  
  185.     UnLockFiles();
  186.  
  187.     if (OwnDevUnitBase) {
  188.     CloseLibrary(OwnDevUnitBase);
  189.     OwnDevUnitBase = NULL;
  190.     }
  191.  
  192.     if (Port) {
  193.     Forbid();
  194.     DeletePort(Port);
  195.     Permit();
  196.     }
  197. }
  198.