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 { "format string", 5 },
26 { "width columns", 0 },
34 static struct format *fmt;
41 int sc_width (void); /* from termsbr.c */
46 static int process (char *, int);
50 main (int argc, char **argv)
52 int datep = 0, width = 0, status = 0;
53 char *cp, *form = NULL, *format = NULL, *nfs;
54 char buf[BUFSIZ], **argp, **arguments;
58 setlocale(LC_ALL, "");
60 invo_name = r1bindex (argv[0], '/');
62 /* read user profile/context */
65 arguments = getarguments (invo_name, argc, argv, 1);
68 while ((cp = *argp++)) {
70 switch (smatch (++cp, switches)) {
72 ambigsw (cp, switches);
75 adios (NULL, "-%s unknown", cp);
78 snprintf (buf, sizeof(buf), "%s [switches] dates ...",
80 print_help (buf, switches, 1);
83 print_version(invo_name);
87 if (!(form = *argp++) || *form == '-')
88 adios (NULL, "missing argument to %s", argp[-2]);
92 if (!(format = *argp++) || *format == '-')
93 adios (NULL, "missing argument to %s", argp[-2]);
98 if (!(cp = *argp++) || *cp == '-')
99 adios (NULL, "missing argument to %s", argp[-2]);
105 adios (NULL, "more than %d dates", NDATES);
112 adios (NULL, "usage: %s [switches] dates ...", invo_name);
114 /* get new format string */
115 nfs = new_fs (form, format, FORMAT);
118 if ((width = sc_width ()) < WIDTH / 2)
124 fmt_compile (nfs, &fmt);
132 for (datep = 0; dates[datep]; datep++)
133 status += process (dates[datep], width);
135 context_save (); /* save the context file */
142 process (char *date, int length)
145 char buffer[WBUFSIZ + 1];
146 register struct comp *cptr;
148 FINDCOMP (cptr, "text");
151 fmt_scan (fmt, buffer, length, dat);
152 fputs (buffer, stdout);