Added all of the MH sources, including RCS files, in
[mmh] / docs / historical / mh-6.8.5 / uip / RCS / whom.c,v
1 head    1.11;
2 access;
3 symbols;
4 locks; strict;
5 comment @ * @;
6
7
8 1.11
9 date    92.12.15.00.20.22;      author jromine; state Exp;
10 branches;
11 next    1.10;
12
13 1.10
14 date    92.11.04.02.28.49;      author jromine; state Exp;
15 branches;
16 next    1.9;
17
18 1.9
19 date    92.05.19.21.00.21;      author jromine; state Exp;
20 branches;
21 next    1.8;
22
23 1.8
24 date    92.02.10.17.33.44;      author jromine; state Exp;
25 branches;
26 next    1.7;
27
28 1.7
29 date    92.01.31.22.30.01;      author jromine; state Exp;
30 branches;
31 next    1.6;
32
33 1.6
34 date    92.01.31.16.35.55;      author jromine; state Exp;
35 branches;
36 next    1.5;
37
38 1.5
39 date    92.01.30.22.39.58;      author jromine; state Exp;
40 branches;
41 next    1.4;
42
43 1.4
44 date    90.04.05.15.00.25;      author sources; state Exp;
45 branches;
46 next    1.3;
47
48 1.3
49 date    90.03.16.15.27.30;      author sources; state Exp;
50 branches;
51 next    1.2;
52
53 1.2
54 date    90.02.05.15.32.06;      author sources; state Exp;
55 branches;
56 next    1.1;
57
58 1.1
59 date    90.02.05.15.31.51;      author sources; state Exp;
60 branches;
61 next    ;
62
63
64 desc
65 @@
66
67
68 1.11
69 log
70 @endif sugar
71 @
72 text
73 @/* whom.c - report who a message would go to */
74 #ifndef lint
75 static char ident[] = "@@(#)$Id: whom.c,v 1.10 1992/11/04 02:28:49 jromine Exp jromine $";
76 #endif  /* lint */
77
78 #include "../h/mh.h"
79 #include <stdio.h>
80 #include <signal.h>
81 #ifdef LOCALE
82 #include        <locale.h>
83 #endif
84
85 /* \f */
86
87 static struct swit switches[] = {
88 #define ALIASW  0
89     "alias aliasfile", 0,
90
91 #define CHKSW   1
92     "check", 0,
93 #define NOCHKSW 2
94     "nocheck", 0,
95
96 #define DRAFTSW 3
97     "draft", 0,
98
99 #define DFOLDSW 4
100     "draftfolder +folder", 6,
101 #define DMSGSW  5
102     "draftmessage msg", 6,
103 #define NDFLDSW 6
104     "nodraftfolder", 0,
105
106 #define HELPSW  7
107     "help", 4,
108
109 #define CLIESW  8
110     "client host", -6,
111 #define SERVSW  9
112     "server host", -6,
113 #define SNOOPSW 10
114     "snoop", -5,
115
116     NULL, 0
117 };
118
119 /* \f */
120
121 /* ARGSUSED */
122
123 main (argc, argv)
124 int     argc;
125 char   *argv[];
126 {
127     int     child_id,
128             i,
129             status,
130             isdf = 0,
131             distsw = 0,
132             vecp = 0;
133     char   *cp,
134            *dfolder = NULL,
135            *dmsg = NULL,
136            *msg = NULL,
137           **ap,
138           **argp,
139             backup[BUFSIZ],
140             buf[100],
141            *arguments[MAXARGS],
142            *vec[MAXARGS];
143
144 #ifdef LOCALE
145         setlocale(LC_ALL, "");
146 #endif
147     invo_name = r1bindex (argv[0], '/');
148     if ((cp = m_find (invo_name)) != NULL) {
149         ap = brkstring (cp = getcpy (cp), " ", "\n");
150         ap = copyip (ap, arguments);
151     }
152     else
153         ap = arguments;
154     (void) copyip (argv + 1, ap);
155     argp = arguments;
156
157     vec[vecp++] = invo_name;
158     vec[vecp++] = "-whom";
159     vec[vecp++] = "-library";
160     vec[vecp++] = getcpy (m_maildir (""));
161
162 /* \f */
163
164     while (cp = *argp++) {
165         if (*cp == '-')
166             switch (smatch (++cp, switches)) {
167                 case AMBIGSW: 
168                     ambigsw (cp, switches);
169                     done (1);
170                 case UNKWNSW: 
171                     adios (NULLCP, "-%s unknown", cp);
172                 case HELPSW: 
173                     (void) sprintf (buf, "%s [switches] [file]", invo_name);
174                     help (buf, switches);
175                     done (1);
176
177                 case CHKSW: 
178                 case NOCHKSW: 
179                 case SNOOPSW:
180                     vec[vecp++] = --cp;
181                     continue;
182
183                 case DRAFTSW:
184                     msg = draft;
185                     continue;
186
187                 case DFOLDSW: 
188                     if (dfolder)
189                         adios (NULLCP, "only one draft folder at a time!");
190                     if (!(cp = *argp++) || *cp == '-')
191                         adios (NULLCP, "missing argument to %s", argp[-2]);
192                     dfolder = path (*cp == '+' || *cp == '@@' ? cp + 1 : cp,
193                             *cp != '@@' ? TFOLDER : TSUBCWF);
194                     continue;
195                 case DMSGSW: 
196                     if (dmsg)
197                         adios (NULLCP, "only one draft message at a time!");
198                     if (!(dmsg = *argp++) || *dmsg == '-')
199                         adios (NULLCP, "missing argument to %s", argp[-2]);
200                     continue;
201                 case NDFLDSW: 
202                     dfolder = NULL;
203                     isdf = NOTOK;
204                     continue;
205
206                 case ALIASW: 
207                 case CLIESW: 
208                 case SERVSW: 
209                     vec[vecp++] = --cp;
210                     if (!(cp = *argp++) || *cp == '-')
211                         adios (NULLCP, "missing argument to %s", argp[-2]);
212                     vec[vecp++] = cp;
213                     continue;
214             }
215         if (msg)
216             adios (NULLCP, "only one draft at a time!");
217         else
218             vec[vecp++] = msg = cp;
219     }
220     if (cp = m_find ("Aliasfile")) {    /* allow Aliasfile: profile entry */
221         char *dp = NULL;
222
223         for (ap = brkstring(dp = getcpy(cp), " ", "\n"); ap && *ap; ap++) {
224             vec[vecp++] = "-alias";
225             vec[vecp++] = *ap;
226         }
227     }
228
229 /* \f */
230
231     if (msg == NULL) {
232 #ifdef  WHATNOW
233         if (dfolder || (cp = getenv ("mhdraft")) == NULL || *cp == '\0')
234 #endif  /* WHATNOW */
235             cp  = getcpy (m_draft (dfolder, dmsg, 1, &isdf));
236         msg = vec[vecp++] = cp;
237     }
238     if ((cp = getenv ("mhdist"))
239             && *cp
240             && (distsw = atoi (cp))
241             && (cp = getenv ("mhaltmsg"))
242             && *cp) {
243         if (distout (msg, cp, backup) == NOTOK)
244             done (1);
245         vec[vecp++] = "-dist";
246         distsw++;
247     }
248     vec[vecp] = NULL;
249
250     closefds (3);
251
252     if (distsw)
253         for (i = 0; (child_id = fork ()) == NOTOK && i < 5; i++)
254             sleep (5);
255     switch (distsw ? child_id : OK) {
256         case NOTOK:
257             advise (NULLCP, "unable to fork, so checking directly...");
258         case OK:
259             execvp (postproc, vec);
260             fprintf (stderr, "unable to exec ");
261             perror (postproc);
262             _exit (-1);
263
264         default:
265             (void) signal (SIGHUP, SIG_IGN);
266             (void) signal (SIGINT, SIG_IGN);
267             (void) signal (SIGQUIT, SIG_IGN);
268             (void) signal (SIGTERM, SIG_IGN);
269
270             status = pidwait (child_id, OK);
271
272             (void) unlink (msg);
273             if (rename (backup, msg) == NOTOK)
274                 adios (msg, "unable to rename %s to", backup);
275             done (status);
276     }
277 }
278 @
279
280
281 1.10
282 log
283 @LOCALE
284 @
285 text
286 @d3 2
287 a4 2
288 static char ident[] = "@@(#)$Id: whom.c,v 1.9 1992/05/19 21:00:21 jromine Exp jromine $";
289 #endif  lint
290 d162 1
291 a162 1
292 #endif  WHATNOW
293 @
294
295
296 1.9
297 log
298 @NULL->0
299 @
300 text
301 @d3 1
302 a3 1
303 static char ident[] = "@@(#)$Id: whom.c,v 1.8 1992/02/10 17:33:44 jromine Exp jromine $";
304 d9 3
305 d72 3
306 @
307
308
309 1.8
310 log
311 @allow "Aliasfile" to be multiple files
312 @
313 text
314 @d3 1
315 a3 1
316 static char ident[] = "@@(#)$Id: whom.c,v 1.7 1992/01/31 22:30:01 jromine Exp jromine $";
317 d155 1
318 a155 1
319         if (dfolder || (cp = getenv ("mhdraft")) == NULL || *cp == NULL)
320 @
321
322
323 1.7
324 log
325 @kerberos
326 @
327 text
328 @d3 1
329 a3 1
330 static char ident[] = "@@(#)$Id: whom.c,v 1.6 1992/01/31 16:35:55 jromine Exp jromine $";
331 d143 6
332 a148 2
333         vec[vecp++] = "-alias";
334         vec[vecp++] = getcpy(cp);
335 @
336
337
338 1.6
339 log
340 @Multimedia MH
341 @
342 text
343 @d3 1
344 a3 1
345 static char ident[] = "@@(#)$Id: whom.c,v 1.5 1992/01/30 22:39:58 jromine Exp $";
346 d41 1
347 a41 1
348     NULL, NULL
349 @
350
351
352 1.5
353 log
354 @remove WP
355 @
356 text
357 @d3 1
358 a3 1
359 static char ident[] = "@@(#)$Id: whom.c,v 1.4 1990/04/05 15:00:25 sources Exp jromine $";
360 d151 1
361 a151 1
362         if ((cp = getenv ("mhdraft")) == NULL || *cp == NULL)
363 @
364
365
366 1.4
367 log
368 @add ID
369 @
370 text
371 @d3 1
372 a3 1
373 static char ident[] = "@@(#)$Id:$";
374 a40 3
375 #define FILLSW  11
376     "fill-in file", -7,
377
378 a130 1
379                 case FILLSW:
380 @
381
382
383 1.3
384 log
385 @add "Aliasfile: file" profile entry (like -alias file)
386 @
387 text
388 @d2 3
389 @
390
391
392 1.2
393 log
394 @WP Changes -- "-fill-in file"
395 @
396 text
397 @d143 4
398 @
399
400
401 1.1
402 log
403 @Initial revision
404 @
405 text
406 @d38 3
407 d131 1
408 @