Print this page
XXX Remove nawk(1)
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/ypcmd/multi.awk.sh
+++ new/usr/src/cmd/ypcmd/multi.awk.sh
1 -#!/usr/bin/nawk -f
1 +#!/usr/xpg4/bin/awk -f
2 2 #
3 3 # CDDL HEADER START
4 4 #
5 5 # The contents of this file are subject to the terms of the
6 6 # Common Development and Distribution License, Version 1.0 only
7 7 # (the "License"). You may not use this file except in compliance
8 8 # with the License.
9 9 #
10 10 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11 11 # or http://www.opensolaris.org/os/licensing.
12 12 # See the License for the specific language governing permissions
13 13 # and limitations under the License.
↓ open down ↓ |
2 lines elided |
↑ open up ↑ |
14 14 #
15 15 # When distributing Covered Code, include this CDDL HEADER in each
16 16 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17 17 # If applicable, add the following below this CDDL HEADER, with the
18 18 # fields enclosed by brackets "[]" replaced with your own identifying
19 19 # information: Portions Copyright [yyyy] [name of copyright owner]
20 20 #
21 21 # CDDL HEADER END
22 22 #
23 23 #
24 -#ident "%Z%%M% %I% %E% SMI"
25 -#
26 24 # Copyright (c) 1996, by Sun Microsystems, Inc.
27 25 # All rights reserved.
28 26 #
29 27 # Awk code to handle the creation of the YP_MULTI_ entries
30 28 # in the hosts.byname map. Called by multi directly.
31 29 #
32 30
33 31 {
34 32 # Here we loop through the list of hostnames
35 33 # doing two separate things...
36 34 # First, we're building a list of hostnames
37 35 # for the current IP address ($1).
38 36 # Second, if we've seen a name before then
39 37 # we add the current address ($1) to a list
40 38 # of address associated with this particular
41 39 # name ($i).
42 40 #
43 41 # Note, that we're pretty careful about keeping
44 42 # out duplicates (and this has a cost).
45 43
46 44 for (i = 2; i <= NF; i++) {
47 45 # Make the namelist for this address
48 46 if (namelist[$1] == "") {
49 47 namelist[$1] = $i;
50 48 } else if (namelist[$1] == $i) {
51 49 ;
52 50 } else if (index(namelist[$1], $i) == 0) {
53 51 namelist[$1] = namelist[$1] " " $i;
54 52 } else {
55 53 nf = 1;
56 54 numnames = split(namelist[$1], n);
57 55 for (j = 1; j <= numnames; j++) {
58 56 if (n[j] == $i) {
59 57 nf = 0;
60 58 break;
61 59 }
62 60 }
63 61 if (nf) {
64 62 namelist[$1] = namelist[$1] " " $i;
65 63 nf = 0;
66 64 }
67 65 }
68 66
69 67 # Do we have an address for this name?
70 68 # If not, and it's not already there, add it.
71 69 if (addr[$i] == "") {
72 70 addr[$i] = $1;
73 71 } else if (index(addr[$i], $1) == 0) {
74 72 addr[$i] = addr[$i] "," $1
75 73 }
76 74 }
77 75 }
78 76
79 77 END {
80 78 # There are now a bunch o addresses in the addr
81 79 # array that are actually lists. We go through
82 80 # all of them here and build a list of hostname
83 81 # aliases into the namelist array.
84 82 #
85 83 for (host in addr) {
86 84 if (index(addr[host], ",") == 0)
87 85 continue;
88 86 numaddr = split(addr[host], tmpaddr, ",");
89 87 for (i = 1; i <= numaddr; i++) {
90 88 numnames = split(namelist[tmpaddr[i]], tmpname);
91 89 for (j = 1; j <= numnames; j++) {
92 90 if (namelist[addr[host]] == "") {
93 91 namelist[addr[host]] = tmpname[j];
94 92 continue;
95 93 }
96 94 if (namelist[addr[host]] == tmpname[j]) {
97 95 continue;
98 96 }
99 97 if (index(namelist[addr[host]], tmpname[j]) == 0) {
100 98 namelist[addr[host]] = namelist[addr[host]] " " tmpname[j];
101 99 continue;
102 100 } else {
103 101 nf = 1;
104 102 for (k = 1; k <= numnames; k++) {
105 103 if (tmpname[j] == tmpname[k]) {
106 104 nf = 0;
107 105 break;
108 106 }
109 107 }
110 108 if (nf == 1) {
111 109 namelist[addr[host]] = namelist[addr[host]] " " tmpname[j];
112 110 nf = 1;
113 111 }
114 112 }
115 113 }
116 114 }
117 115 }
118 116
119 117 # Now do that funky output thang...
120 118 for (host in addr) {
121 119 if (index(addr[host], ",")) {
122 120 printf("YP_MULTI_");
123 121 }
124 122 printf("%s %s\t%s\n",
125 123 host, addr[host], namelist[addr[host]]);
126 124 }
127 125 }
↓ open down ↓ |
92 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX