names.c (da52b4caaf187775f6b56a72c6b16e94ad728f7b) | names.c (6d8484b0d0191b66f9bfd0dfa89c06a29647f02a) |
---|---|
1/* 2 * Copyright (c) 1980, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 37 unchanged lines hidden (view full) --- 46#include "extern.h" 47 48/* 49 * Allocate a single element of a name list, 50 * initialize its name field to the passed 51 * name and return it. 52 */ 53struct name * | 1/* 2 * Copyright (c) 1980, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 37 unchanged lines hidden (view full) --- 46#include "extern.h" 47 48/* 49 * Allocate a single element of a name list, 50 * initialize its name field to the passed 51 * name and return it. 52 */ 53struct name * |
54nalloc(str, ntype) 55 char str[]; 56 int ntype; | 54nalloc(char str[], int ntype) |
57{ 58 struct name *np; 59 60 np = (struct name *)salloc(sizeof(*np)); 61 np->n_flink = NULL; 62 np->n_blink = NULL; 63 np->n_type = ntype; 64 np->n_name = savestr(str); 65 return (np); 66} 67 68/* 69 * Find the tail of a list and return it. 70 */ 71struct name * | 55{ 56 struct name *np; 57 58 np = (struct name *)salloc(sizeof(*np)); 59 np->n_flink = NULL; 60 np->n_blink = NULL; 61 np->n_type = ntype; 62 np->n_name = savestr(str); 63 return (np); 64} 65 66/* 67 * Find the tail of a list and return it. 68 */ 69struct name * |
72tailof(name) 73 struct name *name; | 70tailof(struct name *name) |
74{ 75 struct name *np; 76 77 np = name; 78 if (np == NULL) 79 return (NULL); 80 while (np->n_flink != NULL) 81 np = np->n_flink; 82 return (np); 83} 84 85/* 86 * Extract a list of names from a line, 87 * and make a list of names from it. 88 * Return the list or NULL if none found. 89 */ 90struct name * | 71{ 72 struct name *np; 73 74 np = name; 75 if (np == NULL) 76 return (NULL); 77 while (np->n_flink != NULL) 78 np = np->n_flink; 79 return (np); 80} 81 82/* 83 * Extract a list of names from a line, 84 * and make a list of names from it. 85 * Return the list or NULL if none found. 86 */ 87struct name * |
91extract(line, ntype) 92 char line[]; 93 int ntype; | 88extract(char line[], int ntype) |
94{ 95 char *cp, *nbuf; 96 struct name *top, *np, *t; 97 98 if (line == NULL || *line == '\0') 99 return (NULL); 100 if ((nbuf = malloc(strlen(line) + 1)) == NULL) 101 err(1, "Out of memory"); --- 12 unchanged lines hidden (view full) --- 114 (void)free(nbuf); 115 return (top); 116} 117 118/* 119 * Turn a list of names into a string of the same names. 120 */ 121char * | 89{ 90 char *cp, *nbuf; 91 struct name *top, *np, *t; 92 93 if (line == NULL || *line == '\0') 94 return (NULL); 95 if ((nbuf = malloc(strlen(line) + 1)) == NULL) 96 err(1, "Out of memory"); --- 12 unchanged lines hidden (view full) --- 109 (void)free(nbuf); 110 return (top); 111} 112 113/* 114 * Turn a list of names into a string of the same names. 115 */ 116char * |
122detract(np, ntype) 123 struct name *np; 124 int ntype; | 117detract(struct name *np, int ntype) |
125{ 126 int s, comma; 127 char *cp, *top; 128 struct name *p; 129 130 comma = ntype & GCOMMA; 131 if (np == NULL) 132 return (NULL); --- 27 unchanged lines hidden (view full) --- 160 return (top); 161} 162 163/* 164 * Grab a single word (liberal word) 165 * Throw away things between ()'s, and take anything between <>. 166 */ 167char * | 118{ 119 int s, comma; 120 char *cp, *top; 121 struct name *p; 122 123 comma = ntype & GCOMMA; 124 if (np == NULL) 125 return (NULL); --- 27 unchanged lines hidden (view full) --- 153 return (top); 154} 155 156/* 157 * Grab a single word (liberal word) 158 * Throw away things between ()'s, and take anything between <>. 159 */ 160char * |
168yankword(ap, wbuf) 169 char *ap, wbuf[]; | 161yankword(char *ap, char wbuf[]) |
170{ 171 char *cp, *cp2; 172 173 cp = ap; 174 for (;;) { 175 if (*cp == '\0') 176 return (NULL); 177 if (*cp == '(') { --- 28 unchanged lines hidden (view full) --- 206} 207 208/* 209 * Grab a single login name (liberal word) 210 * Throw away things between ()'s, take anything between <>, 211 * and look for words before metacharacters %, @, !. 212 */ 213char * | 162{ 163 char *cp, *cp2; 164 165 cp = ap; 166 for (;;) { 167 if (*cp == '\0') 168 return (NULL); 169 if (*cp == '(') { --- 28 unchanged lines hidden (view full) --- 198} 199 200/* 201 * Grab a single login name (liberal word) 202 * Throw away things between ()'s, take anything between <>, 203 * and look for words before metacharacters %, @, !. 204 */ 205char * |
214yanklogin(ap, wbuf) 215 char *ap, wbuf[]; | 206yanklogin(char *ap, char wbuf[]) |
216{ 217 char *cp, *cp2, *cp_temp; 218 int n; 219 220 cp = ap; 221 for (;;) { 222 if (*cp == '\0') 223 return (NULL); --- 58 unchanged lines hidden (view full) --- 282 * For each recipient in the passed name list with a / 283 * in the name, append the message to the end of the named file 284 * and remove him from the recipient list. 285 * 286 * Recipients whose name begins with | are piped through the given 287 * program and removed. 288 */ 289struct name * | 207{ 208 char *cp, *cp2, *cp_temp; 209 int n; 210 211 cp = ap; 212 for (;;) { 213 if (*cp == '\0') 214 return (NULL); --- 58 unchanged lines hidden (view full) --- 273 * For each recipient in the passed name list with a / 274 * in the name, append the message to the end of the named file 275 * and remove him from the recipient list. 276 * 277 * Recipients whose name begins with | are piped through the given 278 * program and removed. 279 */ 280struct name * |
290outof(names, fo, hp) 291 struct name *names; 292 FILE *fo; 293 struct header *hp; | 281outof(struct name *names, FILE *fo, struct header *hp) |
294{ 295 int c, ispipe; 296 struct name *np, *top; 297 time_t now; 298 char *date, *fname; 299 FILE *fout, *fin; 300 301 top = names; --- 133 unchanged lines hidden (view full) --- 435} 436 437/* 438 * Determine if the passed address is a local "send to file" address. 439 * If any of the network metacharacters precedes any slashes, it can't 440 * be a filename. We cheat with .'s to allow path names like ./... 441 */ 442int | 282{ 283 int c, ispipe; 284 struct name *np, *top; 285 time_t now; 286 char *date, *fname; 287 FILE *fout, *fin; 288 289 top = names; --- 133 unchanged lines hidden (view full) --- 423} 424 425/* 426 * Determine if the passed address is a local "send to file" address. 427 * If any of the network metacharacters precedes any slashes, it can't 428 * be a filename. We cheat with .'s to allow path names like ./... 429 */ 430int |
443isfileaddr(name) 444 char *name; | 431isfileaddr(char *name) |
445{ 446 char *cp; 447 448 if (*name == '+') 449 return (1); 450 for (cp = name; *cp != '\0'; cp++) { 451 if (*cp == '!' || *cp == '%' || *cp == '@') 452 return (0); --- 6 unchanged lines hidden (view full) --- 459/* 460 * Map all of the aliased users in the invoker's mailrc 461 * file and insert them into the list. 462 * Changed after all these months of service to recursively 463 * expand names (2/14/80). 464 */ 465 466struct name * | 432{ 433 char *cp; 434 435 if (*name == '+') 436 return (1); 437 for (cp = name; *cp != '\0'; cp++) { 438 if (*cp == '!' || *cp == '%' || *cp == '@') 439 return (0); --- 6 unchanged lines hidden (view full) --- 446/* 447 * Map all of the aliased users in the invoker's mailrc 448 * file and insert them into the list. 449 * Changed after all these months of service to recursively 450 * expand names (2/14/80). 451 */ 452 453struct name * |
467usermap(names) 468 struct name *names; | 454usermap(struct name *names) |
469{ 470 struct name *new, *np, *cp; 471 struct grouphead *gh; 472 int metoo; 473 474 new = NULL; 475 np = names; 476 metoo = (value("metoo") != NULL); --- 17 unchanged lines hidden (view full) --- 494 495/* 496 * Recursively expand a group name. We limit the expansion to some 497 * fixed level to keep things from going haywire. 498 * Direct recursion is not expanded for convenience. 499 */ 500 501struct name * | 455{ 456 struct name *new, *np, *cp; 457 struct grouphead *gh; 458 int metoo; 459 460 new = NULL; 461 np = names; 462 metoo = (value("metoo") != NULL); --- 17 unchanged lines hidden (view full) --- 480 481/* 482 * Recursively expand a group name. We limit the expansion to some 483 * fixed level to keep things from going haywire. 484 * Direct recursion is not expanded for convenience. 485 */ 486 487struct name * |
502gexpand(nlist, gh, metoo, ntype) 503 struct name *nlist; 504 struct grouphead *gh; 505 int metoo, ntype; | 488gexpand(struct name *nlist, struct grouphead *gh, int metoo, int ntype) |
506{ 507 struct group *gp; 508 struct grouphead *ngh; 509 struct name *np; 510 static int depth; 511 char *cp; 512 513 if (depth > MAXEXP) { --- 27 unchanged lines hidden (view full) --- 541 depth--; 542 return (nlist); 543} 544 545/* 546 * Concatenate the two passed name lists, return the result. 547 */ 548struct name * | 489{ 490 struct group *gp; 491 struct grouphead *ngh; 492 struct name *np; 493 static int depth; 494 char *cp; 495 496 if (depth > MAXEXP) { --- 27 unchanged lines hidden (view full) --- 524 depth--; 525 return (nlist); 526} 527 528/* 529 * Concatenate the two passed name lists, return the result. 530 */ 531struct name * |
549cat(n1, n2) 550 struct name *n1, *n2; | 532cat(struct name *n1, struct name *n2) |
551{ 552 struct name *tail; 553 554 if (n1 == NULL) 555 return (n2); 556 if (n2 == NULL) 557 return (n1); 558 tail = tailof(n1); 559 tail->n_flink = n2; 560 n2->n_blink = tail; 561 return (n1); 562} 563 564/* 565 * Unpack the name list onto a vector of strings. 566 * Return an error if the name list won't fit. 567 */ 568char ** | 533{ 534 struct name *tail; 535 536 if (n1 == NULL) 537 return (n2); 538 if (n2 == NULL) 539 return (n1); 540 tail = tailof(n1); 541 tail->n_flink = n2; 542 n2->n_blink = tail; 543 return (n1); 544} 545 546/* 547 * Unpack the name list onto a vector of strings. 548 * Return an error if the name list won't fit. 549 */ 550char ** |
569unpack(np) 570 struct name *np; | 551unpack(struct name *np) |
571{ 572 char **ap, **top; 573 struct name *n; 574 int t, extra, metoo, verbose; 575 576 n = np; 577 if ((t = count(n)) == 0) 578 errx(1, "No names to unpack"); --- 27 unchanged lines hidden (view full) --- 606} 607 608/* 609 * Remove all of the duplicates from the passed name list by 610 * insertion sorting them, then checking for dups. 611 * Return the head of the new list. 612 */ 613struct name * | 552{ 553 char **ap, **top; 554 struct name *n; 555 int t, extra, metoo, verbose; 556 557 n = np; 558 if ((t = count(n)) == 0) 559 errx(1, "No names to unpack"); --- 27 unchanged lines hidden (view full) --- 587} 588 589/* 590 * Remove all of the duplicates from the passed name list by 591 * insertion sorting them, then checking for dups. 592 * Return the head of the new list. 593 */ 594struct name * |
614elide(names) 615 struct name *names; | 595elide(struct name *names) |
616{ 617 struct name *np, *t, *new; 618 struct name *x; 619 620 if (names == NULL) 621 return (NULL); 622 new = names; 623 np = names; --- 81 unchanged lines hidden (view full) --- 705 return (new); 706} 707 708/* 709 * Put another node onto a list of names and return 710 * the list. 711 */ 712struct name * | 596{ 597 struct name *np, *t, *new; 598 struct name *x; 599 600 if (names == NULL) 601 return (NULL); 602 new = names; 603 np = names; --- 81 unchanged lines hidden (view full) --- 685 return (new); 686} 687 688/* 689 * Put another node onto a list of names and return 690 * the list. 691 */ 692struct name * |
713put(list, node) 714 struct name *list, *node; | 693put(struct name *list, struct name *node) |
715{ 716 node->n_flink = list; 717 node->n_blink = NULL; 718 if (list != NULL) 719 list->n_blink = node; 720 return (node); 721} 722 723/* 724 * Determine the number of undeleted elements in 725 * a name list and return it. 726 */ 727int | 694{ 695 node->n_flink = list; 696 node->n_blink = NULL; 697 if (list != NULL) 698 list->n_blink = node; 699 return (node); 700} 701 702/* 703 * Determine the number of undeleted elements in 704 * a name list and return it. 705 */ 706int |
728count(np) 729 struct name *np; | 707count(struct name *np) |
730{ 731 int c; 732 733 for (c = 0; np != NULL; np = np->n_flink) 734 if ((np->n_type & GDEL) == 0) 735 c++; 736 return (c); 737} 738 739/* 740 * Delete the given name from a namelist. 741 */ 742struct name * | 708{ 709 int c; 710 711 for (c = 0; np != NULL; np = np->n_flink) 712 if ((np->n_type & GDEL) == 0) 713 c++; 714 return (c); 715} 716 717/* 718 * Delete the given name from a namelist. 719 */ 720struct name * |
743delname(np, name) 744 struct name *np; 745 char name[]; | 721delname(struct name *np, char name[]) |
746{ 747 struct name *p; 748 749 for (p = np; p != NULL; p = p->n_flink) 750 if (strcasecmp(p->n_name, name) == 0) { 751 if (p->n_blink == NULL) { 752 if (p->n_flink != NULL) 753 p->n_flink->n_blink = NULL; --- 13 unchanged lines hidden (view full) --- 767 768/* 769 * Pretty print a name list 770 * Uncomment it if you need it. 771 */ 772 773/* 774void | 722{ 723 struct name *p; 724 725 for (p = np; p != NULL; p = p->n_flink) 726 if (strcasecmp(p->n_name, name) == 0) { 727 if (p->n_blink == NULL) { 728 if (p->n_flink != NULL) 729 p->n_flink->n_blink = NULL; --- 13 unchanged lines hidden (view full) --- 743 744/* 745 * Pretty print a name list 746 * Uncomment it if you need it. 747 */ 748 749/* 750void |
775prettyprint(name) 776 struct name *name; | 751prettyprint(struct name *name) |
777{ 778 struct name *np; 779 780 np = name; 781 while (np != NULL) { 782 fprintf(stderr, "%s(%d) ", np->n_name, np->n_type); 783 np = np->n_flink; 784 } 785 fprintf(stderr, "\n"); 786} 787*/ | 752{ 753 struct name *np; 754 755 np = name; 756 while (np != NULL) { 757 fprintf(stderr, "%s(%d) ", np->n_name, np->n_type); 758 np = np->n_flink; 759 } 760 fprintf(stderr, "\n"); 761} 762*/ |