3 * dp.c -- parse dates 822-style
5 * This code is Copyright (c) 2002, by the authors of nmh. See the
6 * COPYRIGHT file in the root directory of the nmh distribution for
7 * complete copyright information.
11 #include <h/fmt_scan.h>
17 #define WBUFSIZ BUFSIZ
19 #define FORMAT "%<(nodate{text})error: %{text}%|%(putstr(pretty{text}))%>"
21 static struct swit switches[] = {
23 { "form formatfile", 0 },
25 { "format string", 5 },
27 { "width columns", 0 },
35 static struct format *fmt;
42 int sc_width (void); /* from termsbr.c */
47 static int process (char *, int);
51 main (int argc, char **argv)
53 int datep = 0, width = 0, status = 0;
54 char *cp, *form = NULL, *format = NULL, *nfs;
55 char buf[BUFSIZ], **argp, **arguments;
59 setlocale(LC_ALL, "");
61 invo_name = r1bindex (argv[0], '/');
63 /* read user profile/context */
66 arguments = getarguments (invo_name, argc, argv, 1);
69 while ((cp = *argp++)) {
71 switch (smatch (++cp, switches)) {
73 ambigsw (cp, switches);
76 adios (NULL, "-%s unknown", cp);
79 snprintf (buf, sizeof(buf), "%s [switches] dates ...",
81 print_help (buf, switches, 1);
84 print_version(invo_name);
88 if (!(form = *argp++) || *form == '-')
89 adios (NULL, "missing argument to %s", argp[-2]);
93 if (!(format = *argp++) || *format == '-')
94 adios (NULL, "missing argument to %s", argp[-2]);
99 if (!(cp = *argp++) || *cp == '-')
100 adios (NULL, "missing argument to %s", argp[-2]);
106 adios (NULL, "more than %d dates", NDATES);
113 adios (NULL, "usage: %s [switches] dates ...", invo_name);
115 /* get new format string */
116 nfs = new_fs (form, format, FORMAT);
119 if ((width = sc_width ()) < WIDTH / 2)
125 fmt_compile (nfs, &fmt);
133 for (datep = 0; dates[datep]; datep++)
134 status += process (dates[datep], width);
136 context_save (); /* save the context file */
143 process (char *date, int length)
146 char buffer[WBUFSIZ + 1];
147 register struct comp *cptr;
149 FINDCOMP (cptr, "text");
152 fmt_scan (fmt, buffer, length, dat);
153 fputs (buffer, stdout);