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>
17 #define FORMAT "=%<(nodate{text})error: %{text}%|%(putstr(pretty{text}))%>"
19 static struct swit switches[] = {
21 { "form formatfile", 0 },
29 char *version=VERSION;
31 static struct format *fmt;
38 static int process(char *);
42 main(int argc, char **argv)
44 int datep = 0, status = 0;
45 char *cp, *form = NULL, *fmtstr;
46 char buf[BUFSIZ], **argp, **arguments;
49 setlocale(LC_ALL, "");
50 invo_name = mhbasename(argv[0]);
52 /* read user profile/context */
55 arguments = getarguments(invo_name, argc, argv, 1);
58 while ((cp = *argp++)) {
60 switch (smatch(++cp, switches)) {
62 ambigsw(cp, switches);
65 adios(EX_USAGE, NULL, "-%s unknown", cp);
68 snprintf(buf, sizeof(buf), "%s [switches] dates ...", invo_name);
69 print_help(buf, switches, 1);
70 exit(argc == 2 ? EX_OK : EX_USAGE);
72 print_version(invo_name);
73 exit(argc == 2 ? EX_OK : EX_USAGE);
76 if (!(form = *argp++) || *form == '-')
77 adios(EX_USAGE, NULL, "missing argument to %s",
84 adios(EX_USAGE, NULL, "more than %d dates", NDATES);
91 adios(EX_USAGE, NULL, "usage: %s [switches] dates ...", invo_name);
93 /* get new format string */
94 fmtstr = new_fs(form, FORMAT);
96 fmt_compile(fmtstr, &fmt);
104 for (datep = 0; dates[datep]; datep++)
105 status += process(dates[datep]);
107 context_save(); /* save the context file */
116 char buffer[BUFSIZ + 1];
119 FINDCOMP(cptr, "text");
122 fmt_scan(fmt, buffer, BUFSIZ, dat);
123 fputs(buffer, stdout);