9 date 95.12.06.21.04.47; author jromine; state Exp;
14 date 95.12.06.19.20.22; author jromine; state Exp;
19 date 94.04.21.19.23.38; author jromine; state Exp;
24 date 92.12.15.00.20.22; author jromine; state Exp;
29 date 92.12.11.22.16.54; author jromine; state Exp;
34 date 92.12.02.18.51.07; author jromine; state Exp;
39 date 92.11.04.02.28.36; author jromine; state Exp;
44 date 92.10.16.21.37.53; author jromine; state Exp;
49 date 92.10.16.16.52.13; author jromine; state Exp;
54 date 92.02.10.17.33.44; author jromine; state Exp;
59 date 92.01.31.22.29.48; author jromine; state Exp;
64 date 92.01.31.16.35.44; author jromine; state Exp;
69 date 92.01.30.22.39.58; author jromine; state Exp;
74 date 92.01.29.16.55.19; author jromine; state Exp;
79 date 91.01.23.15.43.31; author mh; state Exp;
84 date 91.01.23.14.44.00; author mh; state Exp;
89 date 90.12.27.16.07.11; author mh; state Exp;
94 date 90.12.18.14.01.05; author mh; state Exp;
99 date 90.04.05.14.59.26; author sources; state Exp;
104 date 90.03.22.23.17.17; author sources; state Exp;
109 date 90.02.06.13.38.03; author sources; state Exp;
114 date 90.02.05.15.31.31; author sources; state Exp;
119 date 90.01.29.16.28.13; author sources; state Exp;
124 date 90.01.29.16.27.52; author sources; state Exp;
135 @add hidden -queued (for post?)
138 @/* whatnowsbr.c - the WhatNow shell */
140 static char ident[] = "@@(#)$Id: whatnowsbr.c,v 1.23 1995/12/06 19:20:22 jromine Exp jromine $";
146 #include <sys/types.h>
147 #include <sys/stat.h>
150 #define MIMEminc(a) (a)
152 #define MIMEminc(a) 0
155 static int editfile(), copyf(), sendfile(), sendit(), whomfile();
157 static int mhnfile();
161 static struct swit whatnowswitches[] = {
163 "draftfolder +folder", 0,
165 "draftmessage msg", 0,
185 static struct swit aleqs[] = {
187 "display [<switches>]", 0,
189 "edit [<editor> <switches>]", 0,
191 "list [<switches>]", 0,
193 "push [<switches>]", 0,
197 "refile [<switches>] +folder", 0,
199 "send [<switches>]", 0,
201 "whom [<switches>]", 0,
208 static char *myprompt = "\nWhat now? ";
214 int WhatNow (argc, argv)
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);
241 (void) copyip (argv + 1, ap);
246 while (cp = *argp++) {
248 switch (smatch (++cp, whatnowswitches)) {
250 ambigsw (cp, whatnowswitches);
253 adios (NULLCP, "-%s unknown", cp);
255 (void) sprintf (buf, "%s [switches] [file]", invo_name);
256 help (buf, whatnowswitches);
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);
269 adios (NULLCP, "only one draft message at a time!");
270 if (!(dmsg = *argp++) || *dmsg == '-')
271 adios (NULLCP, "missing argument to %s", argp[-2]);
279 if (!(ed = *argp++) || *ed == '-')
280 adios (NULLCP, "missing argument to %s", argp[-2]);
288 if (!(myprompt = *argp++) || *myprompt == '-')
289 adios (NULLCP, "missing argument to %s", argp[-2]);
293 adios (NULLCP, "only one draft at a time!");
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))
305 if ((cp = getenv ("mhuse")) && *cp)
308 && editfile (&ed, NULLVP, drft, use, NULLMP, msgnam, NULLCP) < 0)
313 (void) sprintf (prompt, myprompt, invo_name);
315 if (!(argp = getans (prompt, aleqs))) {
316 (void) unlink (LINK);
319 switch (smatch (*argp, aleqs)) {
322 (void) showfile (++argp, msgnam);
324 advise (NULLCP, "no alternate message to display");
330 if (editfile (&ed, argp, drft, NOUSE, NULLMP, msgnam, NULLCP)
336 (void) showfile (++argp, drft);
340 (void) whomfile (++argp, drft);
344 if (*++argp && (*argp[0] == 'd' ||
345 ((*argp)[0] == '-' && (*argp)[1] == 'd'))) {
346 if (unlink (drft) == NOTOK)
347 adios (drft, "unable to unlink");
350 if (stat (drft, &st) != NOTOK)
351 advise (NULLCP, "draft left on %s", drft);
355 if (sendfile (++argp, drft, 1))
360 (void) sendfile (++argp, drft, 0);
364 if (refile (++argp, drft) == 0)
369 advise (NULLCP, "say what?");
378 static int reedit = 0;
379 static char *edsave = NULL;
384 static int editfile (ed, arg, file, use, mp, altmsg, cwd)
385 register struct msgs *mp;
397 char altpath[BUFSIZ],
403 int oumask; /* PJS: for setting permissions on symlinks. */
408 if (!reedit) { /* set initial editor */
409 if (*ed == NULL && (*ed = m_find ("editor")) == NULL)
413 if (!*ed) { /* no explicit editor */
415 if ((cp = r1bindex (*ed, '/')) == NULL)
417 cp = concat (cp, "-next", NULLCP);
418 if ((cp = m_find (cp)) != NULL)
423 if (mp == NULL || *altmsg == '/' || cwd == NULL)
424 (void) strcpy (altpath, altmsg);
426 (void) sprintf (altpath, "%s/%s", mp -> foldpath, altmsg);
428 (void) strcpy (linkpath, LINK);
430 (void) sprintf (linkpath, "%s/%s", cwd, LINK);
434 (void) unlink (linkpath);
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' */
440 (void) symlink (altpath, linkpath);
442 umask(oumask); /* PJS: else symlinks are world 'r' */
448 #else /* not BSD42 */
449 (void) link (altpath, linkpath);
450 #endif /* not BSD42 */
454 (void) fflush (stdout);
456 switch (pid = vfork ()) {
458 advise ("fork", "unable to");
467 (void) m_putenv ("mhfolder", mp -> foldpath);
468 (void) m_putenv ("editalt", altpath);
472 vec[vecp++] = r1bindex (*ed, '/');
475 vec[vecp++] = *arg++;
480 fprintf (stderr, "unable to exec ");
485 if (status = pidwait (pid, NOTOK)) {
487 if ((cp = r1bindex (*ed, '/'))
488 && strcmp (cp, "vi") == 0
489 && (status & 0x00ff) == 0)
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",
501 advise (NULLCP, "problems with edit--%s preserved",
503 status = -2; /* maybe "reedit ? -2 : -1"? */
514 && (!mp -> msgflags & READONLY)
516 ? lstat (linkpath, &st) != NOTOK
517 && (st.st_mode & S_IFMT) == S_IFREG
518 && copyf (linkpath, altpath) == NOTOK
519 : stat (linkpath, &st) != NOTOK
521 && (unlink (altpath) == NOTOK
522 || link (linkpath, altpath) == NOTOK)))
523 advise (linkpath, "unable to update %s from", altmsg);
524 #else /* not BSD42 */
527 && (!mp -> msgflags & READONLY)
528 && stat (linkpath, &st) != NOTOK
530 && (unlink (altpath) == NOTOK
531 || link (linkpath, altpath) == NOTOK))
532 advise (linkpath, "unable to update %s from", altmsg);
533 #endif /* not BSD42 */
536 edsave = getcpy (*ed);
539 (void) unlink (linkpath);
547 static int copyf (ifile, ofile)
548 register char *ifile,
556 if ((in = open (ifile, 0)) == NOTOK)
558 if ((out = open (ofile, 1)) == NOTOK || ftruncate (out, 0) == NOTOK) {
560 admonish (ofile, "unable to truncate");
567 while ((i = read (in, buffer, sizeof buffer)) > OK)
568 if (write (out, buffer, i) != i) {
569 advise (ofile, "may have damaged");
583 static sendfile (arg, file, pushsw)
588 register int child_id,
596 if ((cp = m_find ("automhnproc"))
597 && !getenv ("NOMHNPROC")
599 && (i = editfile (&cp, NULLVP, file, NOUSE, NULLMP, NULLCP,
604 if (strcmp (sp = r1bindex (sendproc, '/'), "send") == 0) {
606 sendit (invo_name = sp, arg, file, pushsw);
612 (void) fflush (stdout);
614 for (i = 0; (child_id = vfork ()) == NOTOK && i < 5; i++)
618 advise (NULLCP, "unable to fork, so sending directly...");
621 vec[vecp++] = invo_name;
623 vec[vecp++] = "-push";
626 vec[vecp++] = *arg++;
630 execvp (sendproc, vec);
631 fprintf (stderr, "unable to exec ");
636 if (pidwait (child_id, OK) == 0)
645 #include "../h/mhn.h"
648 static int mhnfile (msgnam)
656 if ((fp = fopen (msgnam, "r")) == NULL)
659 switch (state = m_getfld (state, name, buf, sizeof buf, fp)) {
663 if (uleq (name, VRSN_FIELD) || uprf (name, XXX_FIELD_PRF)) {
667 while (state == FLDPLUS)
668 state = m_getfld (state, name, buf, sizeof buf, fp);
675 for (bp = buf; *bp; bp++)
676 if (*bp != ' ' && *bp != '\t' && *bp != '\n') {
681 state = m_getfld (state, name, buf, sizeof buf, fp);
682 } while (state == BODY);
694 static struct swit sendswitches[] = {
696 "alias aliasfile", 0,
717 "filter filterfile", 0,
732 "mime", MIMEminc(-4),
734 "nomime", MIMEminc(-6),
747 "split seconds", MIMEminc(-5),
787 "draftfolder +folder", -6,
789 "draftmessage msg", -6,
797 "record program", -6,
806 extern int debugsw; /* from sendsbr.c */
814 extern char *altmsg; /* .. */
815 extern char *annotext;
816 extern char *distfile;
820 static sendit (sp, arg, file, pushed)
828 #endif /* not lint */
842 (void) copyip (arg, vec);
843 if ((cp = m_find (sp)) != NULL) {
844 ap = brkstring (cp = getcpy (cp), " ", "\n");
845 ap = copyip (ap, arguments);
850 (void) copyip (vec, ap);
853 debugsw = 0, forwsw = 1, inplace = 0, unique = 0;
854 altmsg = annotext = distfile = NULL;
855 vec[vecp++] = "-library";
856 vec[vecp++] = getcpy (m_maildir (""));
860 while (cp = *argp++) {
862 switch (smatch (++cp, sendswitches)) {
864 ambigsw (cp, sendswitches);
867 advise (NULLCP, "-%s unknown\n", cp);
870 (void) sprintf (buf, "%s [switches]", sp);
871 help (buf, sendswitches);
882 if (!(cp = *argp++) || sscanf (cp, "%d", &splitsw) != 1) {
883 advise (NULLCP, "missing argument to %s", argp[-2]);
911 debugsw++; /* fall */
940 if (!(cp = *argp++) || *cp == '-') {
941 advise (NULLCP, "missing argument to %s", argp[-2]);
949 if (!(cp = *argp++) || *cp == '-') {
950 advise (NULLCP, "missing argument to %s", argp[-2]);
956 advise (NULLCP, "usage: %s [switches]", sp);
959 if (cp = m_find ("Aliasfile")) { /* allow Aliasfile: profile entry */
962 for (ap = brkstring(dp = getcpy(cp), " ", "\n"); ap && *ap; ap++) {
963 vec[vecp++] = "-alias";
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));
979 if ((cp = getenv ("SIGNATURE")) == NULL || *cp == 0)
980 if ((cp = m_find ("signature")) && *cp)
981 (void) m_putenv ("SIGNATURE", cp);
984 (void) sprintf (buf, "%s/.signature", mypath);
985 if ((fp = fopen (buf, "r")) != NULL
986 && fgets (buf, sizeof buf, fp) != NULL) {
988 if (cp = index (buf, '\n'))
990 (void) m_putenv ("SIGNATURE", buf);
995 if ((annotext = getenv ("mhannotate")) == NULL || *annotext == 0)
997 if ((altmsg = getenv ("mhaltmsg")) == NULL || *altmsg == 0)
999 if (annotext && ((cp = getenv ("mhinplace")) != NULL && *cp != 0))
1000 inplace = atoi (cp);
1002 if ((cp = getenv ("mhdist"))
1005 && (distsw = atoi (cp))
1006 #endif /* not lint */
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);
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)
1021 vec[0] = r1bindex (postproc, '/');
1024 if (sendsbr (vec, vecp, file, &st) == OK)
1030 static int whomfile (arg, file)
1031 register char **arg,
1039 (void) fflush (stdout);
1041 switch (pid = vfork ()) {
1043 advise ("fork", "unable to");
1048 vec[vecp++] = r1bindex (whomproc, '/');
1052 vec[vecp++] = *arg++;
1055 execvp (whomproc, vec);
1056 fprintf (stderr, "unable to exec ");
1058 _exit (-1); /* NOTREACHED */
1061 return (pidwait (pid, NOTOK) & 0377 ? 1 : 0);
1074 static char ident[] = "@@(#)$Id: whatnowsbr.c,v 1.22 1994/04/21 19:23:38 jromine Exp jromine $";
1092 static char ident[] = "@@(#)$Id: whatnowsbr.c,v 1.21 1992/12/15 00:20:22 jromine Exp jromine $";
1106 static char ident[] = "@@(#)$Id: whatnowsbr.c,v 1.20 1992/12/11 22:16:54 jromine Exp jromine $";
1109 if (uprf (name, XXX_FIELD_PRF)) {
1120 static char ident[] = "@@(#)$Id: whatnowsbr.c,v 1.19 1992/12/02 18:51:07 jromine Exp jromine $";
1177 static char ident[] = "@@(#)$Id: whatnowsbr.c,v 1.18 1992/11/04 02:28:36 jromine Exp jromine $";
1191 static char ident[] = "@@(#)$Id: whatnowsbr.c,v 1.17 1992/10/16 21:37:53 jromine Exp jromine $";
1203 static char ident[] = "@@(#)$Id: whatnowsbr.c,v 1.16 1992/10/16 16:52:13 jromine Exp jromine $";
1206 (void) putenv ("mhfolder", mp -> foldpath);
1207 (void) putenv ("editalt", altpath);
1210 (void) putenv ("KDS", cp);
1213 (void) putenv ("TMADB", m_maildir (cp));
1216 (void) putenv ("SIGNATURE", cp);
1219 (void) putenv ("SIGNATURE", buf);
1230 static char ident[] = "@@(#)$Id: whatnowsbr.c,v 1.15 1992/02/10 17:33:44 jromine Exp jromine $";
1234 sendfile (++argp, drft, 1);
1238 sendfile (++argp, drft, 0);
1328 @allow "Aliasfile" to be multiple files
1333 static char ident[] = "@@(#)$Id: whatnowsbr.c,v 1.14 1992/01/31 22:29:48 jromine Exp jromine $";
1347 static char ident[] = "@@(#)$Id: whatnowsbr.c,v 1.13 1992/01/31 16:35:44 jromine Exp jromine $";
1350 vec[vecp++] = "-alias";
1351 vec[vecp++] = getcpy(cp);
1362 static char ident[] = "@@(#)$Id: whatnowsbr.c,v 1.12 1992/01/30 22:39:58 jromine Exp $";
1371 if (drft == NULL && (drft = getenv ("mhdraft")) == NULL || *drft == NULL)
1374 if (ed == NULL && ((ed = getenv ("mheditor")) == NULL || *ed == NULL))
1380 if ((cp = getenv ("SIGNATURE")) == NULL || *cp == NULL)
1386 if ((annotext = getenv ("mhannotate")) == NULL || *annotext == NULL)
1389 if ((altmsg = getenv ("mhaltmsg")) == NULL || *altmsg == NULL)
1392 if (annotext && ((cp = getenv ("mhinplace")) != NULL && *cp != NULL))
1403 static char ident[] = "@@(#)$Id: whatnowsbr.c,v 1.11 1992/01/29 16:55:19 jromine Exp jromine $";
1470 @SUNVIBUG -> ATTVIBUG
1475 static char ident[] = "@@(#)$Id: whatnowsbr.c,v 1.10 1991/01/23 15:43:31 mh Exp jromine $";
1484 (void) strcpy (draft, m_scratch (file, invo_name));
1489 vec[vecp++] = "-fill-in";
1490 vec[vecp++] = draft;
1496 if (pidwait (pid, NOTOK)) {
1497 (void) unlink (draft);
1505 if (rename (file, cp = m_backup (file)) == NOTOK) {
1506 advise (cp, "unable to rename %s to", file);
1507 (void) unlink (draft);
1510 if (rename (draft, file) == NOTOK) {
1511 advise (file, "unable to rename %s to ", draft);
1527 static char ident[] = "@@(#)$Id: whatnowsbr.c,v 1.9 91/01/23 14:44:00 mh Exp Locker: mh $";
1544 static char ident[] = "@@(#)$Id: whatnowsbr.c,v 1.8 90/12/27 16:07:11 mh Exp Locker: mh $";
1547 if (cp = r1bindex (*ed, '/') && strcmp (cp, "vi") == 0)
1565 static char ident[] = "@@(#)$Id: whatnowsbr.c,v 1.7 90/12/18 14:01:05 mh Exp Locker: mh $";
1572 @give name of failed draft
1578 static char ident[] = "@@(#)$Id: whatnowsbr.c,v 1.6 90/04/05 14:59:26 sources Exp Locker: mh $";
1581 advise (NULLCP, "problems with edit--%s left in %s",
1593 static char ident[] = "@@(#)$Id:$";
1596 (rename (file, m_backup (file)) != NOTOK)) {
1597 advise (NULLCP, "problems with edit--%s deleted", file);
1603 @add Aliasfile: stuff for built-in "send"
1633 @when edit fails, delete draft by renaming to m_backup(draft)
1652 if (!use && (status & 0xff00)) {
1653 (void) unlink (file);