2 * Copyright (c) 1980 The Regents of the University of California.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 /* 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@pld.ORG.PL>
37 * - added Native Language Support
40 #include <sys/param.h>
41 #include <sys/types.h>
51 void getlist(int *, char ***, char ***, int *);
56 void findv(char **, int, char *);
57 void find(char **, char *);
58 void findin(char *, char *);
59 int itsit(char *, char *);
61 static char *bindirs[] = {
76 "/usr/lib/emacs/*/etc",
79 "/usr/interviews/bin/LINUX",
92 "/usr/local/games/bin",
93 "/usr/local/emacs/etc",
116 static char *mandirs[] = {
122 "/usr/interviews/man/mann",
126 static char *srcdirs[] = {
128 "/usr/src/lib/libc/*",
129 "/usr/src/lib/libc/net/*",
130 "/usr/src/ucb/pascal",
131 "/usr/src/ucb/pascal/utilities",
148 * look for source, documentation and binaries
151 main(int argc, char **argv) {
152 setlocale(LC_ALL, "");
153 bindtextdomain(PACKAGE, LOCALEDIR);
159 fprintf(stderr, _("whereis [ -sbmu ] [ -SBM dir ... -f ] name...\n"));
163 if (argv[0][0] == '-') {
164 register char *cp = argv[0] + 1;
165 while (*cp) switch (*cp++) {
171 getlist(&argc, &argv, &Sflag, &Scnt);
175 getlist(&argc, &argv, &Bflag, &Bcnt);
179 getlist(&argc, &argv, &Mflag, &Mcnt);
212 getlist(int *argcp, char ***argvp, char ***flagp, int *cntp) {
216 for ((*argcp)--; *argcp > 0 && (*argvp)[0][0] != '-'; (*argcp)--)
217 (*cntp)++, (*argvp)++;
226 if (sflag && bflag && mflag)
227 sflag = bflag = mflag = 0;
237 for (dp = cp; *dp; dp++)
239 for (; dp > cp; dp--) {
245 for (dp = cp; *dp; dp++)
258 if (uflag && print == 0 && count != 1) {
266 if (uflag && print == 0 && count != 1) {
274 if (uflag && print == 0 && count != 1) {
288 findv(Sflag, Scnt, cp);
296 findv(Bflag, Bcnt, cp);
304 findv(Mflag, Mcnt, cp);
308 findv(char **dirv, int dirc, char *cp) {
310 findin(*dirv++, cp), dirc--;
314 find(char **dirs, char *cp) {
320 findin(char *dir, char *cp) {
328 dd = strchr(dir, '*');
333 if (l < sizeof(dirbuf)) { /* refuse excessively long names */
334 strcpy (dirbuf, dir);
335 d = strchr(dirbuf, '*');
337 dirp = opendir(dirbuf);
340 while ((dp = readdir(dirp)) != NULL) {
341 if (!strcmp(dp->d_name, ".") ||
342 !strcmp(dp->d_name, ".."))
344 if (strlen(dp->d_name) + l > sizeof(dirbuf))
346 sprintf(d, "%s", dp->d_name);
347 if (stat(dirbuf, &statbuf))
349 if (!S_ISDIR(statbuf.st_mode))
362 while ((dp = readdir(dirp)) != NULL) {
363 if (itsit(cp, dp->d_name)) {
366 printf(" %s/%s", dir, dp->d_name);
373 itsit(char *cp, char *dp) {
376 if (dp[0] == 's' && dp[1] == '.' && itsit(cp, dp+2))
378 if (!strcmp(dp+i-2, ".Z"))
380 else if (!strcmp(dp+i-3, ".gz"))
382 else if (!strcmp(dp+i-4, ".bz2"))
384 while (*cp && *dp && *cp == *dp)
386 if (*cp == 0 && *dp == 0)
390 if (*cp == 0 && *dp++ == '.') {
393 if (--i, *dp++ == '.')
394 return (*dp++ == 'C' && *dp++ == 0);