Added all of the MH sources, including RCS files, in
[mmh] / docs / historical / mh-6.8.5 / uip / RCS / whatnowsbr.c,v
1 head    1.24;
2 access;
3 symbols;
4 locks; strict;
5 comment @ * @;
6
7
8 1.24
9 date    95.12.06.21.04.47;      author jromine; state Exp;
10 branches;
11 next    1.23;
12
13 1.23
14 date    95.12.06.19.20.22;      author jromine; state Exp;
15 branches;
16 next    1.22;
17
18 1.22
19 date    94.04.21.19.23.38;      author jromine; state Exp;
20 branches;
21 next    1.21;
22
23 1.21
24 date    92.12.15.00.20.22;      author jromine; state Exp;
25 branches;
26 next    1.20;
27
28 1.20
29 date    92.12.11.22.16.54;      author jromine; state Exp;
30 branches;
31 next    1.19;
32
33 1.19
34 date    92.12.02.18.51.07;      author jromine; state Exp;
35 branches;
36 next    1.18;
37
38 1.18
39 date    92.11.04.02.28.36;      author jromine; state Exp;
40 branches;
41 next    1.17;
42
43 1.17
44 date    92.10.16.21.37.53;      author jromine; state Exp;
45 branches;
46 next    1.16;
47
48 1.16
49 date    92.10.16.16.52.13;      author jromine; state Exp;
50 branches;
51 next    1.15;
52
53 1.15
54 date    92.02.10.17.33.44;      author jromine; state Exp;
55 branches;
56 next    1.14;
57
58 1.14
59 date    92.01.31.22.29.48;      author jromine; state Exp;
60 branches;
61 next    1.13;
62
63 1.13
64 date    92.01.31.16.35.44;      author jromine; state Exp;
65 branches;
66 next    1.12;
67
68 1.12
69 date    92.01.30.22.39.58;      author jromine; state Exp;
70 branches;
71 next    1.11;
72
73 1.11
74 date    92.01.29.16.55.19;      author jromine; state Exp;
75 branches;
76 next    1.10;
77
78 1.10
79 date    91.01.23.15.43.31;      author mh;      state Exp;
80 branches;
81 next    1.9;
82
83 1.9
84 date    91.01.23.14.44.00;      author mh;      state Exp;
85 branches;
86 next    1.8;
87
88 1.8
89 date    90.12.27.16.07.11;      author mh;      state Exp;
90 branches;
91 next    1.7;
92
93 1.7
94 date    90.12.18.14.01.05;      author mh;      state Exp;
95 branches;
96 next    1.6;
97
98 1.6
99 date    90.04.05.14.59.26;      author sources; state Exp;
100 branches;
101 next    1.5;
102
103 1.5
104 date    90.03.22.23.17.17;      author sources; state Exp;
105 branches;
106 next    1.4;
107
108 1.4
109 date    90.02.06.13.38.03;      author sources; state Exp;
110 branches;
111 next    1.3;
112
113 1.3
114 date    90.02.05.15.31.31;      author sources; state Exp;
115 branches;
116 next    1.2;
117
118 1.2
119 date    90.01.29.16.28.13;      author sources; state Exp;
120 branches;
121 next    1.1;
122
123 1.1
124 date    90.01.29.16.27.52;      author sources; state Exp;
125 branches;
126 next    ;
127
128
129 desc
130 @@
131
132
133 1.24
134 log
135 @add hidden -queued (for post?)
136 @
137 text
138 @/* whatnowsbr.c - the WhatNow shell */
139 #ifndef lint
140 static char ident[] = "@@(#)$Id: whatnowsbr.c,v 1.23 1995/12/06 19:20:22 jromine Exp jromine $";
141 #endif  /* lint */
142
143 #include "../h/mh.h"
144 #include <stdio.h>
145 #include <signal.h>
146 #include <sys/types.h>
147 #include <sys/stat.h>
148
149 #ifndef MIME
150 #define MIMEminc(a)     (a)
151 #else
152 #define MIMEminc(a)     0
153 #endif
154
155 static int      editfile(), copyf(), sendfile(), sendit(), whomfile();
156 #ifdef  MIME
157 static int      mhnfile();
158 #endif
159 /* \f */
160
161 static struct swit whatnowswitches[] = {
162 #define DFOLDSW 0
163     "draftfolder +folder", 0,
164 #define DMSGSW  1
165     "draftmessage msg", 0,
166 #define NDFLDSW 2
167     "nodraftfolder", 0,
168
169 #define EDITRSW 3
170     "editor editor", 0,
171 #define NEDITSW 4
172     "noedit", 0,
173
174 #define PRMPTSW 5
175     "prompt string", 4,
176
177 #define HELPSW  6
178     "help", 4,
179
180     NULL, 0
181 };
182
183 /* \f */
184
185 static struct swit aleqs[] = {
186 #define DISPSW  0
187     "display [<switches>]", 0,
188 #define EDITSW  1
189     "edit [<editor> <switches>]", 0,
190 #define LISTSW  2
191     "list [<switches>]", 0,
192 #define PUSHSW  3
193     "push [<switches>]", 0,
194 #define QUITSW  4
195     "quit [-delete]", 0,
196 #define REFILEOPT 5
197     "refile [<switches>] +folder", 0,
198 #define SENDSW  6
199     "send [<switches>]", 0,
200 #define WHOMSW  7
201     "whom [<switches>]", 0,
202
203     NULL, 0
204 };
205
206 /* \f */
207
208 static char *myprompt = "\nWhat now? ";
209
210 /* \f */
211
212 /* ARGSUSED */
213
214 int     WhatNow (argc, argv)
215 int     argc;
216 char  **argv;
217 {
218     int     isdf = 0,
219             nedit = 0,
220             use = 0;
221     char   *cp,
222            *dfolder = NULL,
223            *dmsg = NULL,
224            *ed = NULL,
225            *drft = NULL,
226            *msgnam = NULL,
227             buf[100],
228             prompt[BUFSIZ],
229           **ap,
230           **argp,
231            *arguments[MAXARGS];
232     struct stat st;
233
234     invo_name = r1bindex (argv[0], '/');
235     if ((cp = m_find (invo_name)) != NULL) {
236         ap = brkstring (cp = getcpy (cp), " ", "\n");
237         ap = copyip (ap, arguments);
238     }
239     else
240         ap = arguments;
241     (void) copyip (argv + 1, ap);
242     argp = arguments;
243
244 /* \f */
245
246     while (cp = *argp++) {
247         if (*cp == '-')
248             switch (smatch (++cp, whatnowswitches)) {
249                 case AMBIGSW: 
250                     ambigsw (cp, whatnowswitches);
251                     done (1);
252                 case UNKWNSW: 
253                     adios (NULLCP, "-%s unknown", cp);
254                 case HELPSW: 
255                     (void) sprintf (buf, "%s [switches] [file]", invo_name);
256                     help (buf, whatnowswitches);
257                     done (1);
258
259                 case DFOLDSW: 
260                     if (dfolder)
261                         adios (NULLCP, "only one draft folder at a time!");
262                     if (!(cp = *argp++) || *cp == '-')
263                         adios (NULLCP, "missing argument to %s", argp[-2]);
264                     dfolder = path (*cp == '+' || *cp == '@@' ? cp + 1 : cp,
265                             *cp != '@@' ? TFOLDER : TSUBCWF);
266                     continue;
267                 case DMSGSW: 
268                     if (dmsg)
269                         adios (NULLCP, "only one draft message at a time!");
270                     if (!(dmsg = *argp++) || *dmsg == '-')
271                         adios (NULLCP, "missing argument to %s", argp[-2]);
272                     continue;
273                 case NDFLDSW: 
274                     dfolder = NULL;
275                     isdf = NOTOK;
276                     continue;
277
278                 case EDITRSW: 
279                     if (!(ed = *argp++) || *ed == '-')
280                         adios (NULLCP, "missing argument to %s", argp[-2]);
281                     nedit = 0;
282                     continue;
283                 case NEDITSW: 
284                     nedit++;
285                     continue;
286
287                 case PRMPTSW:
288                     if (!(myprompt = *argp++) || *myprompt == '-')
289                         adios (NULLCP, "missing argument to %s", argp[-2]);
290                     continue;
291             }
292         if (drft)
293             adios (NULLCP, "only one draft at a time!");
294         else
295             drft = cp;
296     }
297
298 /* \f */
299
300     if (drft == NULL && (drft = getenv ("mhdraft")) == NULL || *drft == 0)
301         drft = getcpy (m_draft (dfolder, dmsg, 1, &isdf));
302     msgnam = (cp = getenv ("mhaltmsg")) && *cp ? getcpy (cp) : NULLCP;
303     if (ed == NULL && ((ed = getenv ("mheditor")) == NULL || *ed == 0))
304         ed = NULL, nedit++;
305     if ((cp = getenv ("mhuse")) && *cp)
306         use = atoi (cp);
307     if (!nedit
308             && editfile (&ed, NULLVP, drft, use, NULLMP, msgnam, NULLCP) < 0)
309         done (1);
310
311 /* \f */
312
313     (void) sprintf (prompt, myprompt, invo_name);
314     for (;;) {
315         if (!(argp = getans (prompt, aleqs))) {
316             (void) unlink (LINK);
317             done (1);
318         }
319         switch (smatch (*argp, aleqs)) {
320             case DISPSW: 
321                 if (msgnam)
322                     (void) showfile (++argp, msgnam);
323                 else
324                     advise (NULLCP, "no alternate message to display");
325                 break;
326
327             case EDITSW: 
328                 if (*++argp)
329                     ed = *argp++;
330                 if (editfile (&ed, argp, drft, NOUSE, NULLMP, msgnam, NULLCP)
331                         == NOTOK)
332                     done (1);
333                 break;
334
335             case LISTSW: 
336                 (void) showfile (++argp, drft);
337                 break;
338
339             case WHOMSW: 
340                 (void) whomfile (++argp, drft);
341                 break;
342
343             case QUITSW: 
344                 if (*++argp && (*argp[0] == 'd' ||
345                             ((*argp)[0] == '-' && (*argp)[1] == 'd'))) {
346                     if (unlink (drft) == NOTOK)
347                         adios (drft, "unable to unlink");
348                 }
349                 else
350                     if (stat (drft, &st) != NOTOK)
351                         advise (NULLCP, "draft left on %s", drft);
352                 done (1);
353
354             case PUSHSW: 
355                 if (sendfile (++argp, drft, 1))
356                     done (1);
357                 break;
358
359             case SENDSW: 
360                 (void) sendfile (++argp, drft, 0);
361                 break;
362
363             case REFILEOPT: 
364                 if (refile (++argp, drft) == 0)
365                     done (0);
366                 break;
367
368             default: 
369                 advise (NULLCP, "say what?");
370                 break;
371         }
372     }
373     /*NOTREACHED*/
374 }
375
376 /* \f   EDIT */
377
378 static int  reedit = 0;
379 static char *edsave = NULL;
380
381
382 /* ARGSUSED */
383
384 static  int editfile (ed, arg, file, use, mp, altmsg, cwd)
385 register struct msgs   *mp;
386 register char **ed,
387               **arg,
388                *file,
389                *altmsg,
390                *cwd;
391 register int    use;
392 {
393     int     pid,
394             status;
395     register int    vecp;
396     register char  *cp;
397     char    altpath[BUFSIZ],
398             linkpath[BUFSIZ],
399            *vec[MAXARGS];
400     struct stat st;
401 #ifdef BSD42
402 #ifdef  notdef
403     int     oumask;     /* PJS: for setting permissions on symlinks. */
404 #endif
405     int     slinked;
406 #endif  /* BSD42 */
407
408     if (!reedit) {              /* set initial editor */
409         if (*ed == NULL && (*ed = m_find ("editor")) == NULL)
410             *ed = sysed;
411     }
412     else
413         if (!*ed) {             /* no explicit editor */
414             *ed = edsave;
415             if ((cp = r1bindex (*ed, '/')) == NULL)
416                 cp = *ed;
417             cp = concat (cp, "-next", NULLCP);
418             if ((cp = m_find (cp)) != NULL)
419                 *ed = cp;
420         }
421
422     if (altmsg) {
423         if (mp == NULL || *altmsg == '/' || cwd == NULL)
424             (void) strcpy (altpath, altmsg);
425         else
426             (void) sprintf (altpath, "%s/%s", mp -> foldpath, altmsg);
427         if (cwd == NULL)
428             (void) strcpy (linkpath, LINK);
429         else
430             (void) sprintf (linkpath, "%s/%s", cwd, LINK);
431     }
432
433     if (altmsg) {
434         (void) unlink (linkpath);
435 #ifdef BSD42
436         if (link (altpath, linkpath) == NOTOK) {
437 #ifdef  notdef  /* I don't think permission on symlinks matters /JLR */
438             oumask = umask(0044);       /* PJS: else symlinks are world 'r' */
439 #endif
440             (void) symlink (altpath, linkpath);
441 #ifdef  notdef
442             umask(oumask);              /* PJS: else symlinks are world 'r' */
443 #endif
444             slinked = 1;
445         }
446         else
447             slinked = 0;
448 #else   /*  not BSD42 */
449         (void) link (altpath, linkpath);
450 #endif  /* not BSD42 */
451     }
452
453     m_update ();
454     (void) fflush (stdout);
455
456     switch (pid = vfork ()) {
457         case NOTOK: 
458             advise ("fork", "unable to");
459             status = NOTOK;
460             break;
461
462         case OK: 
463             if (cwd)
464                 (void) chdir (cwd);
465             if (altmsg) {
466                 if (mp)
467                     (void) m_putenv ("mhfolder", mp -> foldpath);
468                 (void) m_putenv ("editalt", altpath);
469             }
470
471             vecp = 0;
472             vec[vecp++] = r1bindex (*ed, '/');
473             if (arg)
474                 while (*arg)
475                     vec[vecp++] = *arg++;
476             vec[vecp++] = file;
477             vec[vecp] = NULL;
478
479             execvp (*ed, vec);
480             fprintf (stderr, "unable to exec ");
481             perror (*ed);
482             _exit (-1);
483
484         default: 
485             if (status = pidwait (pid, NOTOK)) {
486 #ifdef  ATTVIBUG
487                 if ((cp = r1bindex (*ed, '/'))
488                         && strcmp (cp, "vi") == 0
489                         && (status & 0x00ff) == 0)
490                     status = 0;
491                 else {
492 #endif
493                 if (((status & 0xff00) != 0xff00)
494                         && (!reedit || (status & 0x00ff)))
495                     if (!use && (status & 0xff00) &&
496                             (rename (file, cp = m_backup (file)) != NOTOK)) {
497                         advise (NULLCP, "problems with edit--draft left in %s",
498                                 cp);
499                     }
500                     else
501                         advise (NULLCP, "problems with edit--%s preserved",
502                                 file);
503                 status = -2;    /* maybe "reedit ? -2 : -1"? */
504                 break;
505 #ifdef  ATTVIBUG
506                 }
507 #endif
508             }
509
510             reedit++;
511 #ifdef BSD42
512             if (altmsg
513                     && mp
514                     && (!mp -> msgflags & READONLY)
515                     && (slinked
516                            ? lstat (linkpath, &st) != NOTOK
517                                 && (st.st_mode & S_IFMT) == S_IFREG
518                                 && copyf (linkpath, altpath) == NOTOK
519                            : stat (linkpath, &st) != NOTOK
520                                 && st.st_nlink == 1
521                                 && (unlink (altpath) == NOTOK
522                                         || link (linkpath, altpath) == NOTOK)))
523                 advise (linkpath, "unable to update %s from", altmsg);
524 #else   /* not BSD42 */
525             if (altmsg
526                     && mp
527                     && (!mp -> msgflags & READONLY)
528                     && stat (linkpath, &st) != NOTOK
529                     && st.st_nlink == 1
530                     && (unlink (altpath) == NOTOK
531                         || link (linkpath, altpath) == NOTOK))
532                 advise (linkpath, "unable to update %s from", altmsg);
533 #endif  /* not BSD42 */
534     }
535
536     edsave = getcpy (*ed);
537     *ed = NULL;
538     if (altmsg)
539         (void) unlink (linkpath);
540
541     return status;
542 }
543
544 /* \f */
545
546 #ifdef  BSD42
547 static int  copyf (ifile, ofile)
548 register char   *ifile,
549                 *ofile;
550 {
551     register int    i;
552     int     in,
553             out;
554     char    buffer[BUFSIZ];
555
556     if ((in = open (ifile, 0)) == NOTOK)
557         return NOTOK;
558     if ((out = open (ofile, 1)) == NOTOK || ftruncate (out, 0) == NOTOK) {
559         if (out != NOTOK) {
560             admonish (ofile, "unable to truncate");
561             (void) close (out);
562         }
563         (void) close (in);
564         return NOTOK;
565     }
566
567     while ((i = read (in, buffer, sizeof buffer)) > OK)
568         if (write (out, buffer, i) != i) {
569             advise (ofile, "may have damaged");
570             i = NOTOK;
571             break;
572         }
573
574     (void) close (in);
575     (void) close (out);
576
577     return i;
578 }
579 #endif  /* BSD42 */
580
581 /* \f   SEND */
582
583 static  sendfile (arg, file, pushsw)
584 register char **arg,
585                *file;
586 int     pushsw;
587 {
588     register int    child_id,
589                     i,
590                     vecp;
591     char *cp,
592          *sp,
593          *vec[MAXARGS];
594
595 #ifdef  MIME
596     if ((cp = m_find ("automhnproc"))
597             && !getenv ("NOMHNPROC")
598             && mhnfile (file)
599             && (i = editfile (&cp, NULLVP, file, NOUSE, NULLMP, NULLCP,
600                               NULLCP)))
601         return 0;
602 #endif
603
604     if (strcmp (sp = r1bindex (sendproc, '/'), "send") == 0) {
605         cp = invo_name;
606         sendit (invo_name = sp, arg, file, pushsw);
607         invo_name = cp;
608         return 1;
609     }
610
611     m_update ();
612     (void) fflush (stdout);
613
614     for (i = 0; (child_id = vfork ()) == NOTOK && i < 5; i++)
615         sleep (5);
616     switch (child_id) {
617         case NOTOK: 
618             advise (NULLCP, "unable to fork, so sending directly...");
619         case OK: 
620             vecp = 0;
621             vec[vecp++] = invo_name;
622             if (pushsw)
623                 vec[vecp++] = "-push";
624             if (arg)
625                 while (*arg)
626                     vec[vecp++] = *arg++;
627             vec[vecp++] = file;
628             vec[vecp] = NULL;
629
630             execvp (sendproc, vec);
631             fprintf (stderr, "unable to exec ");
632             perror (sendproc);
633             _exit (-1);
634
635         default: 
636             if (pidwait (child_id, OK) == 0)
637                 done (0);
638             return 1;
639     }
640 }
641
642 /* \f */
643
644 #ifdef MIME
645 #include "../h/mhn.h"
646
647
648 static int  mhnfile (msgnam)
649 char   *msgnam;
650 {
651     int     state;
652     char    buf[BUFSIZ],
653             name[NAMESZ];
654     FILE   *fp;
655
656     if ((fp = fopen (msgnam, "r")) == NULL)
657         return 0;
658     for (state = FLD;;)
659         switch (state = m_getfld (state, name, buf, sizeof buf, fp)) {
660             case FLD:
661             case FLDPLUS:
662             case FLDEOF:
663                 if (uleq (name, VRSN_FIELD) || uprf (name, XXX_FIELD_PRF)) {
664                     (void) fclose (fp);
665                     return 0;
666                 }
667                 while (state == FLDPLUS)
668                     state = m_getfld (state, name, buf, sizeof buf, fp);
669                 break;
670
671             case BODY:
672                 do {
673                     register char *bp;
674
675                     for (bp = buf; *bp; bp++)
676                         if (*bp != ' ' && *bp != '\t' && *bp != '\n') {
677                             (void) fclose (fp);
678                             return 1;
679                         }
680
681                     state = m_getfld (state, name, buf, sizeof buf, fp);
682                 } while (state == BODY);
683                 /* and fall... */
684
685             default:
686                 (void) fclose (fp);
687                 return 0;
688         }
689 }
690 #endif /* MIME */
691
692 /* \f */
693
694 static struct swit  sendswitches[] = {
695 #define ALIASW  0
696     "alias aliasfile", 0,
697
698 #define DEBUGSW 1
699     "debug", -5,
700
701 #define ENCRSW  2
702     "encrypt",
703 #ifndef TMA
704     -7,
705 #else   /* TMA */
706     0,
707 #endif  /* TMA */
708 #define NENCRSW 3
709     "noencrypt",
710 #ifndef TMA
711     -9,
712 #else   /* TMA */
713     0,
714 #endif  /* TMA */
715
716 #define FILTSW  4
717     "filter filterfile", 0,
718 #define NFILTSW 5
719     "nofilter", 0,
720
721 #define FRMTSW  6
722     "format", 0,
723 #define NFRMTSW 7
724     "noformat", 0,
725
726 #define FORWSW  8
727     "forward", 0,
728 #define NFORWSW 9
729     "noforward", 0,
730
731 #define MIMESW  10
732     "mime", MIMEminc(-4),
733 #define NMIMESW 11
734     "nomime", MIMEminc(-6),
735
736 #define MSGDSW  12
737     "msgid", 0,
738 #define NMSGDSW 13
739     "nomsgid", 0,
740
741 #define SPSHSW  14
742     "push", 0,
743 #define NSPSHSW 15
744     "nopush", 0,
745
746 #define SPLITSW 16
747     "split seconds", MIMEminc(-5),
748
749 #define UNIQSW  17
750     "unique", -6,
751 #define NUNIQSW 18
752     "nounique", -8,
753
754 #define VERBSW  19
755     "verbose", 0,
756 #define NVERBSW 20
757     "noverbose", 0,
758
759 #define WATCSW  21
760     "watch", 0,
761 #define NWATCSW 22
762     "nowatch", 0,
763
764 #define WIDTHSW 23
765     "width columns", 0,
766
767 #define SHELPSW 24
768     "help", 4,
769
770 #define MAILSW  25
771     "mail", -4,
772 #define SAMLSW  26
773     "saml", -4,
774 #define SSNDSW  27
775     "send", -4,
776 #define SOMLSW  28
777     "soml", -4,
778
779 #define CLIESW  29
780     "client host", -6,
781 #define SERVSW  30
782     "server host", -6,
783 #define SNOOPSW 31
784     "snoop", -5,
785
786 #define SDRFSW 32
787     "draftfolder +folder", -6,
788 #define SDRMSW 33
789     "draftmessage msg", -6,
790 #define SNDRFSW 34
791     "nodraftfolder", -3,
792
793 #define QUEUESW 35
794     "queued", -6,
795
796 #define RECORSW 36
797     "record program", -6,
798 #define NRECOSW 37
799     "norecord", -8,
800
801     NULL, 0
802 };
803
804 /* \f */
805
806 extern int debugsw;             /* from sendsbr.c */
807 extern int forwsw;
808 extern int inplace;
809 extern int pushsw;
810 extern int splitsw;
811 extern int unique;
812 extern int verbsw;
813
814 extern char *altmsg;            /*  .. */
815 extern char *annotext;
816 extern char *distfile;
817
818 /* \f */
819
820 static  sendit (sp, arg, file, pushed)
821 register char  *sp,
822               **arg,
823                *file;
824 int     pushed;
825 {
826 #ifndef lint
827     int     distsw = 0;
828 #endif  /* not lint */
829     int     vecp = 1;
830     char   *cp,
831             buf[100],
832           **ap,
833           **argp,
834            *arguments[MAXARGS],
835            *vec[MAXARGS];
836     struct stat st;
837 #ifdef  UCI
838     FILE   *fp;
839 #endif  /* UCI */
840
841     if (arg)
842         (void) copyip (arg, vec);
843     if ((cp = m_find (sp)) != NULL) {
844         ap = brkstring (cp = getcpy (cp), " ", "\n");
845         ap = copyip (ap, arguments);
846     }
847     else
848         ap = arguments;
849     if (arg)
850         (void) copyip (vec, ap);
851     argp = arguments;
852
853     debugsw = 0, forwsw = 1, inplace = 0, unique = 0;
854     altmsg = annotext = distfile = NULL;
855     vec[vecp++] = "-library";
856     vec[vecp++] = getcpy (m_maildir (""));
857
858 /* \f */
859
860     while (cp = *argp++) {
861         if (*cp == '-')
862             switch (smatch (++cp, sendswitches)) {
863                 case AMBIGSW: 
864                     ambigsw (cp, sendswitches);
865                     return;
866                 case UNKWNSW: 
867                     advise (NULLCP, "-%s unknown\n", cp);
868                     return;
869                 case SHELPSW: 
870                     (void) sprintf (buf, "%s [switches]", sp);
871                     help (buf, sendswitches);
872                     return;
873
874                 case SPSHSW: 
875                     pushed++;
876                     continue;
877                 case NSPSHSW: 
878                     pushed = 0;
879                     continue;
880
881                 case SPLITSW: 
882                     if (!(cp = *argp++) || sscanf (cp, "%d", &splitsw) != 1) {
883                         advise (NULLCP, "missing argument to %s", argp[-2]);
884                         return;
885                     }
886                     continue;
887
888                 case UNIQSW: 
889                     unique++;
890                     continue;
891                 case NUNIQSW: 
892                     unique = 0;
893                     continue;
894                 case FORWSW: 
895                     forwsw++;
896                     continue;
897                 case NFORWSW: 
898                     forwsw = 0;
899                     continue;
900
901                 case VERBSW: 
902                     verbsw++;
903                     vec[vecp++] = --cp;
904                     continue;
905                 case NVERBSW:
906                     verbsw = 0;
907                     vec[vecp++] = --cp;
908                     continue;
909
910                 case DEBUGSW: 
911                     debugsw++;  /* fall */
912                 case NFILTSW: 
913                 case FRMTSW: 
914                 case NFRMTSW: 
915                 case MIMESW: 
916                 case NMIMESW: 
917                 case MSGDSW: 
918                 case NMSGDSW: 
919                 case WATCSW: 
920                 case NWATCSW: 
921                 case MAILSW: 
922                 case SAMLSW: 
923                 case SSNDSW: 
924                 case SOMLSW: 
925                 case ENCRSW: 
926                 case NENCRSW: 
927                 case SNOOPSW: 
928                 case QUEUESW: 
929                 case NRECOSW: 
930                     vec[vecp++] = --cp;
931                     continue;
932
933                 case ALIASW: 
934                 case FILTSW: 
935                 case WIDTHSW: 
936                 case CLIESW: 
937                 case SERVSW: 
938                 case RECORSW: 
939                     vec[vecp++] = --cp;
940                     if (!(cp = *argp++) || *cp == '-') {
941                         advise (NULLCP, "missing argument to %s", argp[-2]);
942                         return;
943                     }
944                     vec[vecp++] = cp;
945                     continue;
946
947                 case SDRFSW: 
948                 case SDRMSW: 
949                     if (!(cp = *argp++) || *cp == '-') {
950                         advise (NULLCP, "missing argument to %s", argp[-2]);
951                         return;
952                     }
953                 case SNDRFSW: 
954                     continue;
955             }
956         advise (NULLCP, "usage: %s [switches]", sp);
957         return;
958     }
959     if (cp = m_find ("Aliasfile")) {    /* allow Aliasfile: profile entry */
960         char *dp = NULL;
961
962         for (ap = brkstring(dp = getcpy(cp), " ", "\n"); ap && *ap; ap++) {
963             vec[vecp++] = "-alias";
964             vec[vecp++] = *ap;
965         }
966     }
967
968 /* \f */
969
970 #ifdef  TMA
971     if ((cp = getenv ("KDS")) == NULL || *cp == NULL)
972         if ((cp = m_find ("kdsproc")) && *cp)
973             (void) m_putenv ("KDS", cp);
974     if ((cp = getenv ("TMADB")) == NULL || *cp == NULL)
975         if ((cp = m_find ("tmadb")) && *cp)
976             (void) m_putenv ("TMADB", m_maildir (cp));
977 #endif  /* TMA */
978
979     if ((cp = getenv ("SIGNATURE")) == NULL || *cp == 0)
980         if ((cp = m_find ("signature")) && *cp)
981             (void) m_putenv ("SIGNATURE", cp);
982 #ifdef  UCI
983         else {
984             (void) sprintf (buf, "%s/.signature", mypath);
985             if ((fp = fopen (buf, "r")) != NULL
986                 && fgets (buf, sizeof buf, fp) != NULL) {
987                     (void) fclose (fp);
988                     if (cp = index (buf, '\n'))
989                         *cp = 0;
990                     (void) m_putenv ("SIGNATURE", buf);
991             }
992         }
993 #endif  /* UCI */
994
995     if ((annotext = getenv ("mhannotate")) == NULL || *annotext == 0)
996         annotext = NULL;
997     if ((altmsg = getenv ("mhaltmsg")) == NULL || *altmsg == 0)
998         altmsg = NULL;
999     if (annotext && ((cp = getenv ("mhinplace")) != NULL && *cp != 0))
1000         inplace = atoi (cp);
1001
1002     if ((cp = getenv ("mhdist"))
1003             && *cp
1004 #ifndef lint
1005             && (distsw = atoi (cp))
1006 #endif  /* not lint */
1007             && altmsg) {
1008         vec[vecp++] = "-dist";
1009         distfile = getcpy (m_scratch (altmsg, invo_name));
1010         if (link (altmsg, distfile) == NOTOK)
1011             adios (distfile, "unable to link %s to", altmsg);
1012     }
1013     else
1014         distfile = NULL;
1015
1016     if (altmsg == NULL || stat (altmsg, &st) == NOTOK)
1017         st.st_mtime = 0, st.st_dev = 0, st.st_ino = 0;
1018     if (pushsw = pushed)
1019         push ();
1020
1021     vec[0] = r1bindex (postproc, '/');
1022     closefds (3);
1023
1024     if (sendsbr (vec, vecp, file, &st) == OK)
1025         done (0);
1026 }
1027
1028 /* \f   WHOM */
1029
1030 static  int whomfile (arg, file)
1031 register char **arg,
1032                *file;
1033 {
1034     int     pid;
1035     register int    vecp;
1036     char   *vec[MAXARGS];
1037
1038     m_update ();
1039     (void) fflush (stdout);
1040
1041     switch (pid = vfork ()) {
1042         case NOTOK: 
1043             advise ("fork", "unable to");
1044             return 1;
1045
1046         case OK: 
1047             vecp = 0;
1048             vec[vecp++] = r1bindex (whomproc, '/');
1049             vec[vecp++] = file;
1050             if (arg)
1051                 while (*arg)
1052                     vec[vecp++] = *arg++;
1053             vec[vecp] = NULL;
1054
1055             execvp (whomproc, vec);
1056             fprintf (stderr, "unable to exec ");
1057             perror (whomproc);
1058             _exit (-1);         /* NOTREACHED */
1059
1060         default: 
1061             return (pidwait (pid, NOTOK) & 0377 ? 1 : 0);
1062     }
1063 }
1064 @
1065
1066
1067 1.23
1068 log
1069 @fixes from mtr
1070 @
1071 text
1072 @d3 1
1073 a3 1
1074 static char ident[] = "@@(#)$Id: whatnowsbr.c,v 1.22 1994/04/21 19:23:38 jromine Exp jromine $";
1075 d656 4
1076 a659 1
1077 #define RECORSW 35
1078 d661 1
1079 a661 1
1080 #define NRECOSW 36
1081 d791 1
1082 @
1083
1084
1085 1.22
1086 log
1087 @mhn fixes from MTR
1088 @
1089 text
1090 @d3 1
1091 a3 1
1092 static char ident[] = "@@(#)$Id: whatnowsbr.c,v 1.21 1992/12/15 00:20:22 jromine Exp jromine $";
1093 d656 5
1094 d788 1
1095 d797 1
1096 @
1097
1098
1099 1.21
1100 log
1101 @endif sugar
1102 @
1103 text
1104 @d3 1
1105 a3 1
1106 static char ident[] = "@@(#)$Id: whatnowsbr.c,v 1.20 1992/12/11 22:16:54 jromine Exp jromine $";
1107 d526 1
1108 a526 1
1109                 if (uprf (name, XXX_FIELD_PRF)) {
1110 @
1111
1112
1113 1.20
1114 log
1115 @notreached
1116 @
1117 text
1118 @d3 2
1119 a4 2
1120 static char ident[] = "@@(#)$Id: whatnowsbr.c,v 1.19 1992/12/02 18:51:07 jromine Exp jromine $";
1121 #endif  lint
1122 d269 1
1123 a269 1
1124 #endif BSD42
1125 d311 1
1126 a311 1
1127 #else  not BSD42
1128 d313 1
1129 a313 1
1130 #endif not BSD42
1131 d387 1
1132 a387 1
1133 #else   not BSD42
1134 d396 1
1135 a396 1
1136 #endif  not BSD42
1137 d442 1
1138 a442 1
1139 #endif  BSD42
1140 d568 1
1141 a568 1
1142 #else   TMA
1143 d570 1
1144 a570 1
1145 #endif  TMA
1146 d575 1
1147 a575 1
1148 #else   TMA
1149 d577 1
1150 a577 1
1151 #endif  TMA
1152 d683 1
1153 a683 1
1154 #endif  not lint
1155 d694 1
1156 a694 1
1157 #endif  UCI
1158 d829 1
1159 a829 1
1160 #endif  TMA
1161 d845 1
1162 a845 1
1163 #endif  UCI
1164 d858 1
1165 a858 1
1166 #endif  not lint
1167 @
1168
1169
1170 1.19
1171 log
1172 @add decl
1173 @
1174 text
1175 @d3 1
1176 a3 1
1177 static char ident[] = "@@(#)$Id: whatnowsbr.c,v 1.18 1992/11/04 02:28:36 jromine Exp jromine $";
1178 d236 1
1179 a913 1
1180             break;
1181 @
1182
1183
1184 1.18
1185 log
1186 @m_putenv
1187 @
1188 text
1189 @d3 1
1190 a3 1
1191 static char ident[] = "@@(#)$Id: whatnowsbr.c,v 1.17 1992/10/16 21:37:53 jromine Exp jromine $";
1192 d19 3
1193 @
1194
1195
1196 1.17
1197 log
1198 @MIME changes
1199 @
1200 text
1201 @d3 1
1202 a3 1
1203 static char ident[] = "@@(#)$Id: whatnowsbr.c,v 1.16 1992/10/16 16:52:13 jromine Exp jromine $";
1204 d326 2
1205 a327 2
1206                     (void) putenv ("mhfolder", mp -> foldpath);
1207                 (void) putenv ("editalt", altpath);
1208 d821 1
1209 a821 1
1210             (void) putenv ("KDS", cp);
1211 d824 1
1212 a824 1
1213             (void) putenv ("TMADB", m_maildir (cp));
1214 d829 1
1215 a829 1
1216             (void) putenv ("SIGNATURE", cp);
1217 d838 1
1218 a838 1
1219                     (void) putenv ("SIGNATURE", buf);
1220 @
1221
1222
1223 1.16
1224 log
1225 @MIME ifdefs
1226 @
1227 text
1228 @d3 1
1229 a3 1
1230 static char ident[] = "@@(#)$Id: whatnowsbr.c,v 1.15 1992/02/10 17:33:44 jromine Exp jromine $";
1231 d12 6
1232 d215 3
1233 a217 2
1234                 sendfile (++argp, drft, 1);
1235                 done (1);
1236 d220 1
1237 a220 1
1238                 sendfile (++argp, drft, 0);
1239 d454 9
1240 d467 1
1241 a467 1
1242         return;
1243 d497 1
1244 a497 1
1245             return;
1246 d503 50
1247 d590 6
1248 a595 1
1249 #define MSGDSW  10
1250 d597 1
1251 a597 1
1252 #define NMSGDSW 11
1253 d600 1
1254 a600 1
1255 #define SPSHSW  12
1256 d602 1
1257 a602 1
1258 #define NSPSHSW 13
1259 d605 2
1260 a606 7
1261 #define SPLITSW 14
1262     "split seconds",
1263 #ifndef MIME
1264         -5,
1265 #else   /* MIME */
1266         0,
1267 #endif  /* MIME */
1268 d608 1
1269 a608 1
1270 #define UNIQSW  15
1271 d610 1
1272 a610 1
1273 #define NUNIQSW 16
1274 d613 1
1275 a613 1
1276 #define VERBSW  17
1277 d615 1
1278 a615 1
1279 #define NVERBSW 18
1280 d618 1
1281 a618 1
1282 #define WATCSW  19
1283 d620 1
1284 a620 1
1285 #define NWATCSW 20
1286 d623 1
1287 a623 1
1288 #define WIDTHSW 21
1289 d626 1
1290 a626 1
1291 #define SHELPSW 22
1292 d629 1
1293 a629 1
1294 #define MAILSW  23
1295 d631 1
1296 a631 1
1297 #define SAMLSW  24
1298 d633 1
1299 a633 1
1300 #define SSNDSW  25
1301 d635 1
1302 a635 1
1303 #define SOMLSW  26
1304 d638 1
1305 a638 1
1306 #define CLIESW  27
1307 d640 1
1308 a640 1
1309 #define SERVSW  28
1310 d642 1
1311 a642 1
1312 #define SNOOPSW 29
1313 d645 1
1314 a645 1
1315 #define SDRFSW 30
1316 d647 1
1317 a647 1
1318 #define SDRMSW 31
1319 d649 1
1320 a649 1
1321 #define SNDRFSW 32
1322 d766 2
1323 @
1324
1325
1326 1.15
1327 log
1328 @allow "Aliasfile" to be multiple files
1329 @
1330 text
1331 @d3 1
1332 a3 1
1333 static char ident[] = "@@(#)$Id: whatnowsbr.c,v 1.14 1992/01/31 22:29:48 jromine Exp jromine $";
1334 d535 6
1335 a540 1
1336     "split seconds", 0,
1337 @
1338
1339
1340 1.14
1341 log
1342 @kerberos
1343 @
1344 text
1345 @d3 1
1346 a3 1
1347 static char ident[] = "@@(#)$Id: whatnowsbr.c,v 1.13 1992/01/31 16:35:44 jromine Exp jromine $";
1348 d735 6
1349 a740 2
1350         vec[vecp++] = "-alias";
1351         vec[vecp++] = getcpy(cp);
1352 @
1353
1354
1355 1.13
1356 log
1357 @Multimedia MH
1358 @
1359 text
1360 @d3 1
1361 a3 1
1362 static char ident[] = "@@(#)$Id: whatnowsbr.c,v 1.12 1992/01/30 22:39:58 jromine Exp $";
1363 d34 1
1364 a34 1
1365     NULL, NULL
1366 d57 1
1367 a57 1
1368     NULL, NULL
1369 d154 1
1370 a154 1
1371     if (drft == NULL && (drft = getenv ("mhdraft")) == NULL || *drft == NULL)
1372 d157 1
1373 a157 1
1374     if (ed == NULL && ((ed = getenv ("mheditor")) == NULL || *ed == NULL))
1375 d581 1
1376 a581 1
1377     NULL, NULL
1378 d750 1
1379 a750 1
1380     if ((cp = getenv ("SIGNATURE")) == NULL || *cp == NULL)
1381 d760 1
1382 a760 1
1383                         *cp = NULL;
1384 d766 1
1385 a766 1
1386     if ((annotext = getenv ("mhannotate")) == NULL || *annotext == NULL)
1387 d768 1
1388 a768 1
1389     if ((altmsg = getenv ("mhaltmsg")) == NULL || *altmsg == NULL)
1390 d770 1
1391 a770 1
1392     if (annotext && ((cp = getenv ("mhinplace")) != NULL && *cp != NULL))
1393 @
1394
1395
1396 1.12
1397 log
1398 @remove WP
1399 @
1400 text
1401 @d3 1
1402 a3 1
1403 static char ident[] = "@@(#)$Id: whatnowsbr.c,v 1.11 1992/01/29 16:55:19 jromine Exp jromine $";
1404 d534 4
1405 a537 1
1406 #define UNIQSW  14
1407 d539 1
1408 a539 1
1409 #define NUNIQSW 15
1410 d542 1
1411 a542 1
1412 #define VERBSW  16
1413 d544 1
1414 a544 1
1415 #define NVERBSW 17
1416 d547 1
1417 a547 1
1418 #define WATCSW  18
1419 d549 1
1420 a549 1
1421 #define NWATCSW 19
1422 d552 1
1423 a552 1
1424 #define WIDTHSW 20
1425 d555 1
1426 a555 1
1427 #define SHELPSW 21
1428 d558 1
1429 a558 1
1430 #define MAILSW  22
1431 d560 1
1432 a560 1
1433 #define SAMLSW  23
1434 d562 1
1435 a562 1
1436 #define SSNDSW  24
1437 d564 1
1438 a564 1
1439 #define SOMLSW  25
1440 d567 1
1441 a567 1
1442 #define CLIESW  26
1443 d569 1
1444 a569 1
1445 #define SERVSW  27
1446 d571 1
1447 a571 1
1448 #define SNOOPSW 28
1449 d574 1
1450 a574 1
1451 #define SDRFSW 29
1452 d576 1
1453 a576 1
1454 #define SDRMSW 30
1455 d578 1
1456 a578 1
1457 #define SNDRFSW 31
1458 d590 1
1459 d592 1
1460 d661 7
1461 d681 9
1462 a696 2
1463                 case VERBSW: 
1464                 case NVERBSW: 
1465 @
1466
1467
1468 1.11
1469 log
1470 @SUNVIBUG -> ATTVIBUG
1471 @
1472 text
1473 @d3 1
1474 a3 1
1475 static char ident[] = "@@(#)$Id: whatnowsbr.c,v 1.10 1991/01/23 15:43:31 mh Exp jromine $";
1476 a788 5
1477 #ifdef  WP
1478     char   *cp,
1479             draft[BUFSIZ],
1480             backup[BUFSIZ];
1481 #endif
1482 a789 4
1483 #ifdef  WP
1484     (void) strcpy (draft, m_scratch (file, invo_name));
1485 #endif
1486
1487 a804 4
1488 #ifdef  WP
1489             vec[vecp++] = "-fill-in";
1490             vec[vecp++] = draft;
1491 #endif
1492 a812 1
1493 #ifndef WP
1494 a813 5
1495 #else
1496             if (pidwait (pid, NOTOK)) {
1497                 (void) unlink (draft);
1498                 return 1;
1499             }
1500 a814 1
1501 #endif
1502 a815 14
1503
1504 #ifdef  WP
1505     if (rename (file, cp = m_backup (file)) == NOTOK) {
1506         advise (cp, "unable to rename %s to", file);
1507         (void) unlink (draft);
1508         return 1;
1509     }
1510     if (rename (draft, file) == NOTOK) {
1511         advise (file, "unable to rename %s to ", draft);
1512         return 1;
1513     }
1514
1515     return 0;
1516 #endif
1517 @
1518
1519
1520 1.10
1521 log
1522 @fixup SUNVIBUG
1523 @
1524 text
1525 @d3 1
1526 a3 1
1527 static char ident[] = "@@(#)$Id: whatnowsbr.c,v 1.9 91/01/23 14:44:00 mh Exp Locker: mh $";
1528 d338 1
1529 a338 1
1530 #ifdef  SUNVIBUG
1531 d357 1
1532 a357 1
1533 #ifdef  SUNVIBUG
1534 @
1535
1536
1537 1.9
1538 log
1539 @add SUNVIBUG
1540 @
1541 text
1542 @d3 1
1543 a3 1
1544 static char ident[] = "@@(#)$Id: whatnowsbr.c,v 1.8 90/12/27 16:07:11 mh Exp Locker: mh $";
1545 a307 4
1546 #ifdef  SUNVIBUG
1547     if (cp = r1bindex (*ed, '/') && strcmp (cp, "vi") == 0)
1548         reedit++;
1549 #endif
1550 d338 7
1551 d355 1
1552 a355 1
1553                 status = -2;
1554 d357 3
1555 @
1556
1557
1558 1.8
1559 log
1560 @jlr
1561 @
1562 text
1563 @d3 1
1564 a3 1
1565 static char ident[] = "@@(#)$Id: whatnowsbr.c,v 1.7 90/12/18 14:01:05 mh Exp Locker: mh $";
1566 d308 4
1567 @
1568
1569
1570 1.7
1571 log
1572 @give name of failed draft
1573 jlr
1574 @
1575 text
1576 @d3 1
1577 a3 1
1578 static char ident[] = "@@(#)$Id: whatnowsbr.c,v 1.6 90/04/05 14:59:26 sources Exp Locker: mh $";
1579 d342 2
1580 a343 2
1581                         advise (NULLCP, "problems with edit--%s left in %s",
1582                                 file, cp);
1583 @
1584
1585
1586 1.6
1587 log
1588 @add ID
1589 @
1590 text
1591 @d3 1
1592 a3 1
1593 static char ident[] = "@@(#)$Id:$";
1594 d341 3
1595 a343 2
1596                             (rename (file, m_backup (file)) != NOTOK)) {
1597                         advise (NULLCP, "problems with edit--%s deleted", file);
1598 @
1599
1600
1601 1.5
1602 log
1603 @add Aliasfile: stuff for built-in "send"
1604 @
1605 text
1606 @d2 3
1607 @
1608
1609
1610 1.4
1611 log
1612 @ANSI Compilance
1613 @
1614 text
1615 @d701 4
1616 @
1617
1618
1619 1.3
1620 log
1621 @WP Changes
1622 @
1623 text
1624 @d9 1
1625 d251 3
1626 d286 3
1627 d290 3
1628 @
1629
1630
1631 1.2
1632 log
1633 @when edit fails, delete draft by renaming to m_backup(draft)
1634 @
1635 text
1636 @d761 5
1637 d767 4
1638 d786 4
1639 d798 1
1640 d800 7
1641 d808 14
1642 @
1643
1644
1645 1.1
1646 log
1647 @Initial revision
1648 @
1649 text
1650 @d327 2
1651 a328 2
1652                     if (!use && (status & 0xff00)) {
1653                         (void) unlink (file);
1654 @