]>
diplodocus.org Git - nmh/blob - uip/dp.c
3 * dp.c -- parse dates 822-style
5 * This code is Copyright (c) 2002, by the authors of nmh. See the
6 * COPYRIGHT file in the root directory of the nmh distribution for
7 * complete copyright information.
11 #include <h/fmt_scan.h>
17 #define WBUFSIZ BUFSIZ
19 #define FORMAT "%<(nodate{text})error: %{text}%|%(putstr(pretty{text}))%>"
21 static struct swit switches
[] = {
23 { "form formatfile", 0 },
25 { "format string", 5 },
27 { "width columns", 0 },
35 static struct format
*fmt
;
42 static int process (char *, int);
46 main (int argc
, char **argv
)
48 int datep
= 0, width
= 0, status
= 0;
49 char *cp
, *form
= NULL
, *format
= NULL
, *nfs
;
50 char buf
[BUFSIZ
], **argp
, **arguments
;
54 setlocale(LC_ALL
, "");
56 invo_name
= r1bindex (argv
[0], '/');
58 /* read user profile/context */
61 arguments
= getarguments (invo_name
, argc
, argv
, 1);
64 while ((cp
= *argp
++)) {
66 switch (smatch (++cp
, switches
)) {
68 ambigsw (cp
, switches
);
71 adios (NULL
, "-%s unknown", cp
);
74 snprintf (buf
, sizeof(buf
), "%s [switches] dates ...",
76 print_help (buf
, switches
, 1);
79 print_version(invo_name
);
83 if (!(form
= *argp
++) || *form
== '-')
84 adios (NULL
, "missing argument to %s", argp
[-2]);
88 if (!(format
= *argp
++) || *format
== '-')
89 adios (NULL
, "missing argument to %s", argp
[-2]);
94 if (!(cp
= *argp
++) || *cp
== '-')
95 adios (NULL
, "missing argument to %s", argp
[-2]);
101 adios (NULL
, "more than %d dates", NDATES
);
108 adios (NULL
, "usage: %s [switches] dates ...", invo_name
);
110 /* get new format string */
111 nfs
= new_fs (form
, format
, FORMAT
);
114 if ((width
= sc_width ()) < WIDTH
/ 2)
120 fmt_compile (nfs
, &fmt
);
128 for (datep
= 0; dates
[datep
]; datep
++)
129 status
+= process (dates
[datep
], width
);
131 context_save (); /* save the context file */
138 process (char *date
, int length
)
141 char buffer
[WBUFSIZ
+ 1];
142 register struct comp
*cptr
;
144 FINDCOMP (cptr
, "text");
147 fmt_scan (fmt
, buffer
, length
, dat
);
148 fputs (buffer
, stdout
);