]>
diplodocus.org Git - nmh/blob - uip/dp.c
3 * dp.c -- parse dates 822-style
9 #include <h/fmt_scan.h>
10 #include <zotnet/tws/tws.h>
15 #define WBUFSIZ BUFSIZ
17 #define FORMAT "%<(nodate{text})error: %{text}%|%(putstr(pretty{text}))%>"
19 static struct swit switches
[] = {
21 { "form formatfile", 0 },
23 { "format string", 5 },
25 { "width columns", 0 },
33 static struct format
*fmt
;
40 int sc_width (void); /* from termsbr.c */
45 static int process (char *, int);
49 main (int argc
, char **argv
)
51 int datep
= 0, width
= 0, status
= 0;
52 char *cp
, *form
= NULL
, *format
= NULL
, *nfs
;
53 char buf
[BUFSIZ
], **argp
, **arguments
;
57 setlocale(LC_ALL
, "");
59 invo_name
= r1bindex (argv
[0], '/');
61 /* read user profile/context */
64 arguments
= getarguments (invo_name
, argc
, argv
, 1);
67 while ((cp
= *argp
++)) {
69 switch (smatch (++cp
, switches
)) {
71 ambigsw (cp
, switches
);
74 adios (NULL
, "-%s unknown", cp
);
77 snprintf (buf
, sizeof(buf
), "%s [switches] dates ...",
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 */
135 return done (status
);
140 process (char *date
, int length
)
143 char buffer
[WBUFSIZ
+ 1];
144 register struct comp
*cptr
;
146 FINDCOMP (cptr
, "text");
149 fmt_scan (fmt
, buffer
, length
, dat
);
150 fputs (buffer
, stdout
);