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>
15 #define FORMAT "=%<(nodate{text})error: %{text}%|%(putstr(pretty{text}))%>"
17 static struct swit switches[] = {
19 { "form formatfile", 0 },
27 static struct format *fmt;
34 static int process(char *);
38 main(int argc, char **argv)
40 int datep = 0, status = 0;
41 char *cp, *form = NULL, *fmtstr;
42 char buf[BUFSIZ], **argp, **arguments;
46 setlocale(LC_ALL, "");
48 invo_name = mhbasename(argv[0]);
50 /* read user profile/context */
53 arguments = getarguments(invo_name, argc, argv, 1);
56 while ((cp = *argp++)) {
58 switch (smatch(++cp, switches)) {
60 ambigsw(cp, switches);
63 adios(NULL, "-%s unknown", cp);
66 snprintf(buf, sizeof(buf), "%s [switches] dates ...", invo_name);
67 print_help(buf, switches, 1);
70 print_version(invo_name);
74 if (!(form = *argp++) || *form == '-')
75 adios(NULL, "missing argument to %s",
82 adios(NULL, "more than %d dates", NDATES);
89 adios(NULL, "usage: %s [switches] dates ...", invo_name);
91 /* get new format string */
92 fmtstr = new_fs(form, FORMAT);
94 fmt_compile(fmtstr, &fmt);
102 for (datep = 0; dates[datep]; datep++)
103 status += process(dates[datep]);
105 context_save(); /* save the context file */
115 char buffer[BUFSIZ + 1];
116 register struct comp *cptr;
118 FINDCOMP(cptr, "text");
121 fmt_scan(fmt, buffer, BUFSIZ, dat);
122 fputs(buffer, stdout);