]> diplodocus.org Git - nmh/blob - docs/historical/mh-6.8.5/uip/RCS/ali.c,v
sbr/mts.c: Delete mmdlm2; use same-valued mmdlm1 instead.
[nmh] / docs / historical / mh-6.8.5 / uip / RCS / ali.c,v
1 head 1.9;
2 access;
3 symbols;
4 locks; strict;
5 comment @ * @;
6
7
8 1.9
9 date 93.09.02.00.05.15; author jromine; state Exp;
10 branches;
11 next 1.8;
12
13 1.8
14 date 92.12.15.00.20.22; author jromine; state Exp;
15 branches;
16 next 1.7;
17
18 1.7
19 date 92.11.04.00.37.27; author jromine; state Exp;
20 branches;
21 next 1.6;
22
23 1.6
24 date 92.02.10.17.33.44; author jromine; state Exp;
25 branches;
26 next 1.5;
27
28 1.5
29 date 92.02.10.17.17.34; author jromine; state Exp;
30 branches;
31 next 1.4;
32
33 1.4
34 date 92.01.31.22.06.17; author jromine; state Exp;
35 branches;
36 next 1.3;
37
38 1.3
39 date 90.04.05.15.03.38; author sources; state Exp;
40 branches;
41 next 1.2;
42
43 1.2
44 date 90.03.16.15.27.13; author sources; state Exp;
45 branches;
46 next 1.1;
47
48 1.1
49 date 90.03.13.14.21.39; author sources; state Exp;
50 branches;
51 next ;
52
53
54 desc
55 @@
56
57
58 1.9
59 log
60 @read AliasFile (system default) in same order as post does
61 @
62 text
63 @/* ali.c - the new ali */
64 #ifndef lint
65 static char ident[] = "@@(#)$Id: ali.c,v 1.8 1992/12/15 00:20:22 jromine Exp jromine $";
66 #endif /* lint */
67
68 #include "../h/mh.h"
69 #include "../h/addrsbr.h"
70 #include "../h/aliasbr.h"
71 #include <stdio.h>
72 #ifdef LOCALE
73 #include <locale.h>
74 #endif
75
76
77 #define NVEC 50 /* maximum number of names */
78
79 /* \f */
80
81 static struct swit switches[] = {
82 #define ALIASW 0
83 "alias aliasfile", 0,
84 #define NALIASW 1
85 "noalias", -7,
86
87 #define LISTSW 2
88 "list", 0,
89 #define NLISTSW 3
90 "nolist", 0,
91
92 #define NORMSW 4
93 "normalize", 0,
94 #define NNORMSW 5
95 "nonormalize", 0,
96
97 #define USERSW 6
98 "user", 0,
99 #define NUSERSW 7
100 "nouser", 0,
101
102 #define HELPSW 8
103 "help", 4,
104
105 NULL, 0
106 };
107
108 /* \f */
109
110 static int pos = 1;
111
112 extern struct aka *akahead;
113
114 /* \f */
115
116 /* ARGSUSED */
117
118 main (argc, argv)
119 int argc;
120 char *argv[];
121 {
122 int i,
123 vecp = 0,
124 inverted = 0,
125 list = 0,
126 noalias = 0,
127 normalize = AD_NHST;
128 char *cp,
129 **ap,
130 **argp,
131 buf[100],
132 *vec[NVEC],
133 *arguments[MAXARGS];
134 struct aka *ak;
135
136 #ifdef LOCALE
137 setlocale(LC_ALL, "");
138 #endif
139 invo_name = r1bindex (argv[0], '/');
140 mts_init (invo_name);
141 if ((cp = m_find (invo_name)) != NULL) {
142 ap = brkstring (cp = getcpy (cp), " ", "\n");
143 ap = copyip (ap, arguments);
144 }
145 else
146 ap = arguments;
147 (void) copyip (argv + 1, ap);
148 argp = arguments;
149
150 /* \f */
151
152 while (cp = *argp++) {
153 if (*cp == '-')
154 switch (smatch (++cp, switches)) {
155 case AMBIGSW:
156 ambigsw (cp, switches);
157 done (1);
158 case UNKWNSW:
159 adios (NULLCP, "-%s unknown", cp);
160 case HELPSW:
161 (void) sprintf (buf, "%s [switches] aliases ...",
162 invo_name);
163 help (buf, switches);
164 done (1);
165
166 case ALIASW:
167 if (!(cp = *argp++) || *cp == '-')
168 adios (NULLCP, "missing argument to %s", argp[-2]);
169 if ((i = alias (cp)) != AK_OK)
170 adios (NULLCP, "aliasing error in %s - %s",
171 cp, akerror (i));
172 continue;
173 case NALIASW:
174 noalias++;
175 continue;
176
177 case LISTSW:
178 list++;
179 continue;
180 case NLISTSW:
181 list = 0;
182 continue;
183
184 case NORMSW:
185 normalize = AD_HOST;
186 continue;
187 case NNORMSW:
188 normalize = AD_NHST;
189 continue;
190
191 case USERSW:
192 inverted++;
193 continue;
194 case NUSERSW:
195 inverted = 0;
196 continue;
197 }
198 vec[vecp++] = cp;
199 }
200
201 if (!noalias) {
202 if (cp = m_find ("Aliasfile")) { /* allow Aliasfile: profile entry */
203 char *dp = NULL;
204
205 for (ap = brkstring(dp = getcpy(cp), " ", "\n"); ap && *ap; ap++)
206 if ((i = alias (*ap)) != AK_OK)
207 adios (NULLCP,
208 "aliasing error in %s - %s", *ap, akerror (i));
209 if (dp)
210 free(dp);
211 }
212 (void) alias (AliasFile);
213 }
214
215
216 /* \f */
217
218 if (vecp)
219 for (i = 0; i < vecp; i++)
220 if (inverted)
221 print_usr (vec[i], list, normalize);
222 else
223 print_aka (akvalue (vec[i]), list, 0);
224 else {
225 if (inverted)
226 adios (NULLCP,
227 "usage: %s -user addresses ... (you forgot the addresses)",
228 invo_name);
229
230 for (ak = akahead; ak; ak = ak -> ak_next) {
231 printf ("%s: ", ak -> ak_name);
232 pos += strlen (ak -> ak_name) + 1;
233 print_aka (akresult (ak), list, pos);
234 }
235 }
236
237 done (0);
238 }
239
240 /* \f */
241
242 print_aka (p, list, margin)
243 register char *p;
244 int list,
245 margin;
246 {
247 register char c;
248
249 if (p == NULL) {
250 printf ("<empty>\n");
251 return;
252 }
253
254 while (c = *p++)
255 switch (c) {
256 case ',':
257 if (*p)
258 if (list)
259 printf ("\n%*s", margin, "");
260 else
261 if (pos >= 68) {
262 printf (",\n ");
263 pos = 2;
264 }
265 else {
266 printf (", ");
267 pos += 2;
268 }
269
270 case 0:
271 break;
272
273 default:
274 pos++;
275 (void) putchar (c);
276 }
277
278 (void) putchar ('\n');
279 pos = 1;
280 }
281
282 /* \f */
283
284 print_usr (s, list, norm)
285 register char *s;
286 int list,
287 norm;
288 {
289 register char *cp,
290 *pp,
291 *vp;
292 register struct aka *ak;
293 register struct mailname *mp,
294 *np;
295
296 if ((pp = getname (s)) == NULL)
297 adios (NULLCP, "no address in \"%s\"", s);
298 if ((mp = getm (pp, NULLCP, 0, norm, NULLCP)) == NULL)
299 adios (NULLCP, "bad address \"%s\"", s);
300 while (getname (""))
301 continue;
302
303 vp = NULL;
304 for (ak = akahead; ak; ak = ak -> ak_next) {
305 pp = akresult (ak);
306 while (cp = getname (pp)) {
307 if ((np = getm (cp, NULLCP, 0, norm, NULLCP)) == NULL)
308 continue;
309 if (uleq (mp -> m_host, np -> m_host)
310 && uleq (mp -> m_mbox, np -> m_mbox)) {
311 vp = vp ? add (ak -> ak_name, add (",", vp))
312 : getcpy (ak -> ak_name);
313 mnfree (np);
314 while (getname (""))
315 continue;
316 break;
317 }
318 mnfree (np);
319 }
320 }
321 mnfree (mp);
322
323 #ifdef notdef
324 printf ("%s: ", s);
325 print_aka (vp ? vp : s, list, pos += strlen (s) + 1);
326 #else
327 print_aka (vp ? vp : s, list, 0);
328 #endif
329 if (vp)
330 free (vp);
331 }
332 @
333
334
335 1.8
336 log
337 @endif sugar
338 @
339 text
340 @d3 1
341 a3 1
342 static char ident[] = "@@(#)$Id: ali.c,v 1.7 1992/11/04 00:37:27 jromine Exp jromine $";
343 a139 1
344 (void) alias (AliasFile);
345 d150 1
346 @
347
348
349 1.7
350 log
351 @putenv -> m_putenv
352 @
353 text
354 @d3 2
355 a4 2
356 static char ident[] = "@@(#)$Id: ali.c,v 1.6 1992/02/10 17:33:44 jromine Exp jromine $";
357 #endif lint
358 @
359
360
361 1.6
362 log
363 @allow "Aliasfile" to be multiple files
364 @
365 text
366 @d3 1
367 a3 1
368 static char ident[] = "@@(#)$Id: ali.c,v 1.5 1992/02/10 17:17:34 jromine Exp jromine $";
369 d10 3
370 d74 3
371 @
372
373
374 1.5
375 log
376 @make -user more self-consistent -- don't output "arg: " before
377 expansion
378 @
379 text
380 @d3 1
381 a3 1
382 static char ident[] = "@@(#)$Id: ali.c,v 1.4 1992/01/31 22:06:17 jromine Exp jromine $";
383 d135 10
384 a144 3
385 if (cp = m_find ("Aliasfile")) /* allow Aliasfile: profile entry */
386 if ((i = alias (cp)) != AK_OK)
387 adios (NULLCP, "aliasing error in %s - %s", cp, akerror (i));
388 @
389
390
391 1.4
392 log
393 @kerberos
394 @
395 text
396 @d3 1
397 a3 1
398 static char ident[] = "@@(#)$Id: ali.c,v 1.3 1990/04/05 15:03:38 sources Exp jromine $";
399 d151 2
400 a152 1
401 adios (NULLCP, "usage: %s addresses ... (you forgot the addresses)",
402 d248 1
403 d251 3
404 @
405
406
407 1.3
408 log
409 @add ID
410 @
411 text
412 @d3 1
413 a3 1
414 static char ident[] = "@@(#)$Id:$";
415 d40 1
416 a40 1
417 NULL, NULL
418 d194 1
419 a194 1
420 case NULL:
421 @
422
423
424 1.2
425 log
426 @add "Aliasfile: file" profile entry (like -alias file)
427 @
428 text
429 @d2 3
430 @
431
432
433 1.1
434 log
435 @Initial revision
436 @
437 text
438 @d130 1
439 a130 1
440 if (!noalias)
441 d132 5
442 @