]> diplodocus.org Git - nmh/blob - uip/rcvpack.c
Fixed three LC_ALL settings:
[nmh] / uip / rcvpack.c
1
2 /*
3 * rcvpack.c -- append message to a file
4 *
5 * This code is Copyright (c) 2002, by the authors of nmh. See the
6 * COPYRIGHT file in the root directory of the nmh distribution for
7 * complete copyright information.
8 */
9
10 #include <h/mh.h>
11 #include <h/dropsbr.h>
12 #include <h/rcvmail.h>
13 #include <h/tws.h>
14 #include <h/mts.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 setlocale(LC_ALL, "");
44 invo_name = r1bindex (argv[0], '/');
45
46 /* read user profile/context */
47 context_read();
48
49 mts_init (invo_name);
50 arguments = getarguments (invo_name, argc, argv, 1);
51 argp = arguments;
52
53 /* parse arguments */
54 while ((cp = *argp++)) {
55 if (*cp == '-') {
56 switch (smatch (++cp, switches)) {
57 case AMBIGSW:
58 ambigsw (cp, switches);
59 done (1);
60 case UNKWNSW:
61 adios (NULL, "-%s unknown", cp);
62
63 case HELPSW:
64 snprintf (buf, sizeof(buf), "%s [switches] file", invo_name);
65 print_help (buf, switches, 1);
66 done (0);
67 case VERSIONSW:
68 print_version(invo_name);
69 done (0);
70
71 case MBOXSW:
72 mbx_style = MBOX_FORMAT;
73 continue;
74 case MMDFSW:
75 mbx_style = MMDF_FORMAT;
76 continue;
77 }
78 }
79 if (file)
80 adios (NULL, "only one file at a time!");
81 else
82 file = cp;
83 }
84
85 if (!file)
86 adios (NULL, "%s [switches] file", invo_name);
87
88 rewind (stdin);
89
90 /* open and lock the file */
91 if ((md = mbx_open (file, mbx_style, getuid(), getgid(), m_gmprot())) == NOTOK)
92 done (RCV_MBX);
93
94 /* append the message */
95 if (mbx_copy (file, mbx_style, md, fileno(stdin), 1, NULL, 0) == NOTOK) {
96 mbx_close (file, md);
97 done (RCV_MBX);
98 }
99
100 /* close and unlock the file */
101 if (mbx_close (file, md) == NOTOK)
102 done (RCV_MBX);
103
104 done (RCV_MOK);
105 return 1;
106 }