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 = mhbasename(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 ...", invo_name);
79 print_help(buf, switches, 1);
82 print_version(invo_name);
86 if (!(form = *argp++) || *form == '-')
87 adios(NULL, "missing argument to %s", argp[-2]);
91 if (!(format = *argp++) || *format == '-')
92 adios(NULL, "missing argument to %s", argp[-2]);
97 if (!(cp = *argp++) || *cp == '-')
98 adios(NULL, "missing argument to %s", argp[-2]);
104 adios(NULL, "more than %d dates", NDATES);
111 adios(NULL, "usage: %s [switches] dates ...", invo_name);
113 /* get new format string */
114 nfs = new_fs(form, format, FORMAT);
117 if ((width = sc_width()) < WIDTH / 2)
123 fmt_compile(nfs, &fmt);
131 for (datep = 0; dates[datep]; datep++)
132 status += process(dates[datep], width);
134 context_save(); /* save the context file */
141 process(char *date, int length)
144 char buffer[WBUFSIZ + 1];
145 register struct comp *cptr;
147 FINDCOMP(cptr, "text");
150 fmt_scan(fmt, buffer, length, dat);
151 fputs(buffer, stdout);