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