Removed the space between function names and the opening parenthesis.
[mmh] / uip / rcvpack.c
1 /*
2 ** rcvpack.c -- append message to a file
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/dropsbr.h>
11 #include <h/rcvmail.h>
12 #include <h/tws.h>
13 #include <h/mts.h>
14
15 static struct swit switches[] = {
16 #define MBOXSW  0
17         { "mbox", 0 },
18 #define MMDFSW  1
19         { "mmdf", 0 },
20 #define VERSIONSW  2
21         { "version", 0 },
22 #define HELPSW  3
23         { "help", 0 },
24         { NULL, 0 }
25 };
26
27 /*
28 ** default format in which to save messages
29 */
30 static int mbx_style = MBOX_FORMAT;
31
32
33 int
34 main(int argc, char **argv)
35 {
36         int md;
37         char *cp, *file = NULL, buf[BUFSIZ];
38         char **argp, **arguments;
39
40 #ifdef LOCALE
41         setlocale(LC_ALL, "");
42 #endif
43         invo_name = r1bindex(argv[0], '/');
44
45         /* read user profile/context */
46         context_read();
47
48         mts_init(invo_name);
49         arguments = getarguments(invo_name, argc, argv, 1);
50         argp = arguments;
51
52         /* parse arguments */
53         while ((cp = *argp++)) {
54                 if (*cp == '-') {
55                         switch (smatch(++cp, switches)) {
56                                 case AMBIGSW:
57                                         ambigsw(cp, switches);
58                                         done(1);
59                                 case UNKWNSW:
60                                         adios(NULL, "-%s unknown", cp);
61
62                                 case HELPSW:
63                                         snprintf(buf, sizeof(buf),
64                                                         "%s [switches] file",
65                                                         invo_name);
66                                         print_help(buf, switches, 1);
67                                         done(1);
68                                 case VERSIONSW:
69                                         print_version(invo_name);
70                                         done(1);
71
72                                 case MBOXSW:
73                                         mbx_style = MBOX_FORMAT;
74                                         continue;
75                                 case MMDFSW:
76                                         mbx_style = MMDF_FORMAT;
77                                         continue;
78                         }
79                 }
80                 if (file)
81                         adios(NULL, "only one file at a time!");
82                 else
83                         file = cp;
84         }
85
86         if (!file)
87                 adios(NULL, "%s [switches] file", invo_name);
88
89         rewind(stdin);
90
91         /* open and lock the file */
92         if ((md = mbx_open(file, mbx_style, getuid(), getgid(), m_gmprot()))
93                         == NOTOK)
94                 done(RCV_MBX);
95
96         /* append the message */
97         if (mbx_copy(file, mbx_style, md, fileno(stdin), 1, NULL, 0)
98                         == NOTOK) {
99                 mbx_close(file, md);
100                 done(RCV_MBX);
101         }
102
103         /* close and unlock the file */
104         if (mbx_close(file, md) == NOTOK)
105                 done(RCV_MBX);
106
107         done(RCV_MOK);
108         return 1;
109 }