xref: /titanic_52/usr/src/ucbcmd/whereis/whereis.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * Copyright 1990 Sun Microsystems, Inc.  All rights reserved.
3*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
4*7c478bd9Sstevel@tonic-gate  */
5*7c478bd9Sstevel@tonic-gate 
6*7c478bd9Sstevel@tonic-gate /*
7*7c478bd9Sstevel@tonic-gate  * Copyright (c) 1980 Regents of the University of California.
8*7c478bd9Sstevel@tonic-gate  * All rights reserved.  The Berkeley software License Agreement
9*7c478bd9Sstevel@tonic-gate  * specifies the terms and conditions for redistribution.
10*7c478bd9Sstevel@tonic-gate  */
11*7c478bd9Sstevel@tonic-gate 
12*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
13*7c478bd9Sstevel@tonic-gate 
14*7c478bd9Sstevel@tonic-gate 
15*7c478bd9Sstevel@tonic-gate #include <sys/param.h>
16*7c478bd9Sstevel@tonic-gate #include <dirent.h>
17*7c478bd9Sstevel@tonic-gate #include <stdio.h>
18*7c478bd9Sstevel@tonic-gate #include <ctype.h>
19*7c478bd9Sstevel@tonic-gate 
20*7c478bd9Sstevel@tonic-gate static char *bindirs[] = {
21*7c478bd9Sstevel@tonic-gate 	"/etc",
22*7c478bd9Sstevel@tonic-gate 	"/sbin",
23*7c478bd9Sstevel@tonic-gate 	"/usr/bin",
24*7c478bd9Sstevel@tonic-gate 	"/usr/ccs/bin",
25*7c478bd9Sstevel@tonic-gate 	"/usr/ccs/lib",
26*7c478bd9Sstevel@tonic-gate 	"/usr/lang",
27*7c478bd9Sstevel@tonic-gate 	"/usr/lbin",
28*7c478bd9Sstevel@tonic-gate 	"/usr/lib",
29*7c478bd9Sstevel@tonic-gate 	"/usr/sbin",
30*7c478bd9Sstevel@tonic-gate 	"/usr/ucb",
31*7c478bd9Sstevel@tonic-gate 	"/usr/ucblib",
32*7c478bd9Sstevel@tonic-gate 	"/usr/ucbinclude",
33*7c478bd9Sstevel@tonic-gate 	"/usr/games",
34*7c478bd9Sstevel@tonic-gate 	"/usr/local",
35*7c478bd9Sstevel@tonic-gate 	"/usr/local/bin",
36*7c478bd9Sstevel@tonic-gate 	"/usr/new",
37*7c478bd9Sstevel@tonic-gate 	"/usr/old",
38*7c478bd9Sstevel@tonic-gate 	"/usr/hosts",
39*7c478bd9Sstevel@tonic-gate 	"/usr/include",
40*7c478bd9Sstevel@tonic-gate 	"/usr/etc",
41*7c478bd9Sstevel@tonic-gate 	0
42*7c478bd9Sstevel@tonic-gate };
43*7c478bd9Sstevel@tonic-gate static char *mandirs[] = {
44*7c478bd9Sstevel@tonic-gate 	"/usr/man/man1",
45*7c478bd9Sstevel@tonic-gate 	"/usr/man/man1b",
46*7c478bd9Sstevel@tonic-gate 	"/usr/man/man1c",
47*7c478bd9Sstevel@tonic-gate 	"/usr/man/man1f",
48*7c478bd9Sstevel@tonic-gate 	"/usr/man/man1m",
49*7c478bd9Sstevel@tonic-gate 	"/usr/man/man1s",
50*7c478bd9Sstevel@tonic-gate 	"/usr/man/man2",
51*7c478bd9Sstevel@tonic-gate 	"/usr/man/man3",
52*7c478bd9Sstevel@tonic-gate 	"/usr/man/man3b",
53*7c478bd9Sstevel@tonic-gate 	"/usr/man/man3c",
54*7c478bd9Sstevel@tonic-gate 	"/usr/man/man3e",
55*7c478bd9Sstevel@tonic-gate 	"/usr/man/man3g",
56*7c478bd9Sstevel@tonic-gate 	"/usr/man/man3j",
57*7c478bd9Sstevel@tonic-gate 	"/usr/man/man3k",
58*7c478bd9Sstevel@tonic-gate 	"/usr/man/man3l",
59*7c478bd9Sstevel@tonic-gate 	"/usr/man/man3m",
60*7c478bd9Sstevel@tonic-gate 	"/usr/man/man3n",
61*7c478bd9Sstevel@tonic-gate 	"/usr/man/man3s",
62*7c478bd9Sstevel@tonic-gate 	"/usr/man/man3w",
63*7c478bd9Sstevel@tonic-gate 	"/usr/man/man3x",
64*7c478bd9Sstevel@tonic-gate 	"/usr/man/man3x11",
65*7c478bd9Sstevel@tonic-gate 	"/usr/man/man3xt",
66*7c478bd9Sstevel@tonic-gate 	"/usr/man/man4",
67*7c478bd9Sstevel@tonic-gate 	"/usr/man/man4b",
68*7c478bd9Sstevel@tonic-gate 	"/usr/man/man5",
69*7c478bd9Sstevel@tonic-gate 	"/usr/man/man6",
70*7c478bd9Sstevel@tonic-gate 	"/usr/man/man7",
71*7c478bd9Sstevel@tonic-gate 	"/usr/man/man7b",
72*7c478bd9Sstevel@tonic-gate 	"/usr/man/man8",
73*7c478bd9Sstevel@tonic-gate 	"/usr/man/man9e",
74*7c478bd9Sstevel@tonic-gate 	"/usr/man/man9f",
75*7c478bd9Sstevel@tonic-gate 	"/usr/man/man9s",
76*7c478bd9Sstevel@tonic-gate 	"/usr/man/manl",
77*7c478bd9Sstevel@tonic-gate 	"/usr/man/mann",
78*7c478bd9Sstevel@tonic-gate 	"/usr/man/mano",
79*7c478bd9Sstevel@tonic-gate 	0
80*7c478bd9Sstevel@tonic-gate };
81*7c478bd9Sstevel@tonic-gate static char *srcdirs[]  = {
82*7c478bd9Sstevel@tonic-gate 	"/usr/src/cmd",
83*7c478bd9Sstevel@tonic-gate 	"/usr/src/head",
84*7c478bd9Sstevel@tonic-gate 	"/usr/src/lib",
85*7c478bd9Sstevel@tonic-gate 	"/usr/src/lib/libc",
86*7c478bd9Sstevel@tonic-gate 	"/usr/src/lib/libc/port",
87*7c478bd9Sstevel@tonic-gate 	"/usr/src/lib/libc/port/gen",
88*7c478bd9Sstevel@tonic-gate 	"/usr/src/lib/libc/port/print",
89*7c478bd9Sstevel@tonic-gate 	"/usr/src/lib/libc/port/stdio",
90*7c478bd9Sstevel@tonic-gate 	"/usr/src/lib/libc/port/sys",
91*7c478bd9Sstevel@tonic-gate 	"/usr/src/lib/libc/sparc",
92*7c478bd9Sstevel@tonic-gate 	"/usr/src/lib/libc/sparc/gen",
93*7c478bd9Sstevel@tonic-gate 	"/usr/src/lib/libc/sparc/sys",
94*7c478bd9Sstevel@tonic-gate 	"/usr/src/ucbcmd",
95*7c478bd9Sstevel@tonic-gate 	"/usr/src/ucblib",
96*7c478bd9Sstevel@tonic-gate 	"/usr/src/ucbinclude",
97*7c478bd9Sstevel@tonic-gate 	"/usr/src/uts",
98*7c478bd9Sstevel@tonic-gate 	"/usr/src/uts/common",
99*7c478bd9Sstevel@tonic-gate 	"/usr/src/uts/sun",
100*7c478bd9Sstevel@tonic-gate 	"/usr/src/uts/sun4",
101*7c478bd9Sstevel@tonic-gate 	"/usr/src/uts/sun4c",
102*7c478bd9Sstevel@tonic-gate 	"/usr/src/uts/sparc",
103*7c478bd9Sstevel@tonic-gate 	"/usr/src/local",
104*7c478bd9Sstevel@tonic-gate 	"/usr/src/new",
105*7c478bd9Sstevel@tonic-gate 	"/usr/src/old",
106*7c478bd9Sstevel@tonic-gate 	0
107*7c478bd9Sstevel@tonic-gate };
108*7c478bd9Sstevel@tonic-gate 
109*7c478bd9Sstevel@tonic-gate char	sflag = 1;
110*7c478bd9Sstevel@tonic-gate char	bflag = 1;
111*7c478bd9Sstevel@tonic-gate char	mflag = 1;
112*7c478bd9Sstevel@tonic-gate char	**Sflag;
113*7c478bd9Sstevel@tonic-gate int	Scnt;
114*7c478bd9Sstevel@tonic-gate char	**Bflag;
115*7c478bd9Sstevel@tonic-gate int	Bcnt;
116*7c478bd9Sstevel@tonic-gate char	**Mflag;
117*7c478bd9Sstevel@tonic-gate int	Mcnt;
118*7c478bd9Sstevel@tonic-gate char	uflag;
119*7c478bd9Sstevel@tonic-gate /*
120*7c478bd9Sstevel@tonic-gate  * whereis name
121*7c478bd9Sstevel@tonic-gate  * look for source, documentation and binaries
122*7c478bd9Sstevel@tonic-gate  */
123*7c478bd9Sstevel@tonic-gate main(argc, argv)
124*7c478bd9Sstevel@tonic-gate 	int argc;
125*7c478bd9Sstevel@tonic-gate 	char *argv[];
126*7c478bd9Sstevel@tonic-gate {
127*7c478bd9Sstevel@tonic-gate 
128*7c478bd9Sstevel@tonic-gate 	argc--, argv++;
129*7c478bd9Sstevel@tonic-gate 	if (argc == 0) {
130*7c478bd9Sstevel@tonic-gate usage:
131*7c478bd9Sstevel@tonic-gate 		fprintf(stderr, "whereis [ -sbmu ] [ -SBM dir ... -f ] name...\n");
132*7c478bd9Sstevel@tonic-gate 		exit(1);
133*7c478bd9Sstevel@tonic-gate 	}
134*7c478bd9Sstevel@tonic-gate 	do
135*7c478bd9Sstevel@tonic-gate 		if (argv[0][0] == '-') {
136*7c478bd9Sstevel@tonic-gate 			register char *cp = argv[0] + 1;
137*7c478bd9Sstevel@tonic-gate 			while (*cp) switch (*cp++) {
138*7c478bd9Sstevel@tonic-gate 
139*7c478bd9Sstevel@tonic-gate 			case 'f':
140*7c478bd9Sstevel@tonic-gate 				break;
141*7c478bd9Sstevel@tonic-gate 
142*7c478bd9Sstevel@tonic-gate 			case 'S':
143*7c478bd9Sstevel@tonic-gate 				getlist(&argc, &argv, &Sflag, &Scnt);
144*7c478bd9Sstevel@tonic-gate 				break;
145*7c478bd9Sstevel@tonic-gate 
146*7c478bd9Sstevel@tonic-gate 			case 'B':
147*7c478bd9Sstevel@tonic-gate 				getlist(&argc, &argv, &Bflag, &Bcnt);
148*7c478bd9Sstevel@tonic-gate 				break;
149*7c478bd9Sstevel@tonic-gate 
150*7c478bd9Sstevel@tonic-gate 			case 'M':
151*7c478bd9Sstevel@tonic-gate 				getlist(&argc, &argv, &Mflag, &Mcnt);
152*7c478bd9Sstevel@tonic-gate 				break;
153*7c478bd9Sstevel@tonic-gate 
154*7c478bd9Sstevel@tonic-gate 			case 's':
155*7c478bd9Sstevel@tonic-gate 				zerof();
156*7c478bd9Sstevel@tonic-gate 				sflag++;
157*7c478bd9Sstevel@tonic-gate 				continue;
158*7c478bd9Sstevel@tonic-gate 
159*7c478bd9Sstevel@tonic-gate 			case 'u':
160*7c478bd9Sstevel@tonic-gate 				uflag++;
161*7c478bd9Sstevel@tonic-gate 				continue;
162*7c478bd9Sstevel@tonic-gate 
163*7c478bd9Sstevel@tonic-gate 			case 'b':
164*7c478bd9Sstevel@tonic-gate 				zerof();
165*7c478bd9Sstevel@tonic-gate 				bflag++;
166*7c478bd9Sstevel@tonic-gate 				continue;
167*7c478bd9Sstevel@tonic-gate 
168*7c478bd9Sstevel@tonic-gate 			case 'm':
169*7c478bd9Sstevel@tonic-gate 				zerof();
170*7c478bd9Sstevel@tonic-gate 				mflag++;
171*7c478bd9Sstevel@tonic-gate 				continue;
172*7c478bd9Sstevel@tonic-gate 
173*7c478bd9Sstevel@tonic-gate 			default:
174*7c478bd9Sstevel@tonic-gate 				goto usage;
175*7c478bd9Sstevel@tonic-gate 			}
176*7c478bd9Sstevel@tonic-gate 			argv++;
177*7c478bd9Sstevel@tonic-gate 		} else
178*7c478bd9Sstevel@tonic-gate 			lookup(*argv++);
179*7c478bd9Sstevel@tonic-gate 	while (--argc > 0);
180*7c478bd9Sstevel@tonic-gate 	exit(0);
181*7c478bd9Sstevel@tonic-gate 	/* NOTREACHED */
182*7c478bd9Sstevel@tonic-gate }
183*7c478bd9Sstevel@tonic-gate 
184*7c478bd9Sstevel@tonic-gate getlist(argcp, argvp, flagp, cntp)
185*7c478bd9Sstevel@tonic-gate 	char ***argvp;
186*7c478bd9Sstevel@tonic-gate 	int *argcp;
187*7c478bd9Sstevel@tonic-gate 	char ***flagp;
188*7c478bd9Sstevel@tonic-gate 	int *cntp;
189*7c478bd9Sstevel@tonic-gate {
190*7c478bd9Sstevel@tonic-gate 
191*7c478bd9Sstevel@tonic-gate 	(*argvp)++;
192*7c478bd9Sstevel@tonic-gate 	*flagp = *argvp;
193*7c478bd9Sstevel@tonic-gate 	*cntp = 0;
194*7c478bd9Sstevel@tonic-gate 	for ((*argcp)--; *argcp > 0 && (*argvp)[0][0] != '-'; (*argcp)--)
195*7c478bd9Sstevel@tonic-gate 		(*cntp)++, (*argvp)++;
196*7c478bd9Sstevel@tonic-gate 	(*argcp)++;
197*7c478bd9Sstevel@tonic-gate 	(*argvp)--;
198*7c478bd9Sstevel@tonic-gate }
199*7c478bd9Sstevel@tonic-gate 
200*7c478bd9Sstevel@tonic-gate 
201*7c478bd9Sstevel@tonic-gate zerof()
202*7c478bd9Sstevel@tonic-gate {
203*7c478bd9Sstevel@tonic-gate 
204*7c478bd9Sstevel@tonic-gate 	if (sflag && bflag && mflag)
205*7c478bd9Sstevel@tonic-gate 		sflag = bflag = mflag = 0;
206*7c478bd9Sstevel@tonic-gate }
207*7c478bd9Sstevel@tonic-gate int	count;
208*7c478bd9Sstevel@tonic-gate int	print;
209*7c478bd9Sstevel@tonic-gate 
210*7c478bd9Sstevel@tonic-gate 
211*7c478bd9Sstevel@tonic-gate lookup(cp)
212*7c478bd9Sstevel@tonic-gate 	register char *cp;
213*7c478bd9Sstevel@tonic-gate {
214*7c478bd9Sstevel@tonic-gate 	register char *dp;
215*7c478bd9Sstevel@tonic-gate 
216*7c478bd9Sstevel@tonic-gate 	for (dp = cp; *dp; dp++)
217*7c478bd9Sstevel@tonic-gate 		continue;
218*7c478bd9Sstevel@tonic-gate 	for (; dp > cp; dp--) {
219*7c478bd9Sstevel@tonic-gate 		if (*dp == '.') {
220*7c478bd9Sstevel@tonic-gate 			*dp = 0;
221*7c478bd9Sstevel@tonic-gate 			break;
222*7c478bd9Sstevel@tonic-gate 		}
223*7c478bd9Sstevel@tonic-gate 	}
224*7c478bd9Sstevel@tonic-gate 	for (dp = cp; *dp; dp++)
225*7c478bd9Sstevel@tonic-gate 		if (*dp == '/')
226*7c478bd9Sstevel@tonic-gate 			cp = dp + 1;
227*7c478bd9Sstevel@tonic-gate 	if (uflag) {
228*7c478bd9Sstevel@tonic-gate 		print = 0;
229*7c478bd9Sstevel@tonic-gate 		count = 0;
230*7c478bd9Sstevel@tonic-gate 	} else
231*7c478bd9Sstevel@tonic-gate 		print = 1;
232*7c478bd9Sstevel@tonic-gate again:
233*7c478bd9Sstevel@tonic-gate 	if (print)
234*7c478bd9Sstevel@tonic-gate 		printf("%s:", cp);
235*7c478bd9Sstevel@tonic-gate 	if (sflag) {
236*7c478bd9Sstevel@tonic-gate 		looksrc(cp);
237*7c478bd9Sstevel@tonic-gate 		if (uflag && print == 0 && count != 1) {
238*7c478bd9Sstevel@tonic-gate 			print = 1;
239*7c478bd9Sstevel@tonic-gate 			goto again;
240*7c478bd9Sstevel@tonic-gate 		}
241*7c478bd9Sstevel@tonic-gate 	}
242*7c478bd9Sstevel@tonic-gate 	count = 0;
243*7c478bd9Sstevel@tonic-gate 	if (bflag) {
244*7c478bd9Sstevel@tonic-gate 		lookbin(cp);
245*7c478bd9Sstevel@tonic-gate 		if (uflag && print == 0 && count != 1) {
246*7c478bd9Sstevel@tonic-gate 			print = 1;
247*7c478bd9Sstevel@tonic-gate 			goto again;
248*7c478bd9Sstevel@tonic-gate 		}
249*7c478bd9Sstevel@tonic-gate 	}
250*7c478bd9Sstevel@tonic-gate 	count = 0;
251*7c478bd9Sstevel@tonic-gate 	if (mflag) {
252*7c478bd9Sstevel@tonic-gate 		lookman(cp);
253*7c478bd9Sstevel@tonic-gate 		if (uflag && print == 0 && count != 1) {
254*7c478bd9Sstevel@tonic-gate 			print = 1;
255*7c478bd9Sstevel@tonic-gate 			goto again;
256*7c478bd9Sstevel@tonic-gate 		}
257*7c478bd9Sstevel@tonic-gate 	}
258*7c478bd9Sstevel@tonic-gate 	if (print)
259*7c478bd9Sstevel@tonic-gate 		printf("\n");
260*7c478bd9Sstevel@tonic-gate }
261*7c478bd9Sstevel@tonic-gate 
262*7c478bd9Sstevel@tonic-gate looksrc(cp)
263*7c478bd9Sstevel@tonic-gate 	char *cp;
264*7c478bd9Sstevel@tonic-gate {
265*7c478bd9Sstevel@tonic-gate 	if (Sflag == 0) {
266*7c478bd9Sstevel@tonic-gate 		find(srcdirs, cp);
267*7c478bd9Sstevel@tonic-gate 	} else
268*7c478bd9Sstevel@tonic-gate 		findv(Sflag, Scnt, cp);
269*7c478bd9Sstevel@tonic-gate }
270*7c478bd9Sstevel@tonic-gate 
271*7c478bd9Sstevel@tonic-gate lookbin(cp)
272*7c478bd9Sstevel@tonic-gate 	char *cp;
273*7c478bd9Sstevel@tonic-gate {
274*7c478bd9Sstevel@tonic-gate 	if (Bflag == 0)
275*7c478bd9Sstevel@tonic-gate 		find(bindirs, cp);
276*7c478bd9Sstevel@tonic-gate 	else
277*7c478bd9Sstevel@tonic-gate 		findv(Bflag, Bcnt, cp);
278*7c478bd9Sstevel@tonic-gate }
279*7c478bd9Sstevel@tonic-gate 
280*7c478bd9Sstevel@tonic-gate lookman(cp)
281*7c478bd9Sstevel@tonic-gate 	char *cp;
282*7c478bd9Sstevel@tonic-gate {
283*7c478bd9Sstevel@tonic-gate 	if (Mflag == 0) {
284*7c478bd9Sstevel@tonic-gate 		find(mandirs, cp);
285*7c478bd9Sstevel@tonic-gate 	} else
286*7c478bd9Sstevel@tonic-gate 		findv(Mflag, Mcnt, cp);
287*7c478bd9Sstevel@tonic-gate }
288*7c478bd9Sstevel@tonic-gate 
289*7c478bd9Sstevel@tonic-gate findv(dirv, dirc, cp)
290*7c478bd9Sstevel@tonic-gate 	char **dirv;
291*7c478bd9Sstevel@tonic-gate 	int dirc;
292*7c478bd9Sstevel@tonic-gate 	char *cp;
293*7c478bd9Sstevel@tonic-gate {
294*7c478bd9Sstevel@tonic-gate 
295*7c478bd9Sstevel@tonic-gate 	while (dirc > 0)
296*7c478bd9Sstevel@tonic-gate 		findin(*dirv++, cp), dirc--;
297*7c478bd9Sstevel@tonic-gate }
298*7c478bd9Sstevel@tonic-gate 
299*7c478bd9Sstevel@tonic-gate find(dirs, cp)
300*7c478bd9Sstevel@tonic-gate 	char **dirs;
301*7c478bd9Sstevel@tonic-gate 	char *cp;
302*7c478bd9Sstevel@tonic-gate {
303*7c478bd9Sstevel@tonic-gate 
304*7c478bd9Sstevel@tonic-gate 	while (*dirs)
305*7c478bd9Sstevel@tonic-gate 		findin(*dirs++, cp);
306*7c478bd9Sstevel@tonic-gate }
307*7c478bd9Sstevel@tonic-gate 
308*7c478bd9Sstevel@tonic-gate findin(dir, cp)
309*7c478bd9Sstevel@tonic-gate 	char *dir, *cp;
310*7c478bd9Sstevel@tonic-gate {
311*7c478bd9Sstevel@tonic-gate 	DIR *dirp;
312*7c478bd9Sstevel@tonic-gate 	struct dirent *dp;
313*7c478bd9Sstevel@tonic-gate 
314*7c478bd9Sstevel@tonic-gate 	dirp = opendir(dir);
315*7c478bd9Sstevel@tonic-gate 	if (dirp == NULL)
316*7c478bd9Sstevel@tonic-gate 		return;
317*7c478bd9Sstevel@tonic-gate 	while ((dp = readdir(dirp)) != NULL) {
318*7c478bd9Sstevel@tonic-gate 		if (itsit(cp, dp->d_name)) {
319*7c478bd9Sstevel@tonic-gate 			count++;
320*7c478bd9Sstevel@tonic-gate 			if (print)
321*7c478bd9Sstevel@tonic-gate 				printf(" %s/%s", dir, dp->d_name);
322*7c478bd9Sstevel@tonic-gate 		}
323*7c478bd9Sstevel@tonic-gate 	}
324*7c478bd9Sstevel@tonic-gate 	closedir(dirp);
325*7c478bd9Sstevel@tonic-gate }
326*7c478bd9Sstevel@tonic-gate 
327*7c478bd9Sstevel@tonic-gate itsit(cp, dp)
328*7c478bd9Sstevel@tonic-gate 	register char *cp, *dp;
329*7c478bd9Sstevel@tonic-gate {
330*7c478bd9Sstevel@tonic-gate 	register int i = strlen(dp);
331*7c478bd9Sstevel@tonic-gate 
332*7c478bd9Sstevel@tonic-gate 	if (dp[0] == 's' && dp[1] == '.' && itsit(cp, dp+2))
333*7c478bd9Sstevel@tonic-gate 		return (1);
334*7c478bd9Sstevel@tonic-gate 	while (*cp && *dp && *cp == *dp)
335*7c478bd9Sstevel@tonic-gate 		cp++, dp++, i--;
336*7c478bd9Sstevel@tonic-gate 	if (*cp == 0 && *dp == 0)
337*7c478bd9Sstevel@tonic-gate 		return (1);
338*7c478bd9Sstevel@tonic-gate 	while (isdigit(*dp))
339*7c478bd9Sstevel@tonic-gate 		dp++;
340*7c478bd9Sstevel@tonic-gate 	if (*cp == 0 && *dp++ == '.') {
341*7c478bd9Sstevel@tonic-gate 		--i;
342*7c478bd9Sstevel@tonic-gate 		while (i > 0 && *dp)
343*7c478bd9Sstevel@tonic-gate 			if (--i, *dp++ == '.')
344*7c478bd9Sstevel@tonic-gate 				return (*dp++ == 'C' && *dp++ == 0);
345*7c478bd9Sstevel@tonic-gate 		return (1);
346*7c478bd9Sstevel@tonic-gate 	}
347*7c478bd9Sstevel@tonic-gate 	return (0);
348*7c478bd9Sstevel@tonic-gate }
349