]> diplodocus.org Git - nmh/blob - uip/rcvpack.c
Use va_copy() to get a copy of va_list, instead of using original.
[nmh] / uip / rcvpack.c
1 /* rcvpack.c -- append message to a file
2 *
3 * This code is Copyright (c) 2002, by the authors of nmh. See the
4 * COPYRIGHT file in the root directory of the nmh distribution for
5 * complete copyright information.
6 */
7
8 #include <h/mh.h>
9 #include <h/dropsbr.h>
10 #include <h/rcvmail.h>
11 #include <h/tws.h>
12 #include <h/mts.h>
13 #include "h/done.h"
14 #include <h/utils.h>
15
16 #define RCVPACK_SWITCHES \
17 X("mbox", 0, MBOXSW) \
18 X("mmdf", 0, MMDFSW) \
19 X("version", 0, VERSIONSW) \
20 X("help", 0, HELPSW) \
21
22 #define X(sw, minchars, id) id,
23 DEFINE_SWITCH_ENUM(RCVPACK);
24 #undef X
25
26 #define X(sw, minchars, id) { sw, minchars, id },
27 DEFINE_SWITCH_ARRAY(RCVPACK, switches);
28 #undef X
29
30 /*
31 * default format in which to save messages
32 */
33 static int mbx_style = MBOX_FORMAT;
34
35
36 int
37 main (int argc, char **argv)
38 {
39 int md;
40 char *cp, *file = NULL, buf[BUFSIZ];
41 char **argp, **arguments;
42
43 if (nmh_init(argv[0], true, false)) { return 1; }
44
45 mts_init ();
46 arguments = getarguments (invo_name, argc, argv, 1);
47 argp = arguments;
48
49 /* parse arguments */
50 while ((cp = *argp++)) {
51 if (*cp == '-') {
52 switch (smatch (++cp, switches)) {
53 case AMBIGSW:
54 ambigsw (cp, switches);
55 done (1);
56 case UNKWNSW:
57 die("-%s unknown", cp);
58
59 case HELPSW:
60 snprintf (buf, sizeof(buf), "%s [switches] file", invo_name);
61 print_help (buf, switches, 1);
62 done (0);
63 case VERSIONSW:
64 print_version(invo_name);
65 done (0);
66
67 case MBOXSW:
68 mbx_style = MBOX_FORMAT;
69 continue;
70 case MMDFSW:
71 mbx_style = MMDF_FORMAT;
72 continue;
73 }
74 }
75 if (file)
76 die("only one file at a time!");
77 file = cp;
78 }
79
80 if (!file)
81 die("%s [switches] file", invo_name);
82
83 rewind (stdin);
84
85 /* open and lock the file */
86 if ((md = mbx_open (file, mbx_style, getuid(), getgid(), m_gmprot())) == NOTOK)
87 done (RCV_MBX);
88
89 /* append the message */
90 if (mbx_copy (file, mbx_style, md, fileno(stdin), NULL) == NOTOK) {
91 mbx_close (file, md);
92 done (RCV_MBX);
93 }
94
95 /* close and unlock the file */
96 if (mbx_close (file, md) == NOTOK)
97 done (RCV_MBX);
98
99 done (RCV_MOK);
100 return 1;
101 }