]> diplodocus.org Git - nmh/blob - docs/historical/mh-6.8.5/uip/RCS/ap.c,v
sbr/mts.c: Delete mmdlm2; use same-valued mmdlm1 instead.
[nmh] / docs / historical / mh-6.8.5 / uip / RCS / ap.c,v
1 head 1.7;
2 access;
3 symbols;
4 locks; strict;
5 comment @ * @;
6
7
8 1.7
9 date 92.12.15.00.20.22; author jromine; state Exp;
10 branches;
11 next 1.6;
12
13 1.6
14 date 92.11.04.00.38.40; author jromine; state Exp;
15 branches;
16 next 1.5;
17
18 1.5
19 date 92.02.05.07.26.30; author jromine; state Exp;
20 branches;
21 next 1.4;
22
23 1.4
24 date 92.01.31.22.07.10; author jromine; state Exp;
25 branches;
26 next 1.3;
27
28 1.3
29 date 90.04.05.15.00.32; author sources; state Exp;
30 branches;
31 next 1.2;
32
33 1.2
34 date 90.02.06.13.16.22; author sources; state Exp;
35 branches;
36 next 1.1;
37
38 1.1
39 date 90.02.06.13.16.10; author sources; state Exp;
40 branches;
41 next ;
42
43
44 desc
45 @@
46
47
48 1.7
49 log
50 @endif sugar
51 @
52 text
53 @/* ap.c - parse addresses 822-style */
54 #ifndef lint
55 static char ident[] = "@@(#)$Id: ap.c,v 1.6 1992/11/04 00:38:40 jromine Exp jromine $";
56 #endif /* lint */
57
58 #include "../h/mh.h"
59 #include "../h/addrsbr.h"
60 #include "../h/formatsbr.h"
61 #include <stdio.h>
62 #ifdef LOCALE
63 #include <locale.h>
64 #endif
65
66
67 #define NADDRS 100
68
69 #define WIDTH 78
70 #define WBUFSIZ BUFSIZ
71
72 #define FORMAT "%<{error}%{error}: %{text}%|%(putstr(proper{text}))%>"
73
74 /* \f */
75
76 static struct swit switches[] = {
77 #define FORMSW 0
78 "form formatfile", 0,
79 #define FMTSW 1
80 "format string", 5,
81
82 #define NORMSW 2
83 "normalize", 0,
84 #define NNORMSW 3
85 "nonormalize", 0,
86
87 #define WIDSW 4
88 "width columns", 0,
89
90 #define HELPSW 5
91 "help", 4,
92
93 NULL, 0
94 };
95
96 /* \f */
97
98 static struct format *fmt;
99
100 static int dat[5];
101
102 static int process();
103 /* \f */
104
105 /* ARGSUSED */
106
107 main (argc, argv)
108 int argc;
109 char **argv;
110 {
111 int addrp = 0,
112 normalize = AD_HOST,
113 width = 0,
114 status = 0;
115 char *cp,
116 *form = NULL,
117 *format = NULL,
118 *nfs,
119 buf[80],
120 **ap,
121 **argp,
122 *arguments[MAXARGS],
123 *addrs[NADDRS];
124
125 #ifdef LOCALE
126 setlocale(LC_ALL, "");
127 #endif
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);
133 }
134 else
135 ap = arguments;
136 (void) copyip (argv + 1, ap);
137 argp = arguments;
138
139 /* \f */
140
141 while (cp = *argp++) {
142 if (*cp == '-')
143 switch (smatch (++cp, switches)) {
144 case AMBIGSW:
145 ambigsw (cp, switches);
146 done (1);
147
148 case UNKWNSW:
149 adios (NULLCP, "-%s unknown", cp);
150
151 case HELPSW:
152 (void) sprintf (buf, "%s [switches] addrs ...", invo_name);
153 help (buf, switches);
154 done (1);
155
156 case FORMSW:
157 if (!(form = *argp++) || *form == '-')
158 adios (NULLCP, "missing argument to %s", argp[-2]);
159 format = NULL;
160 continue;
161 case FMTSW:
162 if (!(format = *argp++) || *format == '-')
163 adios (NULLCP, "missing argument to %s", argp[-2]);
164 form = NULL;
165 continue;
166
167 case WIDSW:
168 if (!(cp = *argp++) || *cp == '-')
169 adios (NULLCP, "missing argument to %s", argp[-2]);
170 width = atoi (cp);
171 continue;
172
173 case NORMSW:
174 normalize = AD_HOST;
175 continue;
176 case NNORMSW:
177 normalize = AD_NHST;
178 continue;
179 }
180 if (addrp > NADDRS)
181 adios (NULLCP, "more than %d addresses", NADDRS);
182 else
183 addrs[addrp++] = cp;
184 }
185 addrs[addrp] = NULL;
186
187 /* \f */
188
189 if (addrp == 0)
190 adios (NULLCP, "usage: %s [switches] addrs ...", invo_name);
191
192 nfs = new_fs (form, format, FORMAT);
193 if (width == 0) {
194 if ((width = sc_width ()) < WIDTH / 2)
195 width = WIDTH / 2;
196 width -= 2;
197 }
198 if (width > WBUFSIZ)
199 width = WBUFSIZ;
200 fmt_norm = normalize;
201 (void) fmt_compile (nfs, &fmt);
202 dat[0] = dat[1] = dat[2] = dat[4] = 0;
203 dat[3] = width;
204
205 for (addrp = 0; addrs[addrp]; addrp++)
206 status += process (addrs[addrp], width, normalize);
207
208 done (status);
209 }
210
211 /* \f */
212
213 struct pqpair {
214 char *pq_text;
215 char *pq_error;
216 struct pqpair *pq_next;
217 };
218
219
220 static int process (arg, length, norm)
221 register char *arg;
222 int length,
223 norm;
224 {
225 int status = 0;
226 register char *cp;
227 char buffer[WBUFSIZ + 1],
228 error[BUFSIZ];
229 register struct comp *cptr;
230 register struct pqpair *p,
231 *q;
232 struct pqpair pq;
233 register struct mailname *mp;
234
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);
242 status++;
243 }
244 else {
245 p -> pq_text = getcpy (mp -> m_text);
246 mnfree (mp);
247 }
248 q = (q -> pq_next = p);
249 }
250
251 for (p = pq.pq_next; p; p = q) {
252 FINDCOMP (cptr, "text");
253 if (cptr)
254 cptr -> c_text = p -> pq_text;
255 FINDCOMP (cptr, "error");
256 if (cptr)
257 cptr -> c_text = p -> pq_error;
258
259 (void) fmtscan (fmt, buffer, length, dat);
260 (void) fputs (buffer, stdout);
261
262 free (p -> pq_text);
263 if (p -> pq_error)
264 free (p -> pq_error);
265 q = p -> pq_next;
266 free ((char *) p);
267 }
268
269 return status;
270 }
271 @
272
273
274 1.6
275 log
276 @putenv -> m_putenv
277 @
278 text
279 @d3 2
280 a4 2
281 static char ident[] = "@@(#)$Id: ap.c,v 1.5 1992/02/05 07:26:30 jromine Exp jromine $";
282 #endif lint
283 @
284
285
286 1.5
287 log
288 @put unseen sequence in mh-format
289 @
290 text
291 @d3 1
292 a3 1
293 static char ident[] = "@@(#)$Id: ap.c,v 1.4 1992/01/31 22:07:10 jromine Exp jromine $";
294 d10 3
295 d73 3
296 @
297
298
299 1.4
300 log
301 @kerberos
302 @
303 text
304 @d3 1
305 a3 1
306 static char ident[] = "@@(#)$Id: ap.c,v 1.3 1990/04/05 15:00:32 sources Exp jromine $";
307 d45 1
308 a45 1
309 static int dat[4];
310 d144 1
311 a144 1
312 dat[0] = dat[1] = dat[2] = 0;
313 @
314
315
316 1.3
317 log
318 @add ID
319 @
320 text
321 @d3 1
322 a3 1
323 static char ident[] = "@@(#)$Id:$";
324 d38 1
325 a38 1
326 NULL, NULL
327 @
328
329
330 1.2
331 log
332 @ANSI Compilance
333 @
334 text
335 @d2 3
336 @
337
338
339 1.1
340 log
341 @Initial revision
342 @
343 text
344 @d44 1
345 @