3 * dp.c -- parse dates 822-style
7 * This code is Copyright (c) 2002, by the authors of nmh. See the
8 * COPYRIGHT file in the root directory of the nmh distribution for
9 * complete copyright information.
13 #include <h/fmt_scan.h>
19 #define WBUFSIZ BUFSIZ
21 #define FORMAT "%<(nodate{text})error: %{text}%|%(putstr(pretty{text}))%>"
23 static struct swit switches[] = {
25 { "form formatfile", 0 },
27 { "format string", 5 },
29 { "width columns", 0 },
37 static struct format *fmt;
44 int sc_width (void); /* from termsbr.c */
49 static int process (char *, int);
53 main (int argc, char **argv)
55 int datep = 0, width = 0, status = 0;
56 char *cp, *form = NULL, *format = NULL, *nfs;
57 char buf[BUFSIZ], **argp, **arguments;
61 setlocale(LC_ALL, "");
63 invo_name = r1bindex (argv[0], '/');
65 /* read user profile/context */
68 arguments = getarguments (invo_name, argc, argv, 1);
71 while ((cp = *argp++)) {
73 switch (smatch (++cp, switches)) {
75 ambigsw (cp, switches);
78 adios (NULL, "-%s unknown", cp);
81 snprintf (buf, sizeof(buf), "%s [switches] dates ...",
83 print_help (buf, switches, 1);
86 print_version(invo_name);
90 if (!(form = *argp++) || *form == '-')
91 adios (NULL, "missing argument to %s", argp[-2]);
95 if (!(format = *argp++) || *format == '-')
96 adios (NULL, "missing argument to %s", argp[-2]);
101 if (!(cp = *argp++) || *cp == '-')
102 adios (NULL, "missing argument to %s", argp[-2]);
108 adios (NULL, "more than %d dates", NDATES);
115 adios (NULL, "usage: %s [switches] dates ...", invo_name);
117 /* get new format string */
118 nfs = new_fs (form, format, FORMAT);
121 if ((width = sc_width ()) < WIDTH / 2)
127 fmt_compile (nfs, &fmt);
135 for (datep = 0; dates[datep]; datep++)
136 status += process (dates[datep], width);
138 context_save (); /* save the context file */
139 return done (status);
144 process (char *date, int length)
147 char buffer[WBUFSIZ + 1];
148 register struct comp *cptr;
150 FINDCOMP (cptr, "text");
153 fmt_scan (fmt, buffer, length, dat);
154 fputs (buffer, stdout);