home *** CD-ROM | disk | FTP | other *** search
/ back2roots/padua / padua.7z / padua / uucp / auucp+-1.02 / fuucp_plus_src.lzh / util / inform.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-11-21  |  3.0 KB  |  152 lines

  1.  
  2. /*
  3.  *  INFORM how click-cmd "text" [-x file-to-delete-on-exit]
  4.  *
  5.  *  $Header: Beta:src/uucp/src/MUtil/RCS/inform.c,v 1.2 90/04/03 20:44:58 dillon Exp Locker: dillon $
  6.  *
  7.  *  (C) Copyright 1989-1990 by Matthew Dillon,  All Rights Reserved.
  8.  *
  9.  *  INFORM mail - "You have new mail"
  10.  *
  11.  *  Brings up an unobtrusive window saying that you have new mail and waits
  12.  *  for the user to hit the close box or double click the title bar.  If
  13.  *  the title bar is double clicked
  14.  *
  15.  *  Multiple runs of the same command with the same 'how' field do not cause
  16.  *  further requesters to come up.  Note that sendmail also has a lockout
  17.  *  mechanism by way of a temporary file which is not deleted until
  18.  *  inform exits (the -x option).
  19.  */
  20.  
  21. #include <exec/types.h>
  22. #include <exec/ports.h>
  23. #include <intuition/intuition.h>
  24.  
  25. #include <stdio.h>
  26. #include <stdlib.h>
  27. #include "protos.h"
  28. #include "config.h"
  29. #include "version.h"
  30.  
  31. #define TBFI    0   /*    meaningless */
  32.  
  33. IDENT(".00");
  34.  
  35. struct Window    *Win;
  36. struct MsgPort    *Port;
  37.  
  38. struct IntuitionBase *IntuitionBase;
  39. struct GfxBase         *GfxBase;
  40.  
  41. struct NewWindow Nw = {
  42.     320, 0, TBFI, 10, -1, -1,
  43.     CLOSEWINDOW|MOUSEBUTTONS,
  44.     WINDOWCLOSE|BACKDROP|SIMPLE_REFRESH|RMBTRAP|NOCAREREFRESH,
  45.     NULL, NULL, TBFI, NULL, NULL, 0, 0, -1, -1, WBENCHSCREEN
  46. };
  47.  
  48. Local void xexit(int);
  49. Local int WaitWinAction(void);
  50.  
  51. char *DelFile;
  52.  
  53. void
  54. main(ac, av)
  55. char *av[];
  56. {
  57.     static char pubname[64];
  58.  
  59.     {
  60.     short i;
  61.     for (i = 4; i < ac; ++i) {
  62.         char *ptr = av[i];
  63.         if (*ptr == '-') {
  64.         ptr += 2;
  65.         switch(ptr[-1]) {
  66.         case 'x':
  67.             if (*ptr)
  68.             DelFile = ptr;
  69.             else
  70.             DelFile = av[++i];
  71.             break;
  72.         }
  73.         }
  74.     }
  75.     }
  76.  
  77.     if (ac < 3) {
  78.     fprintf(stderr, "Inform id clickcmd text\n");
  79.     exit(1);
  80.     }
  81.     sprintf(pubname, "Inform.%s", av[1]);
  82.     LockFile("T:Inform");
  83.     if (FindPort(pubname) == NULL)
  84.     Port = CreatePort(pubname, 0);
  85.     UnLockFile("T:Inform");
  86.     if (Port) {
  87.     IntuitionBase = OpenLibrary("intuition.library", 0);
  88.     GfxBase       = OpenLibrary("graphics.library", 0);
  89.     if (IntuitionBase && GfxBase) {
  90.         Nw.Width = strlen(av[3]) * 8 + 32;
  91.         Nw.Title = (UBYTE *)av[3];
  92.         if (Win = OpenWindow(&Nw)) {
  93.         ShowTitle(Win->WScreen, 0);
  94.         if (WaitWinAction()) {
  95.             Execute(av[2], NULL, NULL);
  96.         }
  97.         }
  98.     }
  99.     }
  100.     if (DelFile)
  101.     remove(DelFile);
  102.     xexit(0);
  103. }
  104.  
  105. Local int
  106. WaitWinAction()
  107. {
  108.     short click = 0;
  109.     short notdone = 1;
  110.     struct IntuiMessage *im;
  111.  
  112.     while (notdone) {
  113.     WaitPort(Win->UserPort);
  114.     while (im = (struct IntuiMessage *)GetMsg(Win->UserPort)) {
  115.         switch(im->Class) {
  116.         case MOUSEBUTTONS:
  117.         if (im->Code == SELECTDOWN) {
  118.             click = 1;
  119.             notdone = 0;
  120.             break;
  121.         }
  122.         break;
  123.         case CLOSEWINDOW:
  124.         notdone = 0;
  125.         break;
  126.         }
  127.         ReplyMsg((struct Message *)im);
  128.     }
  129.     }
  130.     CloseWindow(Win);
  131.     Win = NULL;
  132.     return((int)click);
  133. }
  134.  
  135. Local void
  136. xexit(code)
  137. {
  138.     if (Win)
  139.     CloseWindow(Win);
  140.     if (GfxBase)
  141.     CloseLibrary(GfxBase);
  142.     if (IntuitionBase)
  143.     CloseLibrary(IntuitionBase);
  144.     if (Port) {
  145.     Forbid();
  146.     DeletePort(Port);
  147.     Permit();
  148.     }
  149.     exit(code);
  150. }
  151.  
  152.