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>
16 #define WBUFSIZ BUFSIZ
18 #define FORMAT "=%<(nodate{text})error: %{text}%|%(putstr(pretty{text}))%>"
20 static struct swit switches[] = {
22 { "form formatfile", 0 },
24 { "width columns", 0 },
32 static struct format *fmt;
39 int sc_width(void); /* from termsbr.c */
44 static int process(char *, int);
48 main(int argc, char **argv)
50 int datep = 0, width = 0, status = 0;
51 char *cp, *form = NULL, *nfs;
52 char buf[BUFSIZ], **argp, **arguments;
56 setlocale(LC_ALL, "");
58 invo_name = mhbasename(argv[0]);
60 /* read user profile/context */
63 arguments = getarguments(invo_name, argc, argv, 1);
66 while ((cp = *argp++)) {
68 switch (smatch(++cp, switches)) {
70 ambigsw(cp, switches);
73 adios(NULL, "-%s unknown", cp);
76 snprintf(buf, sizeof(buf), "%s [switches] dates ...", invo_name);
77 print_help(buf, switches, 1);
80 print_version(invo_name);
84 if (!(form = *argp++) || *form == '-')
85 adios(NULL, "missing argument to %s",
90 if (!(cp = *argp++) || *cp == '-')
91 adios(NULL, "missing argument to %s",
98 adios(NULL, "more than %d dates", NDATES);
105 adios(NULL, "usage: %s [switches] dates ...", invo_name);
107 /* get new format string */
108 nfs = new_fs(form, FORMAT);
111 if ((width = sc_width()) < WIDTH / 2)
117 fmt_compile(nfs, &fmt);
125 for (datep = 0; dates[datep]; datep++)
126 status += process(dates[datep], width);
128 context_save(); /* save the context file */
135 process(char *date, int length)
138 char buffer[WBUFSIZ + 1];
139 register struct comp *cptr;
141 FINDCOMP(cptr, "text");
144 fmt_scan(fmt, buffer, length, dat);
145 fputs(buffer, stdout);