Remove unused code
[mmh] / uip / dp.c
1 /*
2 ** dp.c -- parse dates 822-style
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/fmt_scan.h>
11 #include <h/tws.h>
12 #include <locale.h>
13 #include <sysexits.h>
14
15 #define NDATES 100
16
17 #define FORMAT "=%<(nodate{text})error: %{text}%|%(putstr(pretty{text}))%>"
18
19 static struct swit switches[] = {
20 #define FORMSW  0
21         { "form formatfile", 0 },
22 #define VERSIONSW  1
23         { "Version", 0 },
24 #define HELPSW  2
25         { "help", 0 },
26         { NULL, 0 }
27 };
28
29 char *version=VERSION;
30
31 static struct format *fmt;
32
33 static int dat[5];
34
35 /*
36 ** static prototypes
37 */
38 static int process(char *);
39
40
41 int
42 main(int argc, char **argv)
43 {
44         int datep = 0, status = 0;
45         char *cp, *form = NULL, *fmtstr;
46         char buf[BUFSIZ], **argp, **arguments;
47         char *dates[NDATES];
48
49         setlocale(LC_ALL, "");
50         invo_name = mhbasename(argv[0]);
51
52         /* read user profile/context */
53         context_read();
54
55         arguments = getarguments(invo_name, argc, argv, 1);
56         argp = arguments;
57
58         while ((cp = *argp++)) {
59                 if (*cp == '-') {
60                         switch (smatch(++cp, switches)) {
61                         case AMBIGSW:
62                                 ambigsw(cp, switches);
63                                 exit(EX_USAGE);
64                         case UNKWNSW:
65                                 adios(EX_USAGE, NULL, "-%s unknown", cp);
66
67                         case HELPSW:
68                                 snprintf(buf, sizeof(buf), "%s [switches] dates ...", invo_name);
69                                 print_help(buf, switches, 1);
70                                 exit(argc == 2 ? EX_OK : EX_USAGE);
71                         case VERSIONSW:
72                                 print_version(invo_name);
73                                 exit(argc == 2 ? EX_OK : EX_USAGE);
74
75                         case FORMSW:
76                                 if (!(form = *argp++) || *form == '-')
77                                         adios(EX_USAGE, NULL, "missing argument to %s",
78                                                         argp[-2]);
79                                 continue;
80
81                         }
82                 }
83                 if (datep > NDATES)
84                         adios(EX_USAGE, NULL, "more than %d dates", NDATES);
85                 else
86                         dates[datep++] = cp;
87         }
88         dates[datep] = NULL;
89
90         if (datep == 0)
91                 adios(EX_USAGE, NULL, "usage: %s [switches] dates ...", invo_name);
92
93         /* get new format string */
94         fmtstr = new_fs(form, FORMAT);
95
96         fmt_compile(fmtstr, &fmt);
97
98         dat[0] = 0;
99         dat[1] = 0;
100         dat[2] = 0;
101         dat[3] = BUFSIZ;
102         dat[4] = 0;
103
104         for (datep = 0; dates[datep]; datep++)
105                 status += process(dates[datep]);
106
107         context_save();  /* save the context file */
108         return status;
109 }
110
111
112 static int
113 process(char *date)
114 {
115         int status = 0;
116         char buffer[BUFSIZ + 1];
117         struct comp *cptr;
118
119         FINDCOMP(cptr, "text");
120         if (cptr)
121                 cptr->c_text = date;
122         fmt_scan(fmt, buffer, BUFSIZ, dat);
123         fputs(buffer, stdout);
124
125         return status;
126 }