]> diplodocus.org Git - nmh/blob - sbr/refile.c
Alter mh-chart(7)'s NAME to be lowercase.
[nmh] / sbr / refile.c
1
2 /*
3 * refile.c -- call the "fileproc" to refile the
4 * -- msg or draft into another folder
5 *
6 * This code is Copyright (c) 2002, by the authors of nmh. See the
7 * COPYRIGHT file in the root directory of the nmh distribution for
8 * complete copyright information.
9 */
10
11 #include <h/mh.h>
12 #include <h/utils.h>
13
14
15 int
16 refile (char **arg, char *file)
17 {
18 pid_t pid;
19 int vecp;
20 char **vec;
21 char *program;
22
23 vec = argsplit(fileproc, &program, &vecp);
24
25 vec[vecp++] = mh_xstrdup("-nolink"); /* override bad .mh_profile defaults */
26 vec[vecp++] = mh_xstrdup("-nopreserve");
27 vec[vecp++] = mh_xstrdup("-file");
28 vec[vecp++] = getcpy(file);
29
30 if (arg) {
31 while (*arg)
32 vec[vecp++] = mh_xstrdup(*arg++);
33 }
34 vec[vecp] = NULL;
35
36 context_save(); /* save the context file */
37 fflush(stdout);
38
39 switch (pid = fork()) {
40 case -1:
41 advise ("fork", "unable to");
42 return -1;
43
44 case 0:
45 execvp (program, vec);
46 fprintf (stderr, "unable to exec ");
47 perror (fileproc);
48 _exit (-1);
49
50 default:
51 arglist_free(program, vec);
52 return (pidwait (pid, -1));
53 }
54 }