]>
diplodocus.org Git - nmh/blob - docs/historical/mh-6.8.5/uip/ap.c
1 /* ap.c - parse addresses 822-style */
3 static char ident
[] = "@(#)$Id: ap.c,v 1.7 1992/12/15 00:20:22 jromine Exp $";
7 #include "../h/addrsbr.h"
8 #include "../h/formatsbr.h"
18 #define WBUFSIZ BUFSIZ
20 #define FORMAT "%<{error}%{error}: %{text}%|%(putstr(proper{text}))%>"
24 static struct swit switches
[] = {
46 static struct format
*fmt
;
74 setlocale(LC_ALL
, "");
76 invo_name
= r1bindex (argv
[0], '/');
78 if ((cp
= m_find (invo_name
)) != NULL
) {
79 ap
= brkstring (cp
= getcpy (cp
), " ", "\n");
80 ap
= copyip (ap
, arguments
);
84 (void) copyip (argv
+ 1, ap
);
89 while (cp
= *argp
++) {
91 switch (smatch (++cp
, switches
)) {
93 ambigsw (cp
, switches
);
97 adios (NULLCP
, "-%s unknown", cp
);
100 (void) sprintf (buf
, "%s [switches] addrs ...", invo_name
);
101 help (buf
, switches
);
105 if (!(form
= *argp
++) || *form
== '-')
106 adios (NULLCP
, "missing argument to %s", argp
[-2]);
110 if (!(format
= *argp
++) || *format
== '-')
111 adios (NULLCP
, "missing argument to %s", argp
[-2]);
116 if (!(cp
= *argp
++) || *cp
== '-')
117 adios (NULLCP
, "missing argument to %s", argp
[-2]);
129 adios (NULLCP
, "more than %d addresses", NADDRS
);
138 adios (NULLCP
, "usage: %s [switches] addrs ...", invo_name
);
140 nfs
= new_fs (form
, format
, FORMAT
);
142 if ((width
= sc_width ()) < WIDTH
/ 2)
148 fmt_norm
= normalize
;
149 (void) fmt_compile (nfs
, &fmt
);
150 dat
[0] = dat
[1] = dat
[2] = dat
[4] = 0;
153 for (addrp
= 0; addrs
[addrp
]; addrp
++)
154 status
+= process (addrs
[addrp
], width
, normalize
);
164 struct pqpair
*pq_next
;
168 static int process (arg
, length
, norm
)
175 char buffer
[WBUFSIZ
+ 1],
177 register struct comp
*cptr
;
178 register struct pqpair
*p
,
181 register struct mailname
*mp
;
183 (q
= &pq
) -> pq_next
= NULL
;
184 while (cp
= getname (arg
)) {
185 if ((p
= (struct pqpair
*) calloc ((unsigned) 1, sizeof *p
)) == NULL
)
186 adios (NULLCP
, "unable to allocate pqpair memory");
187 if ((mp
= getm (cp
, NULLCP
, 0, norm
, error
)) == NULL
) {
188 p
-> pq_text
= getcpy (cp
);
189 p
-> pq_error
= getcpy (error
);
193 p
-> pq_text
= getcpy (mp
-> m_text
);
196 q
= (q
-> pq_next
= p
);
199 for (p
= pq
.pq_next
; p
; p
= q
) {
200 FINDCOMP (cptr
, "text");
202 cptr
-> c_text
= p
-> pq_text
;
203 FINDCOMP (cptr
, "error");
205 cptr
-> c_text
= p
-> pq_error
;
207 (void) fmtscan (fmt
, buffer
, length
, dat
);
208 (void) fputs (buffer
, stdout
);
212 free (p
-> pq_error
);