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 static struct format *fmt;
36 static int process(char *);
40 main(int argc, char **argv)
42 int datep = 0, status = 0;
43 char *cp, *form = NULL, *fmtstr;
44 char buf[BUFSIZ], **argp, **arguments;
47 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(EX_USAGE, NULL, "-%s unknown", cp);
66 snprintf(buf, sizeof(buf), "%s [switches] dates ...", invo_name);
67 print_help(buf, switches, 1);
68 exit(argc == 2 ? EX_OK : EX_USAGE);
70 print_version(invo_name);
71 exit(argc == 2 ? EX_OK : EX_USAGE);
74 if (!(form = *argp++) || *form == '-')
75 adios(EX_USAGE, NULL, "missing argument to %s",
82 adios(EX_USAGE, NULL, "more than %d dates", NDATES);
89 adios(EX_USAGE, 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 */
114 char buffer[BUFSIZ + 1];
117 FINDCOMP(cptr, "text");
120 fmt_scan(fmt, buffer, BUFSIZ, dat);
121 fputs(buffer, stdout);