]> diplodocus.org Git - nmh/blob - sbr/refile.c
fea72e210afc52d4fb2eaca8edac502509a97003
[nmh] / sbr / refile.c
1 /* refile.c -- call the "fileproc" to refile the
2 * -- msg or draft into another folder
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
9 #include <h/mh.h>
10 #include "error.h"
11 #include <h/utils.h>
12
13
14 int
15 refile (char **arg, char *file)
16 {
17 pid_t pid;
18 int vecp;
19 char **vec;
20 char *program;
21
22 vec = argsplit(fileproc, &program, &vecp);
23
24 vec[vecp++] = mh_xstrdup("-nolink"); /* override bad .mh_profile defaults */
25 vec[vecp++] = mh_xstrdup("-nopreserve");
26 vec[vecp++] = mh_xstrdup("-file");
27 vec[vecp++] = getcpy(file);
28
29 if (arg) {
30 while (*arg)
31 vec[vecp++] = mh_xstrdup(*arg++);
32 }
33 vec[vecp] = NULL;
34
35 context_save(); /* save the context file */
36 fflush(stdout);
37
38 switch (pid = fork()) {
39 case -1:
40 advise ("fork", "unable to");
41 return -1;
42
43 case 0:
44 execvp (program, vec);
45 fprintf (stderr, "unable to exec ");
46 perror (fileproc);
47 _exit(1);
48
49 default:
50 arglist_free(program, vec);
51 return pidwait(pid, -1);
52 }
53 }