9 date 92.12.15.00.20.22; author jromine; state Exp;
14 date 92.11.04.00.38.40; author jromine; state Exp;
19 date 92.02.05.07.26.30; author jromine; state Exp;
24 date 92.01.31.22.07.10; author jromine; state Exp;
29 date 90.04.05.15.00.32; author sources; state Exp;
34 date 90.02.06.13.16.22; author sources; state Exp;
39 date 90.02.06.13.16.10; author sources; state Exp;
53 @/* ap.c - parse addresses 822-style */
55 static char ident[] = "@@(#)$Id: ap.c,v 1.6 1992/11/04 00:38:40 jromine Exp jromine $";
59 #include "../h/addrsbr.h"
60 #include "../h/formatsbr.h"
70 #define WBUFSIZ BUFSIZ
72 #define FORMAT "%<{error}%{error}: %{text}%|%(putstr(proper{text}))%>"
76 static struct swit switches[] = {
98 static struct format *fmt;
102 static int process();
126 setlocale(LC_ALL, "");
128 invo_name = r1bindex (argv[0], '/');
129 mts_init (invo_name);
130 if ((cp = m_find (invo_name)) != NULL) {
131 ap = brkstring (cp = getcpy (cp), " ", "\n");
132 ap = copyip (ap, arguments);
136 (void) copyip (argv + 1, ap);
141 while (cp = *argp++) {
143 switch (smatch (++cp, switches)) {
145 ambigsw (cp, switches);
149 adios (NULLCP, "-%s unknown", cp);
152 (void) sprintf (buf, "%s [switches] addrs ...", invo_name);
153 help (buf, switches);
157 if (!(form = *argp++) || *form == '-')
158 adios (NULLCP, "missing argument to %s", argp[-2]);
162 if (!(format = *argp++) || *format == '-')
163 adios (NULLCP, "missing argument to %s", argp[-2]);
168 if (!(cp = *argp++) || *cp == '-')
169 adios (NULLCP, "missing argument to %s", argp[-2]);
181 adios (NULLCP, "more than %d addresses", NADDRS);
190 adios (NULLCP, "usage: %s [switches] addrs ...", invo_name);
192 nfs = new_fs (form, format, FORMAT);
194 if ((width = sc_width ()) < WIDTH / 2)
200 fmt_norm = normalize;
201 (void) fmt_compile (nfs, &fmt);
202 dat[0] = dat[1] = dat[2] = dat[4] = 0;
205 for (addrp = 0; addrs[addrp]; addrp++)
206 status += process (addrs[addrp], width, normalize);
216 struct pqpair *pq_next;
220 static int process (arg, length, norm)
227 char buffer[WBUFSIZ + 1],
229 register struct comp *cptr;
230 register struct pqpair *p,
233 register struct mailname *mp;
235 (q = &pq) -> pq_next = NULL;
236 while (cp = getname (arg)) {
237 if ((p = (struct pqpair *) calloc ((unsigned) 1, sizeof *p)) == NULL)
238 adios (NULLCP, "unable to allocate pqpair memory");
239 if ((mp = getm (cp, NULLCP, 0, norm, error)) == NULL) {
240 p -> pq_text = getcpy (cp);
241 p -> pq_error = getcpy (error);
245 p -> pq_text = getcpy (mp -> m_text);
248 q = (q -> pq_next = p);
251 for (p = pq.pq_next; p; p = q) {
252 FINDCOMP (cptr, "text");
254 cptr -> c_text = p -> pq_text;
255 FINDCOMP (cptr, "error");
257 cptr -> c_text = p -> pq_error;
259 (void) fmtscan (fmt, buffer, length, dat);
260 (void) fputs (buffer, stdout);
264 free (p -> pq_error);
281 static char ident[] = "@@(#)$Id: ap.c,v 1.5 1992/02/05 07:26:30 jromine Exp jromine $";
288 @put unseen sequence in mh-format
293 static char ident[] = "@@(#)$Id: ap.c,v 1.4 1992/01/31 22:07:10 jromine Exp jromine $";
306 static char ident[] = "@@(#)$Id: ap.c,v 1.3 1990/04/05 15:00:32 sources Exp jromine $";
312 dat[0] = dat[1] = dat[2] = 0;
323 static char ident[] = "@@(#)$Id:$";