1: /* whom.c - report who a message would go to */
   2: 
   3: #include "../h/mh.h"
   4: #include <stdio.h>
   5: #include <signal.h>
   6: 
   7: /*  */
   8: 
   9: static struct swit switches[] = {
  10: #define ALIASW  0
  11:     "alias aliasfile", 0,
  12: 
  13: #define CHKSW   1
  14:     "check", 0,
  15: #define NOCHKSW 2
  16:     "nocheck", 0,
  17: 
  18: #define DRAFTSW 3
  19:     "draft", 0,
  20: 
  21: #define DFOLDSW 4
  22:     "draftfolder +folder", 6,
  23: #define DMSGSW  5
  24:     "draftmessage msg", 6,
  25: #define NDFLDSW 6
  26:     "nodraftfolder", 0,
  27: 
  28: #define HELPSW  7
  29:     "help", 4,
  30: 
  31: #define CLIESW  8
  32:     "client host", -6,
  33: #define SERVSW  9
  34:     "server host", -6,
  35: #define SNOOPSW 10
  36:     "snoop", -5,
  37: 
  38:     NULL, NULL
  39: };
  40: 
  41: /*  */
  42: 
  43: /* ARGSUSED */
  44: 
  45: main (argc, argv)
  46: int     argc;
  47: char   *argv[];
  48: {
  49:     int     child_id,
  50:         i,
  51:         status,
  52:         isdf = 0,
  53:         distsw = 0,
  54:             vecp = 0;
  55:     char   *cp,
  56:        *dfolder = NULL,
  57:        *dmsg = NULL,
  58:            *msg = NULL,
  59:           **ap,
  60:           **argp,
  61:         backup[BUFSIZ],
  62:             buf[100],
  63:            *arguments[MAXARGS],
  64:            *vec[MAXARGS];
  65: 
  66:     invo_name = r1bindex (argv[0], '/');
  67:     if ((cp = m_find (invo_name)) != NULL) {
  68:     ap = brkstring (cp = getcpy (cp), " ", "\n");
  69:     ap = copyip (ap, arguments);
  70:     }
  71:     else
  72:     ap = arguments;
  73:     (void) copyip (argv + 1, ap);
  74:     argp = arguments;
  75: 
  76:     vec[vecp++] = invo_name;
  77:     vec[vecp++] = "-whom";
  78:     vec[vecp++] = "-library";
  79:     vec[vecp++] = getcpy (m_maildir (""));
  80: 
  81: /*  */
  82: 
  83:     while (cp = *argp++) {
  84:     if (*cp == '-')
  85:         switch (smatch (++cp, switches)) {
  86:         case AMBIGSW:
  87:             ambigsw (cp, switches);
  88:             done (1);
  89:         case UNKWNSW:
  90:             adios (NULLCP, "-%s unknown", cp);
  91:         case HELPSW:
  92:             (void) sprintf (buf, "%s [switches] [file]", invo_name);
  93:             help (buf, switches);
  94:             done (1);
  95: 
  96:         case CHKSW:
  97:         case NOCHKSW:
  98:         case SNOOPSW:
  99:             vec[vecp++] = --cp;
 100:             continue;
 101: 
 102:         case DRAFTSW:
 103:             msg = draft;
 104:             continue;
 105: 
 106:         case DFOLDSW:
 107:             if (dfolder)
 108:             adios (NULLCP, "only one draft folder at a time!");
 109:             if (!(cp = *argp++) || *cp == '-')
 110:             adios (NULLCP, "missing argument to %s", argp[-2]);
 111:             dfolder = path (*cp == '+' || *cp == '@' ? cp + 1 : cp,
 112:                 *cp != '@' ? TFOLDER : TSUBCWF);
 113:             continue;
 114:         case DMSGSW:
 115:             if (dmsg)
 116:             adios (NULLCP, "only one draft message at a time!");
 117:             if (!(dmsg = *argp++) || *dmsg == '-')
 118:             adios (NULLCP, "missing argument to %s", argp[-2]);
 119:             continue;
 120:         case NDFLDSW:
 121:             dfolder = NULL;
 122:             isdf = NOTOK;
 123:             continue;
 124: 
 125:         case ALIASW:
 126:         case CLIESW:
 127:         case SERVSW:
 128:             vec[vecp++] = --cp;
 129:             if (!(cp = *argp++) || *cp == '-')
 130:             adios (NULLCP, "missing argument to %s", argp[-2]);
 131:             vec[vecp++] = cp;
 132:             continue;
 133:         }
 134:     if (msg)
 135:         adios (NULLCP, "only one draft at a time!");
 136:     else
 137:         vec[vecp++] = msg = cp;
 138:     }
 139: 
 140: /*  */
 141: 
 142:     if (msg == NULL) {
 143: #ifdef  WHATNOW
 144:     if ((cp = getenv ("mhdraft")) == NULL || *cp == NULL)
 145: #endif	WHATNOW
 146:         cp  = getcpy (m_draft (dfolder, dmsg, 1, &isdf));
 147:     msg = vec[vecp++] = cp;
 148:     }
 149:     if ((cp = getenv ("mhdist"))
 150:         && *cp
 151:         && (distsw = atoi (cp))
 152:         && (cp = getenv ("mhaltmsg"))
 153:         && *cp) {
 154:     if (distout (msg, cp, backup) == NOTOK)
 155:         done (1);
 156:     vec[vecp++] = "-dist";
 157:     distsw++;
 158:     }
 159:     vec[vecp] = NULL;
 160: 
 161:     closefds (3);
 162: 
 163:     if (distsw)
 164:     for (i = 0; (child_id = fork ()) == NOTOK && i < 5; i++)
 165:         sleep (5);
 166:     switch (distsw ? child_id : OK) {
 167:     case NOTOK:
 168:             advise (NULLCP, "unable to fork, so checking directly...");
 169:     case OK:
 170:         execvp (postproc, vec);
 171:         fprintf (stderr, "unable to exec ");
 172:         perror (postproc);
 173:         _exit (-1);
 174: 
 175:     default:
 176:         (void) signal (SIGHUP, SIG_IGN);
 177:         (void) signal (SIGINT, SIG_IGN);
 178:         (void) signal (SIGQUIT, SIG_IGN);
 179:         (void) signal (SIGTERM, SIG_IGN);
 180: 
 181:         status = pidwait (child_id, OK);
 182: 
 183:         (void) unlink (msg);
 184:         if (rename (backup, msg) == NOTOK)
 185:         adios (msg, "unable to rename %s to", backup);
 186:         done (status);
 187:     }
 188: }

Defined functions

main defined in line 45; never used

Defined variables

switches defined in line 9; used 3 times

Defined macros

ALIASW defined in line 10; never used
CHKSW defined in line 13; never used
CLIESW defined in line 31; never used
DFOLDSW defined in line 21; never used
DMSGSW defined in line 23; never used
DRAFTSW defined in line 18; never used
HELPSW defined in line 28; never used
NDFLDSW defined in line 25; never used
NOCHKSW defined in line 15; never used
SERVSW defined in line 33; never used
SNOOPSW defined in line 35; never used
Last modified: 1985-10-27
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 974
Valid CSS Valid XHTML 1.0 Strict