Print this page
5166 sendmail package should be replaceable
Reviewed by: Hans Rosenfeld <hans.rosenfeld@nexenta.com>
Reviewed by: Josef 'Jeff' Sipek <josef.sipek@nexenta.com>
Reviewed by: Toomas Soome <tsoome@me.com>
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/mailx/names.c
+++ new/usr/src/cmd/mailx/names.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License, Version 1.0 only
6 6 * (the "License"). You may not use this file except in compliance
7 7 * with the License.
8 8 *
9 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 10 * or http://www.opensolaris.org/os/licensing.
11 11 * See the License for the specific language governing permissions
12 12 * and limitations under the License.
13 13 *
14 14 * When distributing Covered Code, include this CDDL HEADER in each
15 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 16 * If applicable, add the following below this CDDL HEADER, with the
17 17 * fields enclosed by brackets "[]" replaced with your own identifying
18 18 * information: Portions Copyright [yyyy] [name of copyright owner]
19 19 *
20 20 * CDDL HEADER END
21 21 */
22 22
23 23 /*
24 24 * Copyright 2001 Sun Microsystems, Inc. All rights reserved.
25 25 * Use is subject to license terms.
26 26 */
27 27
28 28 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
29 29 /* All Rights Reserved */
30 30
↓ open down ↓ |
30 lines elided |
↑ open up ↑ |
31 31 /*
32 32 * University Copyright- Copyright (c) 1982, 1986, 1988
33 33 * The Regents of the University of California
34 34 * All Rights Reserved
35 35 *
36 36 * University Acknowledgment- Portions of this document are derived from
37 37 * software developed by the University of California, Berkeley, and its
38 38 * contributors.
39 39 */
40 40
41 -#pragma ident "%Z%%M% %I% %E% SMI"
42 -
43 41 /*
44 42 * mailx -- a modified version of a University of California at Berkeley
45 43 * mail program
46 44 *
47 45 * Handle name lists.
48 46 */
49 47
50 48 #include "rcv.h"
51 49 #include <locale.h>
52 50
53 51 static struct name *nalloc(char str[]);
54 52 static int isfileaddr(char *name);
55 53 static int lengthof(struct name *name);
56 -static struct name *gexpand(struct name *nlist, struct grouphead *gh, int metoo, int arg_ntype);
57 -static char *norm(register char *user, register char *ubuf, int nbangs);
54 +static struct name *gexpand(struct name *nlist, struct grouphead *gh,
55 + int metoo, int arg_ntype);
56 +static char *norm(register char *user, register char *ubuf,
57 + int nbangs);
58 58 static struct name *put(struct name *list, struct name *node);
59 59
60 60 /*
61 61 * Allocate a single element of a name list,
62 62 * initialize its name field to the passed
63 63 * name and return it.
64 64 */
65 65
66 66 static struct name *
67 67 nalloc(char str[])
68 68 {
69 69 register struct name *np;
70 70
71 - np = (struct name *) salloc(sizeof *np);
71 + np = (struct name *)salloc(sizeof (*np));
72 72 np->n_flink = NIL;
73 73 np->n_blink = NIL;
74 74 np->n_type = -1;
75 75 np->n_full = savestr(str);
76 76 np->n_name = skin(np->n_full);
77 - return(np);
77 + return (np);
78 78 }
79 79
80 80 /*
81 81 * Find the tail of a list and return it.
82 82 */
83 83
84 84 struct name *
85 85 tailof(struct name *name)
86 86 {
87 87 register struct name *np;
88 88
89 89 np = name;
90 90 if (np == NIL)
91 - return(NIL);
91 + return (NIL);
92 92 while (np->n_flink != NIL)
93 93 np = np->n_flink;
94 - return(np);
94 + return (np);
95 95 }
96 96
97 97 /*
98 98 * Extract a list of names from a line,
99 99 * and make a list of names from it.
100 100 * Return the list or NIL if none found.
101 101 */
102 102
103 103 struct name *
104 104 extract(char line[], int arg_ntype)
105 105 {
106 106 short ntype = (short)arg_ntype;
107 107 register char *cp;
108 108 register struct name *top, *np, *t;
109 109 char nbuf[BUFSIZ], abuf[BUFSIZ];
110 110 int comma;
111 111
112 112 if (line == NOSTR || strlen(line) == 0)
113 - return(NIL);
113 + return (NIL);
114 114 comma = docomma(line);
115 115 top = NIL;
116 116 np = NIL;
117 117 cp = line;
118 118 while ((cp = yankword(cp, nbuf, sizeof (nbuf), comma)) != NOSTR) {
119 119 if (np != NIL && equal(nbuf, "at")) {
120 120 nstrcpy(abuf, sizeof (abuf), nbuf);
121 121 if ((cp = yankword(cp, nbuf, sizeof (nbuf),
122 - comma)) == NOSTR) {
122 + comma)) == NOSTR) {
123 123 nstrcpy(nbuf, sizeof (nbuf), abuf);
124 124 goto normal;
125 125 }
126 126 snprintf(abuf, sizeof (abuf), "%s@%s", np->n_name,
127 - nbuf);
127 + nbuf);
128 128 np->n_name = savestr(abuf);
129 129 continue;
130 130 }
131 131 normal:
132 132 t = nalloc(nbuf);
133 133 t->n_type = ntype;
134 134 if (top == NIL)
135 135 top = t;
136 136 else
137 137 np->n_flink = t;
138 138 t->n_blink = np;
139 139 np = t;
140 140 }
141 - return(top);
141 + return (top);
142 142 }
143 143
144 144 /*
145 145 * Turn a list of names into a string of the same names.
146 146 */
147 147
148 148 char *
149 149 detract(register struct name *np, int ntype)
150 150 {
151 151 register int s;
152 152 register char *cp, *top;
153 153 register struct name *p;
154 154
155 155 if (np == NIL)
156 - return(NOSTR);
156 + return (NOSTR);
157 157 s = 0;
158 158 for (p = np; p != NIL; p = p->n_flink) {
159 - if ((ntype && (p->n_type & GMASK) != ntype)
160 - || (p->n_type & GDEL))
159 + if ((ntype && (p->n_type & GMASK) != ntype) ||
160 + (p->n_type & GDEL))
161 161 continue;
162 162 s += strlen(p->n_full) + 2;
163 163 }
164 164 if (s == 0)
165 - return(NOSTR);
165 + return (NOSTR);
166 166 top = (char *)salloc((unsigned)(++s));
167 167 cp = top;
168 168 for (p = np; p != NIL; p = p->n_flink) {
169 - if ((ntype && (p->n_type & GMASK) != ntype)
170 - || (p->n_type & GDEL))
169 + if ((ntype && (p->n_type & GMASK) != ntype) ||
170 + (p->n_type & GDEL))
171 171 continue;
172 172 cp = copy(p->n_full, cp);
173 173 *cp++ = ',';
174 174 *cp++ = ' ';
175 175 }
176 176 *cp = 0;
177 - return(top);
177 + return (top);
178 178 }
179 179
180 180 struct name *
181 181 outpre(struct name *to)
182 182 {
183 183 register struct name *np;
184 184
185 185 for (np = to; np; np = np->n_flink)
186 186 if (isfileaddr(np->n_name))
187 187 np->n_type |= GDEL;
188 - return to;
188 + return (to);
189 189 }
190 190
191 191 /*
192 192 * For each recipient in the passed name list with a /
193 193 * in the name, append the message to the end of the named file
194 194 * and remove him from the recipient list.
195 195 *
196 196 * Recipients whose name begins with | are piped through the given
197 197 * program and removed.
198 198 */
199 199
↓ open down ↓ |
1 lines elided |
↑ open up ↑ |
200 200 int
201 201 outof(struct name *names, FILE *fo)
202 202 {
203 203 register int c;
204 204 register struct name *np;
205 205 time_t now;
206 206 char *date, *fname, *shell;
207 207 FILE *fout, *fin;
208 208 int ispipe;
209 209 int nout = 0;
210 - int fd = 0;
210 + int fd = 0;
211 211 #ifdef preSVr4
212 212 char line[BUFSIZ];
213 213 #endif
214 214
215 215 for (np = names; np != NIL; np = np->n_flink) {
216 216 if (!isfileaddr(np->n_name) && np->n_name[0] != '|')
217 217 continue;
218 218 nout++;
219 219 ispipe = np->n_name[0] == '|';
220 220 if (ispipe)
221 221 fname = np->n_name+1;
↓ open down ↓ |
1 lines elided |
↑ open up ↑ |
222 222 else
223 223 fname = safeexpand(np->n_name);
224 224
225 225 /*
226 226 * See if we have copied the complete message out yet.
227 227 * If not, do so.
228 228 */
229 229
230 230 if (image < 0) {
231 231 fd = open(tempEdit, O_CREAT|O_EXCL|O_APPEND|O_WRONLY,
232 - 0600);
232 + 0600);
233 233 if ((fd < 0) && (errno == EEXIST)) {
234 234 if ((fd = open(tempEdit, O_APPEND|O_WRONLY,
235 - 0600)) < 0) {
235 + 0600)) < 0) {
236 236 perror(tempEdit);
237 237 senderr++;
238 238 goto cant;
239 239 }
240 240 }
241 241 if ((fout = fdopen(fd, "a")) == NULL) {
242 242 perror(tempEdit);
243 243 senderr++;
244 244 goto cant;
245 245 }
246 246 image = open(tempEdit, O_RDWR);
247 247 unlink(tempEdit);
248 248 if (image < 0) {
249 249 perror(tempEdit);
250 250 senderr++;
251 251 goto cant;
252 252 } else {
253 253 rewind(fo);
254 254 time(&now);
255 255 date = ctime(&now);
256 256 fprintf(fout, "From %s %s", myname, date);
257 257 while ((c = getc(fo)) != EOF)
258 258 putc(c, fout);
259 259 rewind(fo);
260 260 fflush(fout);
261 261 if (fferror(fout))
262 262 perror(tempEdit);
263 263 fclose(fout);
264 264 }
265 265 }
266 266
267 267 /*
268 268 * Now either copy "image" to the desired file
269 269 * or give it as the standard input to the desired
270 270 * program as appropriate.
271 271 */
272 272
273 273 if (ispipe) {
274 274 wait((int *)NULL);
↓ open down ↓ |
29 lines elided |
↑ open up ↑ |
275 275 switch (fork()) {
276 276 case 0:
277 277 sigchild();
278 278 sigset(SIGHUP, SIG_IGN);
279 279 sigset(SIGINT, SIG_IGN);
280 280 sigset(SIGQUIT, SIG_IGN);
281 281 close(0);
282 282 dup(image);
283 283 close(image);
284 284 lseek(0, 0L, 0);
285 - if ((shell = value("SHELL")) == NOSTR || *shell=='\0')
285 + if ((shell = value("SHELL")) == NOSTR ||
286 + *shell == '\0')
286 287 shell = SHELL;
287 - (void) execlp(shell, shell, "-c", fname, (char *)0);
288 + (void) execlp(shell, shell, "-c", fname,
289 + (char *)0);
288 290 perror(shell);
289 291 exit(1);
290 292 break;
291 293
292 294 case (pid_t)-1:
293 295 perror("fork");
294 296 senderr++;
295 297 goto cant;
296 298 }
297 - }
298 - else {
299 + } else {
299 300 if ((fout = fopen(fname, "a")) == NULL) {
300 301 perror(fname);
301 302 senderr++;
302 303 goto cant;
303 304 }
304 305 fin = Fdopen(image, "r");
305 306 if (fin == NULL) {
306 307 fprintf(stderr,
307 308 gettext("Can't reopen image\n"));
308 309 fclose(fout);
309 310 senderr++;
310 311 goto cant;
311 312 }
312 313 rewind(fin);
313 314 #ifdef preSVr4
314 315 putc(getc(fin), fout);
315 - while (fgets(line, sizeof line, fin)) {
316 - if (!strncmp(line, "From ", 5))
316 + while (fgets(line, sizeof (line), fin)) {
317 + if (strncmp(line, "From ", 5) == 0)
317 318 putc('>', fout);
318 319 fputs(line, fout);
319 320 }
320 321 #else
321 322 while ((c = getc(fin)) != EOF)
322 323 putc(c, fout);
323 324 #endif
324 325 putc('\n', fout);
325 326 fflush(fout);
326 327 if (fferror(fout))
327 328 senderr++, perror(fname);
328 329 fclose(fout);
329 330 fclose(fin);
330 331 }
331 332 cant:
332 333 /*
333 334 * In days of old we removed the entry from the
334 335 * the list; now for sake of header expansion
335 336 * we leave it in and mark it as deleted.
336 337 */
337 338
338 339 #ifdef CRAZYWOW
339 340 {
340 341 register struct name *t, *x;
341 342
342 343 if (np == top) {
343 344 top = np->n_flink;
344 345 if (top != NIL)
345 346 top->n_blink = NIL;
346 347 np = top;
347 348 continue;
348 349 }
349 350 x = np->n_blink;
350 351 t = np->n_flink;
351 352 x->n_flink = t;
352 353 if (t != NIL)
353 354 t->n_blink = x;
↓ open down ↓ |
27 lines elided |
↑ open up ↑ |
354 355 np = t;
355 356 }
356 357 #endif
357 358
358 359 np->n_type |= GDEL;
359 360 }
360 361 if (image >= 0) {
361 362 close(image);
362 363 image = -1;
363 364 }
364 - return(nout);
365 + return (nout);
365 366 }
366 367
367 368 /*
368 369 * Determine if the passed address is a local "send to file" address.
369 370 * If any of the network metacharacters precedes any slashes, it can't
370 371 * be a filename. We cheat with .'s to allow path names like ./...
371 372 * If "fcc" has been unset, then short-circuit those tests, but not
372 373 * the +... test.
373 374 */
374 -static int
375 +static int
375 376 isfileaddr(char *name)
376 377 {
377 378 register char *cp;
378 379 char *fcc = value("fcc");
379 380
380 381 if (any('@', name))
381 - return(0);
382 + return (0);
382 383 if (*name == '+')
383 - return(1);
384 + return (1);
384 385 if (fcc == NOSTR)
385 - return(0);
386 + return (0);
386 387 for (cp = name; *cp; cp++) {
387 388 if (*cp == '.')
388 389 continue;
389 390 if (any(*cp, metanet))
390 - return(0);
391 + return (0);
391 392 if (*cp == '/')
392 - return(1);
393 + return (1);
393 394 }
394 - return(0);
395 + return (0);
395 396 }
396 397
397 398 /*
398 399 * Map all of the aliased users in the invoker's mailrc
399 400 * file and insert them into the list.
400 401 * Changed after all these months of service to recursively
401 402 * expand names (2/14/80).
402 403 */
403 404
404 405 struct name *
405 406 usermap(struct name *names)
406 407 {
407 408 register struct name *newnames, *np, *cp;
408 409 struct grouphead *gh;
409 410 register int metoo;
410 411
411 412 newnames = NIL;
412 413 np = names;
413 414 metoo = (value("metoo") != NOSTR);
414 415 while (np != NIL) {
415 416 if (np->n_name[0] == '\\') {
416 417 cp = np->n_flink;
417 418 newnames = put(newnames, np);
418 419 np = cp;
↓ open down ↓ |
14 lines elided |
↑ open up ↑ |
419 420 continue;
420 421 }
421 422 gh = findgroup(np->n_name);
422 423 cp = np->n_flink;
423 424 if (gh != NOGRP)
424 425 newnames = gexpand(newnames, gh, metoo, np->n_type);
425 426 else
426 427 newnames = put(newnames, np);
427 428 np = cp;
428 429 }
429 - return(newnames);
430 + return (newnames);
430 431 }
431 432
432 433 /*
433 434 * Recursively expand a group name. We limit the expansion to some
434 435 * fixed level to keep things from going haywire.
435 436 * Direct recursion is not expanded for convenience.
436 437 */
437 438
438 439 static struct name *
439 440 gexpand(struct name *nlist, struct grouphead *gh, int metoo, int arg_ntype)
440 441 {
↓ open down ↓ |
1 lines elided |
↑ open up ↑ |
441 442 short ntype = (short)arg_ntype;
442 443 struct mgroup *gp;
443 444 struct grouphead *ngh;
444 445 struct name *np;
445 446 static int depth;
446 447 register char *cp;
447 448
448 449 if (depth > MAXEXP) {
449 450 printf(gettext("Expanding alias to depth larger than %d\n"),
450 451 MAXEXP);
451 - return(nlist);
452 + return (nlist);
452 453 }
453 454 depth++;
454 455 for (gp = gh->g_list; gp != NOGE; gp = gp->ge_link) {
455 456 cp = gp->ge_name;
456 457 if (*cp == '\\')
457 458 goto quote;
458 459 if (strcmp(cp, gh->g_name) == 0)
459 460 goto quote;
460 461 if ((ngh = findgroup(cp)) != NOGRP) {
461 462 nlist = gexpand(nlist, ngh, metoo, ntype);
462 463 continue;
463 464 }
464 465 quote:
465 466 np = nalloc(cp);
466 467 np->n_type = ntype;
467 468 /*
468 469 * At this point should allow to expand
↓ open down ↓ |
7 lines elided |
↑ open up ↑ |
469 470 * to self if only person in group
470 471 */
471 472 if (gp == gh->g_list && gp->ge_link == NOGE)
472 473 goto skip;
473 474 if (!metoo && samebody(myname, gp->ge_name, FALSE))
474 475 np->n_type |= GDEL;
475 476 skip:
476 477 nlist = put(nlist, np);
477 478 }
478 479 depth--;
479 - return(nlist);
480 + return (nlist);
480 481 }
481 482
482 483 /*
483 484 * Normalize a network name for comparison purposes.
484 485 */
485 486 static char *
486 487 norm(register char *user, register char *ubuf, int nbangs)
487 488 {
488 489 register char *cp;
489 490 int inubuf = 0;
490 491
491 - while (*user++ == '!');
492 + while (*user++ == '!')
493 + ;
492 494 user--;
493 495 if (!strchr(user, '!')) {
494 496 snprintf(ubuf, BUFSIZ, "%s!%s", host, user);
495 497 user = ubuf;
496 498 inubuf++;
497 499 }
498 500 if (nbangs) {
499 501 cp = user + strlen(user);
500 502 while (nbangs--)
501 - while (cp > user && *--cp != '!');
503 + while (cp > user && *--cp != '!')
504 + ;
502 505 user = (cp > user) ? ++cp : cp;
503 506 /*
504 507 * Now strip off all Internet-type
505 508 * hosts.
506 509 */
507 510 if ((cp = strchr(user, '%')) == NOSTR)
508 511 cp = strchr(user, '@');
509 512 if (cp != NOSTR) {
510 513 if (!inubuf) {
511 514 strncpy(ubuf, user, cp - user);
512 515 ubuf[cp - user] = '\0';
513 516 user = ubuf;
514 517 } else
515 518 *cp = '\0';
516 519 }
517 520 }
518 - return user;
521 + return (user);
519 522 }
520 523
521 524 /*
522 525 * Implement allnet options.
523 526 */
524 -int
527 +int
525 528 samebody(register char *user, register char *addr, int fuzzy)
526 529 {
527 530 char ubuf[BUFSIZ], abuf[BUFSIZ];
528 531 char *allnet = value("allnet");
529 - int nbangs = allnet ? !strcmp(allnet, "uucp") ? 2 : 1 : 0;
532 + int nbangs = allnet ? (strcmp(allnet, "uucp") == 0) ? 2 : 1 : 0;
530 533
531 534 if (fuzzy && value("fuzzymatch")) {
532 535 int i;
533 536
534 537 (void) strlcpy(ubuf, user, BUFSIZ);
535 538 for (i = 0; ubuf[i]; i++)
536 539 ubuf[i] = tolower(ubuf[i]);
537 540 (void) strlcpy(abuf, addr, BUFSIZ);
538 541 for (i = 0; abuf[i]; i++)
539 542 abuf[i] = tolower(abuf[i]);
540 543 return (strstr(abuf, ubuf) != NOSTR);
541 544 }
542 545 user = norm(user, ubuf, nbangs);
543 546 addr = norm(addr, abuf, nbangs);
544 - return strcmp(user, addr) == 0;
547 + return (strcmp(user, addr) == 0);
545 548 }
546 549
547 550 /*
548 551 * Compute the length of the passed name list and
549 552 * return it.
550 553 */
551 -static int
554 +static int
552 555 lengthof(struct name *name)
553 556 {
554 557 register struct name *np;
555 558 register int c;
556 559
557 560 for (c = 0, np = name; np != NIL; c++, np = np->n_flink)
558 561 ;
559 - return(c);
562 + return (c);
560 563 }
561 564
562 565 /*
563 566 * Concatenate the two passed name lists, return the result.
564 567 */
565 568
566 569 struct name *
567 570 cat(struct name *n1, struct name *n2)
568 571 {
569 572 register struct name *tail;
570 573
571 574 if (n1 == NIL)
572 - return(n2);
575 + return (n2);
573 576 if (n2 == NIL)
574 - return(n1);
577 + return (n1);
575 578 tail = tailof(n1);
576 579 tail->n_flink = n2;
577 580 n2->n_blink = tail;
578 - return(n1);
581 + return (n1);
579 582 }
580 583
581 584 /*
582 585 * Unpack the name list onto a vector of strings.
583 586 * Return an error if the name list won't fit.
584 587 */
585 588
586 589 char **
587 590 unpack(struct name *np)
588 591 {
589 592 register char **ap, **top;
590 593 register struct name *n;
591 594 char hbuf[10];
↓ open down ↓ |
3 lines elided |
↑ open up ↑ |
592 595 int t, extra, metoo, verbose;
593 596
594 597 n = np;
595 598 if ((t = lengthof(n)) == 0)
596 599 panic("No names to unpack");
597 600
598 601 /*
599 602 * Compute the number of extra arguments we will need.
600 603 * We need at least 2 extra -- one for "mail" and one for
601 604 * the terminating 0 pointer.
602 - * Additional spots may be needed to pass along -r and -f to
605 + * Additional spots may be needed to pass along -r and -f to
603 606 * the host mailer.
604 607 */
605 608
606 609 extra = 2;
607 610
608 611 if (rflag != NOSTR)
609 612 extra += 2;
610 -#ifdef SENDMAIL
611 613 extra++;
612 614 metoo = value("metoo") != NOSTR;
613 615 if (metoo)
614 616 extra++;
615 617 verbose = value("verbose") != NOSTR;
616 618 if (verbose)
617 619 extra++;
618 620 if (hflag)
619 621 extra += 2;
620 -#endif /* SENDMAIL */
621 - top = (char **) salloc((t + extra) * sizeof (char *));
622 + top = (char **)salloc((t + extra) * sizeof (char *));
622 623 ap = top;
623 - *ap++ = "mail";
624 + *ap++ = "sendmail";
624 625 if (rflag != NOSTR) {
625 626 *ap++ = "-r";
626 627 *ap++ = rflag;
627 628 }
628 -#ifdef SENDMAIL
629 629 *ap++ = "-i";
630 630 if (metoo)
631 631 *ap++ = "-m";
632 632 if (verbose)
633 633 *ap++ = "-v";
634 634 if (hflag) {
635 635 *ap++ = "-h";
636 636 snprintf(hbuf, sizeof (hbuf), "%d", hflag);
637 637 *ap++ = savestr(hbuf);
638 638 }
639 -#endif /* SENDMAIL */
640 639 while (n != NIL) {
641 640 if (n->n_type & GDEL) {
642 641 n = n->n_flink;
643 642 continue;
644 643 }
645 644 *ap++ = n->n_name;
646 645 n = n->n_flink;
647 646 }
648 647 *ap = NOSTR;
649 - return(top);
648 + return (top);
650 649 }
651 650
652 651 /*
653 652 * See if the user named himself as a destination
654 653 * for outgoing mail. If so, set the global flag
655 654 * selfsent so that we avoid removing his mailbox.
656 655 */
657 656
658 -void
657 +void
659 658 mechk(struct name *names)
660 659 {
661 660 register struct name *np;
662 661
663 662 for (np = names; np != NIL; np = np->n_flink)
664 663 if ((np->n_type & GDEL) == 0 &&
665 664 samebody(np->n_name, myname, FALSE)) {
666 665 selfsent++;
667 666 return;
668 667 }
669 668 }
670 669
671 670 /*
672 671 * Remove all of the duplicates from the passed name list by
673 672 * insertion sorting them, then checking for dups.
↓ open down ↓ |
5 lines elided |
↑ open up ↑ |
674 673 * Return the head of the new list.
675 674 */
676 675
677 676 struct name *
678 677 elide(struct name *names)
679 678 {
680 679 register struct name *np, *t, *newnames;
681 680 struct name *x;
682 681
683 682 if (names == NIL)
684 - return(NIL);
683 + return (NIL);
685 684 newnames = names;
686 685 np = names;
687 686 np = np->n_flink;
688 687 if (np != NIL)
689 688 np->n_blink = NIL;
690 689 newnames->n_flink = NIL;
691 690 while (np != NIL) {
692 691 t = newnames;
693 692 while (strcmp(t->n_name, np->n_name) < 0) {
694 693 if (t->n_flink == NIL)
695 694 break;
696 695 t = t->n_flink;
697 696 }
698 697
699 698 /*
700 699 * If we ran out of t's, put the new entry after
701 700 * the current value of t.
702 701 */
703 702
704 703 if (strcmp(t->n_name, np->n_name) < 0) {
705 704 t->n_flink = np;
706 705 np->n_blink = t;
707 706 t = np;
708 707 np = np->n_flink;
709 708 t->n_flink = NIL;
710 709 continue;
711 710 }
712 711
713 712 /*
714 713 * Otherwise, put the new entry in front of the
715 714 * current t. If at the front of the list,
716 715 * the new guy becomes the new head of the list.
717 716 */
718 717
719 718 if (t == newnames) {
720 719 t = np;
721 720 np = np->n_flink;
722 721 t->n_flink = newnames;
723 722 newnames->n_blink = t;
724 723 t->n_blink = NIL;
725 724 newnames = t;
726 725 continue;
727 726 }
728 727
729 728 /*
730 729 * The normal case -- we are inserting into the
731 730 * middle of the list.
732 731 */
733 732
734 733 x = np;
735 734 np = np->n_flink;
736 735 x->n_flink = t;
737 736 x->n_blink = t->n_blink;
738 737 t->n_blink->n_flink = x;
739 738 t->n_blink = x;
740 739 }
741 740
742 741 /*
743 742 * Now the list headed up by new is sorted.
744 743 * Go through it and remove duplicates.
↓ open down ↓ |
50 lines elided |
↑ open up ↑ |
745 744 * Remember the best "type" among all the
746 745 * duplicates of a name.
747 746 */
748 747
749 748 np = newnames;
750 749 while (np != NIL) {
751 750 int type;
752 751
753 752 t = np;
754 753 type = np->n_type;
755 - while (t->n_flink!=NIL &&
754 + while (t->n_flink != NIL &&
756 755 strcmp(np->n_name, t->n_flink->n_name) == 0) {
757 756 t = t->n_flink;
758 757 /* "To" before "Cc" before "Bcc" */
759 758 if (t->n_type < type)
760 759 type = t->n_type;
761 760 }
762 761 if (t == np || t == NIL) {
763 762 np = np->n_flink;
764 763 continue;
765 764 }
766 765
767 766 /*
↓ open down ↓ |
2 lines elided |
↑ open up ↑ |
768 767 * Now t points to the last entry with the same name
769 768 * as np. Make np point beyond t.
770 769 */
771 770
772 771 np->n_flink = t->n_flink;
773 772 if (t->n_flink != NIL)
774 773 t->n_flink->n_blink = np;
775 774 np->n_type = type;
776 775 np = np->n_flink;
777 776 }
778 - return(newnames);
777 + return (newnames);
779 778 }
780 779
781 780 /*
782 781 * Put another node onto a list of names and return
783 782 * the list.
784 783 */
785 784
786 785 static struct name *
787 786 put(struct name *list, struct name *node)
788 787 {
789 788 node->n_flink = list;
790 789 node->n_blink = NIL;
791 790 if (list != NIL)
792 791 list->n_blink = node;
793 - return(node);
792 + return (node);
794 793 }
795 794
796 795
797 796 /*
798 797 * Delete the given name from a namelist.
799 798 */
800 799 struct name *
801 800 delname(register struct name *np, char name[])
802 801 {
803 802 register struct name *p;
804 803
805 804 for (p = np; p != NIL; p = p->n_flink)
806 805 if (samebody(name, p->n_name, FALSE)) {
807 806 if (p->n_blink == NIL) {
808 807 if (p->n_flink != NIL)
809 808 p->n_flink->n_blink = NIL;
810 809 np = p->n_flink;
↓ open down ↓ |
7 lines elided |
↑ open up ↑ |
811 810 continue;
812 811 }
813 812 if (p->n_flink == NIL) {
814 813 if (p->n_blink != NIL)
815 814 p->n_blink->n_flink = NIL;
816 815 continue;
817 816 }
818 817 p->n_blink->n_flink = p->n_flink;
819 818 p->n_flink->n_blink = p->n_blink;
820 819 }
821 - return(np);
820 + return (np);
822 821 }
823 822
824 823 /*
825 824 * Call the given routine on each element of the name
826 825 * list, replacing said value if need be.
827 826 */
828 827
829 -void
828 +void
830 829 mapf(register struct name *np, char *from)
831 830 {
832 831 register struct name *p;
833 832
834 833 if (debug) fprintf(stderr, "mapf %lx, %s\n", (long)np, from);
835 834 for (p = np; p != NIL; p = p->n_flink)
836 835 if ((p->n_type & GDEL) == 0) {
837 836 p->n_name = netmap(p->n_name, from);
838 837 p->n_full = splice(p->n_name, p->n_full);
839 838 }
840 839 if (debug) fprintf(stderr, "mapf %s done\n", from);
841 840 }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX