Annotations will always be done inplace from now on.
[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 [<switches>]", 0 },
70 #define LISTSW  3
71         { "list [<switches>]", 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)) == NULL) {
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 == NULL && (drft = getenv("mhdraft")) == NULL) || *drft == 0)
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 == NULL && ((ed = getenv("mheditor")) == NULL || *ed == 0)) {
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                                 showfile(++argp, msgnam);
223                         else
224                                 advise(NULL, "no alternate message to display");
225                         break;
226
227                 case EDITSW:
228                         /* Call an editor on the draft file */
229                         if (*++argp)
230                                 ed = *argp++;
231                         if (editfile(&ed, argp, drft, NOUSE, NULL,
232                                         msgnam, NULL, 1) == NOTOK)
233                                 done(1);
234                         break;
235
236                 case LISTSW:
237                         /* display the draft file */
238                         showfile(++argp, drft);
239                         break;
240
241                 case QUITSW:
242                         /* quit */
243                         if (stat(drft, &st) != NOTOK) {
244                                 advise(NULL, "draft left on %s", drft);
245                         }
246                         done(1);
247
248                 case DELETESW:
249                         /* Delete draft and exit */
250                         removefile(drft);
251                         done(1);
252
253                 case PUSHSW:
254                         /* Send draft in background */
255                         if (sendfile(++argp, drft, 1))
256                                 done(1);
257                         break;
258
259                 case SENDSW:
260                         /* Send draft */
261                         sendfile(++argp, drft, 0);
262                         break;
263
264                 case REFILEOPT:
265                         /* Refile the draft */
266                         if (refile(++argp, drft) == 0)
267                                 done(0);
268                         break;
269
270                 case CDCMDSW:
271                         /*
272                         ** Change the working directory for attachments
273                         **
274                         ** Run the directory through the user's shell
275                         ** so that we can take advantage of any syntax
276                         ** that the user is accustomed to.  Read back
277                         ** the absolute path.
278                         */
279
280                         if (*(argp+1) == NULL) {
281                                 sprintf(buf, "$SHELL -c \"cd;pwd\"");
282                         } else {
283                                 writesomecmd(buf, BUFSIZ, "cd", "pwd", argp);
284                         }
285                         if ((f = popen_in_dir(cwd, buf, "r")) != (FILE *)0) {
286                                 fgets(cwd, sizeof (cwd), f);
287
288                                 if (strchr(cwd, '\n') != NULL)
289                                                 *strchr(cwd, '\n') = '\0';
290
291                                 pclose(f);
292                         } else {
293                                 advise("popen", "could not get directory");
294                         }
295
296                         break;
297
298                 case PWDCMDSW:
299                         /* Print the working directory for attachments */
300                         printf("%s\n", cwd);
301                         break;
302
303                 case LSCMDSW:
304                         /*
305                         ** List files in the current attachment working
306                         ** directory
307                         **
308                         ** Use the user's shell so that we can take
309                         ** advantage of any syntax that the user is
310                         ** accustomed to.
311                         */
312                         writelscmd(buf, sizeof(buf), argp);
313                         system_in_dir(cwd, buf);
314                         break;
315
316                 case ALISTCMDSW:
317                         /*
318                         ** List attachments on current draft.  Options are:
319                         **
320                         ** -l    long listing (full path names)
321                         ** -n    numbers listing
322                         */
323
324                         l = NULL;
325                         n = 0;
326
327                         while (*++argp != NULL) {
328                                 if (strcmp(*argp, "-l") == 0)
329                                         l = "/";
330
331                                 else if (strcmp(*argp, "-n") == 0)
332                                         n = 1;
333
334                                 else if (strcmp(*argp, "-ln") == 0 ||
335                                                 strcmp(*argp, "-nl") == 0) {
336                                         l = "/";
337                                         n = 1;
338                                 } else {
339                                         n = -1;
340                                         break;
341                                 }
342                         }
343
344                         if (n == -1)
345                                 advise(NULL, "usage is alist [-ln].");
346
347                         else
348                                 annolist(drft, attach_hdr, l, n);
349
350                         break;
351
352                 case ATTACHCMDSW:
353                         /*
354                         ** Attach files to current draft.
355                         */
356
357                         if (*(argp+1) == NULL) {
358                                 advise(NULL, "attach command requires file argument(s).");
359                                 break;
360                         }
361
362                         /*
363                         ** Build a command line that causes the user's
364                         ** shell to list the file name arguments.
365                         ** This handles and wildcard expansion, tilde
366                         ** expansion, etc.
367                         */
368                         writelscmd(buf, sizeof(buf), argp);
369
370                         /*
371                         ** Read back the response from the shell,
372                         ** which contains a number of lines with one
373                         ** file name per line.  Remove off the newline.
374                         ** Determine whether we have an absolute or
375                         ** relative path name.  Prepend the current
376                         ** working directory to relative path names.
377                         ** Add the attachment annotation to the draft.
378                         */
379                         if ((f = popen_in_dir(cwd, buf, "r")) != (FILE *)0) {
380                                 while (fgets(shell, sizeof (shell), f)
381                                                 != NULL) {
382                                         *(strchr(shell, '\n')) = '\0';
383
384                                         if (*shell == '/')
385                                                 annotate(drft, attach_hdr,
386                                                                 shell, 0,
387                                                                 -2, 1);
388                                         else {
389                                                 sprintf(file, "%s/%s", cwd,
390                                                                 shell);
391                                                 annotate(drft, attach_hdr,
392                                                                 file, 0,
393                                                                 -2, 1);
394                                         }
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);
442
443                                                 for (argp = arguments + 1; *argp != NULL; 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")) != (FILE *)0) {
469                                 while (fgets(shell, sizeof (shell), f)
470                                                 != NULL) {
471                                         *(strchr(shell, '\n')) = '\0';
472                                         annotate(drft, attach_hdr, shell,
473                                                         0, 0, 1);
474                                 }
475                                 pclose(f);
476                         } else {
477                                 advise("popen", "could not get file from shell");
478                         }
479
480                         break;
481
482                 default:
483                         /* Unknown command */
484                         advise(NULL, "say what?");
485                         break;
486                 }
487         }
488         /*NOTREACHED*/
489 }
490
491
492
493 /*
494 ** Build a command line of the form $SHELL -c "cd 'cwd'; cmd argp ... ;
495 ** trailcmd".
496 */
497 static void
498 writesomecmd(char *buf, int bufsz, char *cmd, char *trailcmd, char **argp)
499 {
500         char *cp;
501         /*
502         ** Note that we do not quote -- the argp from the user
503         ** is assumed to be quoted as they desire. (We can't treat
504         ** it as pure literal as that would prevent them using ~,
505         ** wildcards, etc.) The buffer produced by this function
506         ** should be given to popen_in_dir() or system_in_dir() so
507         ** that the current working directory is set correctly.
508         */
509         int ln = snprintf(buf, bufsz, "$SHELL -c \"%s", cmd);
510         /*
511         ** NB that some snprintf() return -1 on overflow rather than the
512         ** new C99 mandated 'number of chars that would have been written'
513         */
514         /*
515         ** length checks here and inside the loop allow for the
516         ** trailing ';', trailcmd, '"' and NUL
517         */
518         int trailln = strlen(trailcmd) + 3;
519         if (ln < 0 || ln + trailln > bufsz)
520                 adios(NULL, "arguments too long");
521
522         cp = buf + ln;
523
524         while (*++argp != NULL) {
525                 ln = strlen(*argp);
526                 /* +1 for leading space */
527                 if (ln + trailln + 1 > bufsz - (cp-buf))
528                         adios(NULL, "arguments too long");
529                 *cp++ = ' ';
530                 memcpy(cp, *argp, ln+1);
531                 cp += ln;
532         }
533         if (*trailcmd) {
534                 *cp++ = ';';
535                 strcpy(cp, trailcmd);
536                 cp += trailln - 3;
537         }
538         *cp++ = '"';
539         *cp = 0;
540 }
541
542 /*
543 ** Build a command line that causes the user's shell to list the file name
544 ** arguments.  This handles and wildcard expansion, tilde expansion, etc.
545 */
546 static void
547 writelscmd(char *buf, int bufsz, char **argp)
548 {
549         writesomecmd(buf, bufsz, "ls", "", argp);
550 }
551
552 /*
553 ** Like system(), but run the command in directory dir.
554 ** This assumes the program is single-threaded!
555 */
556 static int
557 system_in_dir(const char *dir, const char *cmd)
558 {
559         char olddir[BUFSIZ];
560         int r;
561         if (getcwd(olddir, sizeof(olddir)) == 0)
562                 adios("getcwd", "could not get working directory");
563         if (chdir(dir) != 0)
564                 adios("chdir", "could not change working directory");
565         r = system(cmd);
566         if (chdir(olddir) != 0)
567                 adios("chdir", "could not change working directory");
568         return r;
569 }
570
571 /* ditto for popen() */
572 static FILE*
573 popen_in_dir(const char *dir, const char *cmd, const char *type)
574 {
575         char olddir[BUFSIZ];
576         FILE *f;
577         if (getcwd(olddir, sizeof(olddir)) == 0)
578                 adios("getcwd", "could not get working directory");
579         if (chdir(dir) != 0)
580                 adios("chdir", "could not change working directory");
581         f = popen(cmd, type);
582         if (chdir(olddir) != 0)
583                 adios("chdir", "could not change working directory");
584         return f;
585 }
586
587
588 /*
589 ** EDIT
590 */
591
592 static int  reedit = 0;  /* have we been here before? */
593 static char *edsave = NULL;  /* the editor we used previously */
594
595
596 static int
597 editfile(char **ed, char **arg, char *file, int use, struct msgs *mp,
598         char *altmsg, char *cwd, int save_editor)
599 {
600         int pid, status, vecp;
601         char altpath[BUFSIZ], linkpath[BUFSIZ];
602         char *cp, *vec[MAXARGS];
603         struct stat st;
604
605 #ifdef HAVE_LSTAT
606         int slinked = 0;
607 #endif /* HAVE_LSTAT */
608
609         /* Was there a previous edit session? */
610         if (reedit) {
611                 if (!*ed) {  /* no explicit editor */
612                         *ed = edsave;  /* so use the previous one */
613                         if ((cp = mhbasename(*ed)) == NULL)
614                                 cp = *ed;
615
616                         /* unless we've specified it via "editor-next" */
617                         cp = concat(cp, "-next", NULL);
618                         if ((cp = context_find(cp)) != NULL)
619                                 *ed = cp;
620                 }
621         } else {
622                 /* set initial editor */
623                 if (*ed == NULL && (*ed = context_find("editor")) == NULL)
624                         *ed = defaulteditor;
625         }
626
627         if (altmsg) {
628                 if (mp == NULL || *altmsg == '/' || cwd == NULL)
629                         strncpy(altpath, altmsg, sizeof(altpath));
630                 else
631                         snprintf(altpath, sizeof(altpath), "%s/%s",
632                                         mp->foldpath, altmsg);
633                 if (cwd == NULL)
634                         strncpy(linkpath, altmsglink, sizeof(linkpath));
635                 else
636                         snprintf(linkpath, sizeof(linkpath), "%s/%s",
637                                         cwd, altmsglink);
638         }
639
640         if (altmsg) {
641                 unlink(linkpath);
642 #ifdef HAVE_LSTAT
643                 if (link(altpath, linkpath) == NOTOK) {
644                         symlink(altpath, linkpath);
645                         slinked = 1;
646                 } else {
647                         slinked = 0;
648                 }
649 #else /* not HAVE_LSTAT */
650                 link(altpath, linkpath);
651 #endif /* not HAVE_LSTAT */
652         }
653
654         context_save();  /* save the context file */
655         fflush(stdout);
656
657         switch (pid = fork()) {
658         case NOTOK:
659                 advise("fork", "unable to");
660                 status = NOTOK;
661                 break;
662
663         case OK:
664                 if (cwd)
665                         chdir(cwd);
666                 if (altmsg) {
667                         if (mp)
668                                 m_putenv("mhfolder", mp->foldpath);
669                         m_putenv("editalt", altpath);
670                 }
671
672                 vecp = 0;
673                 vec[vecp++] = mhbasename(*ed);
674                 if (arg)
675                         while (*arg)
676                                 vec[vecp++] = *arg++;
677                 vec[vecp++] = file;
678                 vec[vecp] = NULL;
679
680                 execvp(*ed, vec);
681                 fprintf(stderr, "unable to exec ");
682                 perror(*ed);
683                 _exit(-1);
684
685         default:
686                 if ((status = pidwait(pid, NOTOK))) {
687                         if (((status & 0xff00) != 0xff00)
688                                 && (!reedit || (status & 0x00ff))) {
689                                 if (!use && (status & 0xff00) && (rename(file, cp = m_backup (file)) != NOTOK)) {
690                                         advise(NULL, "problems with edit--draft left in %s", cp);
691                                 } else {
692                                         advise(NULL, "problems with edit--%s preserved", file);
693                                 }
694                         }
695                         status = -2;  /* maybe "reedit ? -2 : -1"? */
696                         break;
697                 }
698
699                 reedit++;
700 #ifdef HAVE_LSTAT
701                 if (altmsg && mp && !is_readonly(mp) && (slinked ?
702                                 lstat (linkpath, &st) != NOTOK &&
703                                 S_ISREG(st.st_mode) &&
704                                 copyf(linkpath, altpath) == NOTOK :
705                                 stat(linkpath, &st) != NOTOK &&
706                                 st.st_nlink == 1 &&
707                                 (unlink(altpath) == NOTOK ||
708                                 link(linkpath, altpath) == NOTOK)))
709                         advise(linkpath, "unable to update %s from", altmsg);
710 #else /* HAVE_LSTAT */
711                 if (altmsg && mp && !is_readonly(mp) &&
712                                 stat(linkpath, &st) != NOTOK &&
713                                 st.st_nlink == 1 &&
714                                 (unlink(altpath) == NOTOK ||
715                                 link(linkpath, altpath) == NOTOK))
716                         advise(linkpath, "unable to update %s from", altmsg);
717 #endif /* HAVE_LSTAT */
718         }
719
720         /* normally, we remember which editor we used */
721         if (save_editor)
722                 edsave = getcpy(*ed);
723
724         *ed = NULL;
725         if (altmsg)
726                 unlink(linkpath);
727
728         return status;
729 }
730
731
732 #ifdef HAVE_LSTAT
733 static int
734 copyf(char *ifile, char *ofile)
735 {
736         int i, in, out;
737         char buffer[BUFSIZ];
738
739         if ((in = open(ifile, O_RDONLY)) == NOTOK)
740                 return NOTOK;
741         if ((out = open(ofile, O_WRONLY | O_TRUNC)) == NOTOK) {
742                 admonish(ofile, "unable to open and truncate");
743                 close(in);
744                 return NOTOK;
745         }
746
747         while ((i = read(in, buffer, sizeof(buffer))) > OK)
748                 if (write(out, buffer, i) != i) {
749                         advise(ofile, "may have damaged");
750                         i = NOTOK;
751                         break;
752                 }
753
754         close(in);
755         close(out);
756         return i;
757 }
758 #endif /* HAVE_LSTAT */
759
760
761 /*
762 ** SEND
763 */
764
765 static int
766 sendfile(char **arg, char *file, int pushsw)
767 {
768         pid_t child_id;
769         int i, vecp;
770         char *vec[MAXARGS];
771
772         context_save();  /* save the context file */
773         fflush(stdout);
774
775         for (i = 0; (child_id = fork()) == NOTOK && i < 5; i++)
776                 sleep(5);
777         switch (child_id) {
778         case NOTOK:
779                 advise(NULL, "unable to fork, so sending directly...");
780                 /* fall */
781         case OK:
782                 vecp = 0;
783                 vec[vecp++] = invo_name;
784                 if (pushsw)
785                         vec[vecp++] = "-push";
786                 if (arg)
787                         while (*arg)
788                                 vec[vecp++] = *arg++;
789                 vec[vecp++] = file;
790                 vec[vecp] = NULL;
791
792                 execvp(sendproc, vec);
793                 fprintf(stderr, "unable to exec ");
794                 perror(sendproc);
795                 _exit(-1);
796
797         default:
798                 if (pidwait(child_id, OK) == 0)
799                         done(0);
800                 return 1;
801         }
802 }
803
804
805 /*
806 ** Remove the draft file
807 */
808
809 static int
810 removefile(char *drft)
811 {
812         if (unlink(drft) == NOTOK)
813                 adios(drft, "unable to unlink");
814
815         return OK;
816 }