]>
diplodocus.org Git - nmh/blob - docs/historical/mh-6.8.5/uip/dp.c
1 /* dp.c - parse dates 822-style */
3 static char ident
[] = "@(#)$Id: dp.c,v 1.7 1992/12/15 00:20:22 jromine Exp $";
7 #include "../h/formatsbr.h"
8 #include "../zotnet/tws.h"
18 #define WBUFSIZ BUFSIZ
20 #define FORMAT "%<(nodate{text})error: %{text}%|%(putstr(pretty{text}))%>"
24 static struct swit switches
[] = {
41 static struct format
*fmt
;
68 setlocale(LC_ALL
, "");
70 invo_name
= r1bindex (argv
[0], '/');
71 if ((cp
= m_find (invo_name
)) != NULL
) {
72 ap
= brkstring (cp
= getcpy (cp
), " ", "\n");
73 ap
= copyip (ap
, arguments
);
77 (void) copyip (argv
+ 1, ap
);
82 while (cp
= *argp
++) {
84 switch (smatch (++cp
, switches
)) {
86 ambigsw (cp
, switches
);
89 adios (NULLCP
, "-%s unknown", cp
);
91 (void) sprintf (buf
, "%s [switches] dates ...", invo_name
);
96 if (!(form
= *argp
++) || *form
== '-')
97 adios (NULLCP
, "missing argument to %s", argp
[-2]);
101 if (!(format
= *argp
++) || *format
== '-')
102 adios (NULLCP
, "missing argument to %s", argp
[-2]);
107 if (!(cp
= *argp
++) || *cp
== '-')
108 adios (NULLCP
, "missing argument to %s", argp
[-2]);
113 adios (NULLCP
, "more than %d dates", NDATES
);
122 adios (NULLCP
, "usage: %s [switches] dates ...", invo_name
);
124 nfs
= new_fs (form
, format
, FORMAT
);
126 if ((width
= sc_width ()) < WIDTH
/ 2)
132 (void) fmt_compile (nfs
, &fmt
);
133 dat
[0] = dat
[1] = dat
[2] = dat
[4] = 0;
136 for (datep
= 0; dates
[datep
]; datep
++)
137 status
+= process (dates
[datep
], width
);
146 static int process (date
, length
)
151 char buffer
[WBUFSIZ
+ 1];
152 register struct comp
*cptr
;
154 FINDCOMP (cptr
, "text");
156 cptr
-> c_text
= date
;
157 (void) fmtscan (fmt
, buffer
, length
, dat
);
158 (void) fputs (buffer
, stdout
);