874a787417f0667bfcda79962198cc3757a083ff
[mmh] / uip / whatnow.c
1 /*
2 ** whatnow.c -- the WhatNow shell
3 **
4 ** This code is Copyright (c) 2002, by the authors of nmh.  See the
5 ** COPYRIGHT file in the root directory of the nmh distribution for
6 ** complete copyright information.
7 **
8 **  The inclusion of attachments is eased by
9 **  using the header field name mechanism added to anno and send.
10 **  The header field name for attachments is predefined.
11 **
12 **  Several commands have been added at the whatnow prompt:
13 **
14 **        cd [ directory ]        This option works just like the shell's
15 **                                cd command and lets the user change the
16 **                                directory from which attachments are
17 **                                taken so that long path names are not
18 **                                needed with every file.
19 **
20 **        ls [ ls-options ]       This option works just like the normal
21 **                                ls command and exists to allow the user
22 **                                to verify file names in the directory.
23 **
24 **        pwd                     This option works just like the normal
25 **                                pwd command and exists to allow the user
26 **                                to verify the directory.
27 **
28 **        attach files            This option attaches the named files to
29 **                                the draft.
30 **
31 **        alist [-ln]             This option lists the attachments on the
32 **                                draft.  -l gets long listings, -n gets
33 **                                numbered listings.
34 **
35 **        detach files            This option removes attachments from the
36 **        detach -n numbers       draft.  This can be done by file name or
37 **                                by attachment number.
38 */
39
40 #include <h/mh.h>
41 #include <fcntl.h>
42 #include <signal.h>
43 #include <h/mime.h>
44 #include <h/utils.h>
45
46 static struct swit whatnowswitches[] = {
47 #define EDITRSW  0
48         { "editor editor", 0 },
49 #define NEDITSW  1
50         { "noedit", 0 },
51 #define PRMPTSW  2
52         { "prompt string", 4 },
53 #define VERSIONSW  3
54         { "version", 0 },
55 #define HELPSW  4
56         { "help", 0 },
57         { NULL, 0 }
58 };
59
60 /*
61 ** Options at the "whatnow" prompt
62 */
63 static struct swit aleqs[] = {
64 #define EDITSW  0
65         { "edit [<editor> <switches>]", 0 },
66 #define REFILEOPT  1
67         { "refile [<switches>] +folder", 0 },
68 #define DISPSW  2
69         { "display", 0 },
70 #define LISTSW  3
71         { "list", 0 },
72 #define SENDSW  4
73         { "send [<switches>]", 0 },
74 #define PUSHSW  5
75         { "push [<switches>]", 0 },
76 #define QUITSW  6
77         { "quit", 0 },
78 #define DELETESW  7
79         { "delete", 0 },
80 #define CDCMDSW  8
81         { "cd [directory]", 0 },
82 #define PWDCMDSW  9
83         { "pwd", 0 },
84 #define LSCMDSW  10
85         { "ls", 0 },
86 #define ATTACHCMDSW  11
87         { "attach", 0 },
88 #define DETACHCMDSW  12
89         { "detach [-n]", 2 },
90 #define ALISTCMDSW  13
91         { "alist [-ln] ", 2 },
92         { NULL, 0 }
93 };
94
95 static char *myprompt = "\nWhat now? ";
96
97 /*
98 ** static prototypes
99 */
100 static int editfile(char **, char **, char *, int, struct msgs *,
101         char *, char *, int);
102 static int sendfile(char **, char *, int);
103 static int removefile(char *);
104 static void writelscmd(char *, int, char **);
105 static void writesomecmd(char *buf, int bufsz, char *cmd, char *trailcmd, char **argp);
106 static FILE* popen_in_dir(const char *dir, const char *cmd, const char *type);
107 static int system_in_dir(const char *dir, const char *cmd);
108
109
110 #ifdef HAVE_LSTAT
111 static int copyf(char *, char *);
112 #endif
113
114
115 int
116 main(int argc, char **argv)
117 {
118         int nedit = 0, use = 0;
119         char *cp;
120         char *ed = NULL, *drft = NULL, *msgnam = NULL;
121         char buf[BUFSIZ], prompt[BUFSIZ];
122         char **argp, **arguments;
123         struct stat st;
124         char cwd[MAXPATHLEN + 1];  /* current working directory */
125         char file[MAXPATHLEN + 1];  /* file name buffer */
126         char shell[MAXPATHLEN + 1];  /* shell response buffer */
127         FILE *f;  /* read pointer for bgnd proc */
128         char *l;  /* set on -l to alist  command */
129         int n;  /* set on -n to alist command */
130
131 #ifdef LOCALE
132         setlocale(LC_ALL, "");
133 #endif
134
135         invo_name = mhbasename(argv[0]);
136
137         /* read user profile/context */
138         context_read();
139
140         arguments = getarguments(invo_name, argc, argv, 1);
141         argp = arguments;
142
143         /*
144         ** Get the initial current working directory.
145         */
146
147         if (!getcwd(cwd, sizeof (cwd))) {
148                 adios("getcwd", "could not get working directory");
149         }
150
151         while ((cp = *argp++)) {
152                 if (*cp == '-') {
153                         switch (smatch(++cp, whatnowswitches)) {
154                         case AMBIGSW:
155                                 ambigsw(cp, whatnowswitches);
156                                 done(1);
157                         case UNKWNSW:
158                                 adios(NULL, "-%s unknown", cp);
159
160                         case HELPSW:
161                                 snprintf(buf, sizeof(buf),
162                                                 "%s [switches] [file]",
163                                                 invo_name);
164                                 print_help(buf, whatnowswitches, 1);
165                                 done(1);
166                         case VERSIONSW:
167                                 print_version(invo_name);
168                                 done(1);
169
170                         case EDITRSW:
171                                 if (!(ed = *argp++) || *ed == '-')
172                                         adios(NULL, "missing argument to %s",
173                                                         argp[-2]);
174                                 nedit = 0;
175                                 continue;
176                         case NEDITSW:
177                                 nedit++;
178                                 continue;
179
180                         case PRMPTSW:
181                                 if (!(myprompt = *argp++) || *myprompt == '-')
182                                         adios(NULL, "missing argument to %s",
183                                                         argp[-2]);
184                                 continue;
185
186                         }
187                 }
188                 if (drft)
189                         adios(NULL, "only one draft at a time!");
190                 else
191                         drft = cp;
192         }
193
194         if ((!drft && !(drft = getenv("mhdraft"))) || !*drft)
195                 drft = getcpy(m_draft(seq_cur));
196
197         msgnam = (cp = getenv("mhaltmsg")) && *cp ? getcpy(cp) : NULL;
198
199         if ((cp = getenv("mhuse")) && *cp)
200                 use = atoi(cp);
201
202         if (!ed && (!(ed = getenv("mheditor")) || !*ed)) {
203                 ed = NULL;
204                 nedit++;
205         }
206
207         /* start editing the draft, unless -noedit was given */
208         if (!nedit && editfile(&ed, NULL, drft, use, NULL, msgnam, NULL, 1)
209                         < 0)
210                 done(1);
211
212         snprintf(prompt, sizeof(prompt), myprompt, invo_name);
213         for (;;) {
214                 if (!(argp = getans(prompt, aleqs))) {
215                         unlink(altmsglink);
216                         done(1);
217                 }
218                 switch (smatch(*argp, aleqs)) {
219                 case DISPSW:
220                         /* display the msg being replied to or distributed */
221                         if (msgnam) {
222                                 snprintf(buf, sizeof buf, "%s '%s'",
223                                                 listproc, msgnam);
224                                 system(buf);
225                         } else {
226                                 advise(NULL, "no alternate message to display");
227                         }
228                         break;
229
230                 case EDITSW:
231                         /* Call an editor on the draft file */
232                         if (*++argp)
233                                 ed = *argp++;
234                         if (editfile(&ed, argp, drft, NOUSE, NULL,
235                                         msgnam, NULL, 1) == NOTOK)
236                                 done(1);
237                         break;
238
239                 case LISTSW:
240                         /* display the draft file */
241                         snprintf(buf, sizeof buf, "%s '%s'", listproc, drft);
242                         system(buf);
243                         break;
244
245                 case QUITSW:
246                         /* quit */
247                         if (stat(drft, &st) != NOTOK) {
248                                 advise(NULL, "draft left on %s", drft);
249                         }
250                         done(1);
251
252                 case DELETESW:
253                         /* Delete draft and exit */
254                         removefile(drft);
255                         done(1);
256
257                 case PUSHSW:
258                         /* Send draft in background */
259                         if (sendfile(++argp, drft, 1))
260                                 done(1);
261                         break;
262
263                 case SENDSW:
264                         /* Send draft */
265                         sendfile(++argp, drft, 0);
266                         break;
267
268                 case REFILEOPT:
269                         /* Refile the draft */
270                         if (refile(++argp, drft) == 0)
271                                 done(0);
272                         break;
273
274                 case CDCMDSW:
275                         /*
276                         ** Change the working directory for attachments
277                         **
278                         ** Run the directory through the user's shell
279                         ** so that we can take advantage of any syntax
280                         ** that the user is accustomed to.  Read back
281                         ** the absolute path.
282                         */
283
284                         if (*(argp+1) == NULL) {
285                                 sprintf(buf, "$SHELL -c \"cd;pwd\"");
286                         } else {
287                                 writesomecmd(buf, BUFSIZ, "cd", "pwd", argp);
288                         }
289                         if ((f = popen_in_dir(cwd, buf, "r"))) {
290                                 fgets(cwd, sizeof (cwd), f);
291
292                                 if (strchr(cwd, '\n'))
293                                         *strchr(cwd, '\n') = '\0';
294
295                                 pclose(f);
296                         } else {
297                                 advise("popen", "could not get directory");
298                         }
299
300                         break;
301
302                 case PWDCMDSW:
303                         /* Print the working directory for attachments */
304                         printf("%s\n", cwd);
305                         break;
306
307                 case LSCMDSW:
308                         /*
309                         ** List files in the current attachment working
310                         ** directory
311                         **
312                         ** Use the user's shell so that we can take
313                         ** advantage of any syntax that the user is
314                         ** accustomed to.
315                         */
316                         writelscmd(buf, sizeof(buf), argp);
317                         system_in_dir(cwd, buf);
318                         break;
319
320                 case ALISTCMDSW:
321                         /*
322                         ** List attachments on current draft.  Options are:
323                         **
324                         ** -l    long listing (full path names)
325                         ** -n    numbers listing
326                         */
327
328                         l = NULL;
329                         n = 0;
330
331                         while (*++argp) {
332                                 if (strcmp(*argp, "-l") == 0)
333                                         l = "/";
334
335                                 else if (strcmp(*argp, "-n") == 0)
336                                         n = 1;
337
338                                 else if (strcmp(*argp, "-ln") == 0 ||
339                                                 strcmp(*argp, "-nl") == 0) {
340                                         l = "/";
341                                         n = 1;
342                                 } else {
343                                         n = -1;
344                                         break;
345                                 }
346                         }
347
348                         if (n == -1)
349                                 advise(NULL, "usage is alist [-ln].");
350
351                         else
352                                 annolist(drft, attach_hdr, l, n);
353
354                         break;
355
356                 case ATTACHCMDSW:
357                         /*
358                         ** Attach files to current draft.
359                         */
360
361                         if (*(argp+1) == NULL) {
362                                 advise(NULL, "attach command requires file argument(s).");
363                                 break;
364                         }
365
366                         /*
367                         ** Build a command line that causes the user's
368                         ** shell to list the file name arguments.
369                         ** This handles and wildcard expansion, tilde
370                         ** expansion, etc.
371                         */
372                         writelscmd(buf, sizeof(buf), argp);
373
374                         /*
375                         ** Read back the response from the shell,
376                         ** which contains a number of lines with one
377                         ** file name per line.  Remove off the newline.
378                         ** Determine whether we have an absolute or
379                         ** relative path name.  Prepend the current
380                         ** working directory to relative path names.
381                         ** Add the attachment annotation to the draft.
382                         */
383                         if ((f = popen_in_dir(cwd, buf, "r"))) {
384                                 while (fgets(shell, sizeof(shell), f)) {
385                                         *(strchr(shell, '\n')) = '\0';
386
387                                         if (*shell == '/')
388                                                 sprintf(file, "%s", shell);
389                                         else {
390                                                 sprintf(file, "%s/%s", cwd,
391                                                                 shell);
392                                         }
393                                         annotate(drft, attach_hdr, file, 0,
394                                                         -2, 1, 0);
395                                 }
396
397                                 pclose(f);
398                         } else {
399                                 advise("popen", "could not get file from shell");
400                         }
401
402                         break;
403
404                 case DETACHCMDSW:
405                         /*
406                         ** Detach files from current draft.
407                         **
408                         ** Scan the arguments for a -n.  Mixed file
409                         ** names and numbers aren't allowed, so this
410                         ** catches a -n anywhere in the argument list.
411                         */
412
413                         for (n = 0, arguments = argp + 1;
414                                         *arguments != NULL;
415                                         arguments++) {
416                                 if (strcmp(*arguments, "-n") == 0) {
417                                                 n = 1;
418                                                 break;
419                                 }
420                         }
421
422                         /*
423                         ** A -n was found so interpret the arguments as
424                         ** attachment numbers.  Decrement any remaining
425                         ** argument number that is greater than the one
426                         ** just processed after processing each one so
427                         ** that the numbering stays correct.
428                         */
429
430                         if (n == 1) {
431                                 for (arguments = argp + 1;
432                                                 *arguments != NULL;
433                                                 arguments++) {
434                                         if (strcmp(*arguments, "-n") == 0)
435                                                 continue;
436
437                                         if (**arguments != '\0') {
438                                                 n = atoi(*arguments);
439                                                 annotate(drft, attach_hdr,
440                                                                 NULL, 0,
441                                                                 n, 1, 0);
442
443                                                 for (argp = arguments + 1; *argp; argp++) {
444                                                         if (atoi(*argp) > n) {
445                                                                 if (atoi(*argp) == 1)
446                                                                         *argp = "";
447                                                                 else
448                                                                         sprintf(*argp, "%d", atoi(*argp) - 1);
449                                                         }
450                                                 }
451                                         }
452                                 }
453                         }
454
455                         /*
456                         ** The arguments are interpreted as file names.
457                         ** Run them through the user's shell for wildcard
458                         ** expansion and other goodies.  Do this from
459                         ** the current working directory if the argument
460                         ** is not an absolute path name (does not begin
461                         ** with a /).
462                         **
463                         ** We feed all the file names to the shell at
464                         ** once, otherwise you can't provide a file name
465                         ** with a space in it.
466                         */
467                         writelscmd(buf, sizeof(buf), argp);
468                         if ((f = popen_in_dir(cwd, buf, "r"))) {
469                                 while (fgets(shell, sizeof (shell), f)) {
470                                         *(strchr(shell, '\n')) = '\0';
471                                         annotate(drft, attach_hdr, shell,
472                                                         0, 0, 1, 0);
473                                 }
474                                 pclose(f);
475                         } else {
476                                 advise("popen", "could not get file from shell");
477                         }
478
479                         break;
480
481                 default:
482                         /* Unknown command */
483                         advise(NULL, "say what?");
484                         break;
485                 }
486         }
487         /*NOTREACHED*/
488 }
489
490
491
492 /*
493 ** Build a command line of the form $SHELL -c "cd 'cwd'; cmd argp ... ;
494 ** trailcmd".
495 */
496 static void
497 writesomecmd(char *buf, int bufsz, char *cmd, char *trailcmd, char **argp)
498 {
499         char *cp;
500         /*
501         ** Note that we do not quote -- the argp from the user
502         ** is assumed to be quoted as they desire. (We can't treat
503         ** it as pure literal as that would prevent them using ~,
504         ** wildcards, etc.) The buffer produced by this function
505         ** should be given to popen_in_dir() or system_in_dir() so
506         ** that the current working directory is set correctly.
507         */
508         int ln = snprintf(buf, bufsz, "$SHELL -c \"%s", cmd);
509         /*
510         ** NB that some snprintf() return -1 on overflow rather than the
511         ** new C99 mandated 'number of chars that would have been written'
512         */
513         /*
514         ** length checks here and inside the loop allow for the
515         ** trailing ';', trailcmd, '"' and NUL
516         */
517         int trailln = strlen(trailcmd) + 3;
518         if (ln < 0 || ln + trailln > bufsz)
519                 adios(NULL, "arguments too long");
520
521         cp = buf + ln;
522
523         while (*++argp) {
524                 ln = strlen(*argp);
525                 /* +1 for leading space */
526                 if (ln + trailln + 1 > bufsz - (cp-buf))
527                         adios(NULL, "arguments too long");
528                 *cp++ = ' ';
529                 memcpy(cp, *argp, ln+1);
530                 cp += ln;
531         }
532         if (*trailcmd) {
533                 *cp++ = ';';
534                 strcpy(cp, trailcmd);
535                 cp += trailln - 3;
536         }
537         *cp++ = '"';
538         *cp = 0;
539 }
540
541 /*
542 ** Build a command line that causes the user's shell to list the file name
543 ** arguments.  This handles and wildcard expansion, tilde expansion, etc.
544 */
545 static void
546 writelscmd(char *buf, int bufsz, char **argp)
547 {
548         writesomecmd(buf, bufsz, "ls", "", argp);
549 }
550
551 /*
552 ** Like system(), but run the command in directory dir.
553 ** This assumes the program is single-threaded!
554 */
555 static int
556 system_in_dir(const char *dir, const char *cmd)
557 {
558         char olddir[BUFSIZ];
559         int r;
560         if (getcwd(olddir, sizeof(olddir)) == 0)
561                 adios("getcwd", "could not get working directory");
562         if (chdir(dir) != 0)
563                 adios("chdir", "could not change working directory");
564         r = system(cmd);
565         if (chdir(olddir) != 0)
566                 adios("chdir", "could not change working directory");
567         return r;
568 }
569
570 /* ditto for popen() */
571 static FILE*
572 popen_in_dir(const char *dir, const char *cmd, const char *type)
573 {
574         char olddir[BUFSIZ];
575         FILE *f;
576         if (getcwd(olddir, sizeof(olddir)) == 0)
577                 adios("getcwd", "could not get working directory");
578         if (chdir(dir) != 0)
579                 adios("chdir", "could not change working directory");
580         f = popen(cmd, type);
581         if (chdir(olddir) != 0)
582                 adios("chdir", "could not change working directory");
583         return f;
584 }
585
586
587 /*
588 ** EDIT
589 */
590
591 static int  reedit = 0;  /* have we been here before? */
592 static char *edsave = NULL;  /* the editor we used previously */
593
594
595 static int
596 editfile(char **ed, char **arg, char *file, int use, struct msgs *mp,
597         char *altmsg, char *cwd, int save_editor)
598 {
599         int pid, status, vecp;
600         char altpath[BUFSIZ], linkpath[BUFSIZ];
601         char *cp, *vec[MAXARGS];
602         struct stat st;
603
604 #ifdef HAVE_LSTAT
605         int slinked = 0;
606 #endif /* HAVE_LSTAT */
607
608         /* Was there a previous edit session? */
609         if (reedit) {
610                 if (!*ed) {  /* no explicit editor */
611                         *ed = edsave;  /* so use the previous one */
612                         if (!(cp = mhbasename(*ed)))
613                                 cp = *ed;
614
615                         /* unless we've specified it via "editor-next" */
616                         cp = concat(cp, "-next", NULL);
617                         if ((cp = context_find(cp)))
618                                 *ed = cp;
619                 }
620         } else if (!*ed) {
621                 /* set initial editor */
622                 *ed = defaulteditor;
623         }
624
625         if (altmsg) {
626                 if (!mp || *altmsg == '/' || !cwd)
627                         strncpy(altpath, altmsg, sizeof(altpath));
628                 else
629                         snprintf(altpath, sizeof(altpath), "%s/%s",
630                                         mp->foldpath, altmsg);
631                 if (!cwd)
632                         strncpy(linkpath, altmsglink, sizeof(linkpath));
633                 else
634                         snprintf(linkpath, sizeof(linkpath), "%s/%s",
635                                         cwd, altmsglink);
636         }
637
638         if (altmsg) {
639                 unlink(linkpath);
640 #ifdef HAVE_LSTAT
641                 if (link(altpath, linkpath) == NOTOK) {
642                         symlink(altpath, linkpath);
643                         slinked = 1;
644                 } else {
645                         slinked = 0;
646                 }
647 #else /* not HAVE_LSTAT */
648                 link(altpath, linkpath);
649 #endif /* not HAVE_LSTAT */
650         }
651
652         context_save();  /* save the context file */
653         fflush(stdout);
654
655         switch (pid = fork()) {
656         case NOTOK:
657                 advise("fork", "unable to");
658                 status = NOTOK;
659                 break;
660
661         case OK:
662                 if (cwd)
663                         chdir(cwd);
664                 if (altmsg) {
665                         if (mp)
666                                 m_putenv("mhfolder", mp->foldpath);
667                         m_putenv("editalt", altpath);
668                 }
669
670                 vecp = 0;
671                 vec[vecp++] = mhbasename(*ed);
672                 if (arg)
673                         while (*arg)
674                                 vec[vecp++] = *arg++;
675                 vec[vecp++] = file;
676                 vec[vecp] = NULL;
677
678                 execvp(*ed, vec);
679                 fprintf(stderr, "unable to exec ");
680                 perror(*ed);
681                 _exit(-1);
682
683         default:
684                 if ((status = pidwait(pid, NOTOK))) {
685                         if (((status & 0xff00) != 0xff00)
686                                 && (!reedit || (status & 0x00ff))) {
687                                 if (!use && (status & 0xff00) && (rename(file, cp = m_backup (file)) != NOTOK)) {
688                                         advise(NULL, "problems with edit--draft left in %s", cp);
689                                 } else {
690                                         advise(NULL, "problems with edit--%s preserved", file);
691                                 }
692                         }
693                         status = -2;  /* maybe "reedit ? -2 : -1"? */
694                         break;
695                 }
696
697                 reedit++;
698 #ifdef HAVE_LSTAT
699                 if (altmsg && mp && !is_readonly(mp) && (slinked ?
700                                 lstat (linkpath, &st) != NOTOK &&
701                                 S_ISREG(st.st_mode) &&
702                                 copyf(linkpath, altpath) == NOTOK :
703                                 stat(linkpath, &st) != NOTOK &&
704                                 st.st_nlink == 1 &&
705                                 (unlink(altpath) == NOTOK ||
706                                 link(linkpath, altpath) == NOTOK)))
707                         advise(linkpath, "unable to update %s from", altmsg);
708 #else /* HAVE_LSTAT */
709                 if (altmsg && mp && !is_readonly(mp) &&
710                                 stat(linkpath, &st) != NOTOK &&
711                                 st.st_nlink == 1 &&
712                                 (unlink(altpath) == NOTOK ||
713                                 link(linkpath, altpath) == NOTOK))
714                         advise(linkpath, "unable to update %s from", altmsg);
715 #endif /* HAVE_LSTAT */
716         }
717
718         /* normally, we remember which editor we used */
719         if (save_editor)
720                 edsave = getcpy(*ed);
721
722         *ed = NULL;
723         if (altmsg)
724                 unlink(linkpath);
725
726         return status;
727 }
728
729
730 #ifdef HAVE_LSTAT
731 static int
732 copyf(char *ifile, char *ofile)
733 {
734         int i, in, out;
735         char buffer[BUFSIZ];
736
737         if ((in = open(ifile, O_RDONLY)) == NOTOK)
738                 return NOTOK;
739         if ((out = open(ofile, O_WRONLY | O_TRUNC)) == NOTOK) {
740                 admonish(ofile, "unable to open and truncate");
741                 close(in);
742                 return NOTOK;
743         }
744
745         while ((i = read(in, buffer, sizeof(buffer))) > OK)
746                 if (write(out, buffer, i) != i) {
747                         advise(ofile, "may have damaged");
748                         i = NOTOK;
749                         break;
750                 }
751
752         close(in);
753         close(out);
754         return i;
755 }
756 #endif /* HAVE_LSTAT */
757
758
759 /*
760 ** SEND
761 */
762
763 static int
764 sendfile(char **arg, char *file, int pushsw)
765 {
766         pid_t child_id;
767         int vecp;
768         char *vec[MAXARGS];
769
770         context_save();  /* save the context file */
771         fflush(stdout);
772
773         switch (child_id = fork()) {
774         case NOTOK:
775                 advise(NULL, "unable to fork, so sending directly...");
776                 /* fall */
777         case OK:
778                 vecp = 0;
779                 vec[vecp++] = invo_name;
780                 if (pushsw)
781                         vec[vecp++] = "-push";
782                 if (arg)
783                         while (*arg)
784                                 vec[vecp++] = *arg++;
785                 vec[vecp++] = file;
786                 vec[vecp] = NULL;
787
788                 execvp("send", vec);
789                 fprintf(stderr, "unable to exec ");
790                 perror("send");
791                 _exit(-1);
792
793         default:
794                 if (pidwait(child_id, OK) == 0)
795                         done(0);
796                 return 1;
797         }
798 }
799
800
801 /*
802 ** Remove the draft file
803 */
804
805 static int
806 removefile(char *drft)
807 {
808         if (unlink(drft) == NOTOK)
809                 adios(drft, "unable to unlink");
810
811         return OK;
812 }