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