]> diplodocus.org Git - nmh/blob - sbr/refile.c
Another pass at cleaning up (some of) the manpages.
[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
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++] = getcpy("-nolink"); /* override bad .mh_profile defaults */
25 vec[vecp++] = getcpy("-nopreserve");
26 vec[vecp++] = getcpy("-file");
27 vec[vecp++] = getcpy(file);
28
29 if (arg) {
30 while (*arg)
31 vec[vecp++] = *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 }