2 ** dp.c -- parse dates 822-style
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.
10 #include <h/fmt_scan.h>
15 #define FORMAT "=%<(nodate{text})error: %{text}%|%(putstr(pretty{text}))%>"
17 static struct swit switches[] = {
19 { "form formatfile", 0 },
27 static struct format *fmt;
34 static int process(char *);
38 main(int argc, char **argv)
40 int datep = 0, status = 0;
41 char *cp, *form = NULL, *fmtstr;
42 char buf[BUFSIZ], **argp, **arguments;
45 setlocale(LC_ALL, "");
46 invo_name = mhbasename(argv[0]);
48 /* read user profile/context */
51 arguments = getarguments(invo_name, argc, argv, 1);
54 while ((cp = *argp++)) {
56 switch (smatch(++cp, switches)) {
58 ambigsw(cp, switches);
61 adios(NULL, "-%s unknown", cp);
64 snprintf(buf, sizeof(buf), "%s [switches] dates ...", invo_name);
65 print_help(buf, switches, 1);
68 print_version(invo_name);
72 if (!(form = *argp++) || *form == '-')
73 adios(NULL, "missing argument to %s",
80 adios(NULL, "more than %d dates", NDATES);
87 adios(NULL, "usage: %s [switches] dates ...", invo_name);
89 /* get new format string */
90 fmtstr = new_fs(form, FORMAT);
92 fmt_compile(fmtstr, &fmt);
100 for (datep = 0; dates[datep]; datep++)
101 status += process(dates[datep]);
103 context_save(); /* save the context file */
113 char buffer[BUFSIZ + 1];
114 register struct comp *cptr;
116 FINDCOMP(cptr, "text");
119 fmt_scan(fmt, buffer, BUFSIZ, dat);
120 fputs(buffer, stdout);