# 2.11BSD#431 - /usr/src/ucb/whereis.c

##### Functions

    find              X
    findin            X
    findv             X
    getlist           X
    itsit             X
    lookbin           X
    lookman           X
    looksrc           X
    lookup            X
    main              X
    zerof             X

##### Variables

    Bcnt              X
    Bflag             X
    Mcnt              X
    Mflag             X
    Scnt              X
    Sflag             X
    bflag             X
    copyright         X
    count             X
    mflag             X
    print             X
    sflag             X
    uflag             X

       1: /*
       2:  * Copyright (c) 1980 Regents of the University of California.
       3:  * All rights reserved.  The Berkeley software License Agreement
       4:  * specifies the terms and conditions for redistribution.
       5:  */
       6:
       7: #if !defined(lint) && defined(DOSCCS)
       8: char copyright[] =
       9: "@(#) Copyright (c) 1980 Regents of the University of California.\n\
      10:  All rights reserved.\n";
      11:
      12: static char sccsid[] = "@(#)whereis.c	5.1.1 (2.11BSD) 1996/10/23";
      13: #endif
      14:
      15: #include <sys/param.h>
      16: #include <sys/dir.h>
      17: #include <stdio.h>
      18: #include <ctype.h>
      19:
      20: static char *bindirs[] = {
      21:     "/etc",
      22:     "/bin",
      23:     "/sbin",
      24:     "/usr/bin",
      25:     "/usr/sbin",
      26:     "/usr/games",
      27:     "/usr/ucb",
      28:     "/usr/libexec",
      29:     "/usr/local",
      30:     "/usr/local/bin",
      31:     "/usr/new",
      32:     0
      33: };
      34: static char *mandirs[] = {
      35:     "/usr/man/man1",
      36:     "/usr/man/man2",
      37:     "/usr/man/man3",
      38:     "/usr/man/man4",
      39:     "/usr/man/man5",
      40:     "/usr/man/man6",
      41:     "/usr/man/man7",
      42:     "/usr/man/man8",
      43:     "/usr/man/manl",
      44:     "/usr/man/mann",
      45:     "/usr/man/mano",
      46:     0
      47: };
      48: static char *srcdirs[]  = {
      49:     "/usr/src/bin",
      50:     "/usr/src/sbin",
      51:     "/usr/src/usr.bin",
      52:     "/usr/src/usr.sbin",
      53:     "/usr/src/etc",
      54:     "/usr/src/ucb",
      55:     "/usr/src/games",
      56:     "/usr/src/usr.lib",
      57:     "/usr/src/lib",
      58:     "/usr/src/libexec",
      59:     "/usr/src/local",
      60:     "/usr/src/new",
      61:     "/usr/src/include",
      62:     "/usr/src/lib/libc/gen",
      63:     "/usr/src/lib/libc/stdio",
      64:     "/usr/src/lib/libc/sys",
      65:     "/usr/src/lib/libc/net/inet",
      66:     "/usr/src/lib/libc/net/misc",
      67:     "/usr/src/ucb/pascal",
      68:     "/usr/src/ucb/pascal/utilities",
      69:     0
      70: };
      71:
      72: char    sflag = 1;
      73: char    bflag = 1;
      74: char    mflag = 1;
      75: char    **Sflag;
      76: int Scnt;
      77: char    **Bflag;
      78: int Bcnt;
      79: char    **Mflag;
      80: int Mcnt;
      81: char    uflag;
      82: /*
      83:  * whereis name
      84:  * look for source, documentation and binaries
      85:  */
      86: main(argc, argv)
      87:     int argc;
      88:     char *argv[];
      89: {
      90:
      91:     argc--, argv++;
      92:     if (argc == 0) {
      93: usage:
      94:         fprintf(stderr, "whereis [ -sbmu ] [ -SBM dir ... -f ] name...\n");
      95:         exit(1);
      96:     }
      97:     do
      98:         if (argv[0][0] == '-') {
      99:             register char *cp = argv[0] + 1;
     100:             while (*cp) switch (*cp++) {
     101:
     102:             case 'f':
     103:                 break;
     104:
     105:             case 'S':
     106:                 getlist(&argc, &argv, &Sflag, &Scnt);
     107:                 break;
     108:
     109:             case 'B':
     110:                 getlist(&argc, &argv, &Bflag, &Bcnt);
     111:                 break;
     112:
     113:             case 'M':
     114:                 getlist(&argc, &argv, &Mflag, &Mcnt);
     115:                 break;
     116:
     117:             case 's':
     118:                 zerof();
     119:                 sflag++;
     120:                 continue;
     121:
     122:             case 'u':
     123:                 uflag++;
     124:                 continue;
     125:
     126:             case 'b':
     127:                 zerof();
     128:                 bflag++;
     129:                 continue;
     130:
     131:             case 'm':
     132:                 zerof();
     133:                 mflag++;
     134:                 continue;
     135:
     136:             default:
     137:                 goto usage;
     138:             }
     139:             argv++;
     140:         } else
     141:             lookup(*argv++);
     142:     while (--argc > 0);
     143: }
     144:
     145: getlist(argcp, argvp, flagp, cntp)
     146:     char ***argvp;
     147:     int *argcp;
     148:     char ***flagp;
     149:     int *cntp;
     150: {
     151:
     152:     (*argvp)++;
     153:     *flagp = *argvp;
     154:     *cntp = 0;
     155:     for ((*argcp)--; *argcp > 0 && (*argvp)[0][0] != '-'; (*argcp)--)
     156:         (*cntp)++, (*argvp)++;
     157:     (*argcp)++;
     158:     (*argvp)--;
     159: }
     160:
     161:
     162: zerof()
     163: {
     164:
     165:     if (sflag && bflag && mflag)
     166:         sflag = bflag = mflag = 0;
     167: }
     168: int count;
     169: int print;
     170:
     171:
     172: lookup(cp)
     173:     register char *cp;
     174: {
     175:     register char *dp;
     176:
     177:     for (dp = cp; *dp; dp++)
     178:         continue;
     179:     for (; dp > cp; dp--) {
     180:         if (*dp == '.') {
     181:             *dp = 0;
     182:             break;
     183:         }
     184:     }
     185:     for (dp = cp; *dp; dp++)
     186:         if (*dp == '/')
     187:             cp = dp + 1;
     188:     if (uflag) {
     189:         print = 0;
     190:         count = 0;
     191:     } else
     192:         print = 1;
     193: again:
     194:     if (print)
     195:         printf("%s:", cp);
     196:     if (sflag) {
     197:         looksrc(cp);
     198:         if (uflag && print == 0 && count != 1) {
     199:             print = 1;
     200:             goto again;
     201:         }
     202:     }
     203:     count = 0;
     204:     if (bflag) {
     205:         lookbin(cp);
     206:         if (uflag && print == 0 && count != 1) {
     207:             print = 1;
     208:             goto again;
     209:         }
     210:     }
     211:     count = 0;
     212:     if (mflag) {
     213:         lookman(cp);
     214:         if (uflag && print == 0 && count != 1) {
     215:             print = 1;
     216:             goto again;
     217:         }
     218:     }
     219:     if (print)
     220:         printf("\n");
     221: }
     222:
     223: looksrc(cp)
     224:     char *cp;
     225: {
     226:     if (Sflag == 0) {
     227:         find(srcdirs, cp);
     228:     } else
     229:         findv(Sflag, Scnt, cp);
     230: }
     231:
     232: lookbin(cp)
     233:     char *cp;
     234: {
     235:     if (Bflag == 0)
     236:         find(bindirs, cp);
     237:     else
     238:         findv(Bflag, Bcnt, cp);
     239: }
     240:
     241: lookman(cp)
     242:     char *cp;
     243: {
     244:     if (Mflag == 0) {
     245:         find(mandirs, cp);
     246:     } else
     247:         findv(Mflag, Mcnt, cp);
     248: }
     249:
     250: findv(dirv, dirc, cp)
     251:     char **dirv;
     252:     int dirc;
     253:     char *cp;
     254: {
     255:
     256:     while (dirc > 0)
     257:         findin(*dirv++, cp), dirc--;
     258: }
     259:
     260: find(dirs, cp)
     261:     char **dirs;
     262:     char *cp;
     263: {
     264:
     265:     while (*dirs)
     266:         findin(*dirs++, cp);
     267: }
     268:
     269: findin(dir, cp)
     270:     char *dir, *cp;
     271: {
     272:     DIR *dirp;
     273:     struct direct *dp;
     274:
     275:     dirp = opendir(dir);
     276:     if (dirp == NULL)
     277:         return;
     278:     while ((dp = readdir(dirp)) != NULL) {
     279:         if (itsit(cp, dp->d_name)) {
     280:             count++;
     281:             if (print)
     282:                 printf(" %s/%s", dir, dp->d_name);
     283:         }
     284:     }
     285:     closedir(dirp);
     286: }
     287:
     288: itsit(cp, dp)
     289:     register char *cp, *dp;
     290: {
     291:     register int i = strlen(dp);
     292:
     293:     if (dp[0] == 's' && dp[1] == '.' && itsit(cp, dp+2))
     294:         return (1);
     295:     while (*cp && *dp && *cp == *dp)
     296:         cp++, dp++, i--;
     297:     if (*cp == 0 && *dp == 0)
     298:         return (1);
     299:     while (isdigit(*dp))
     300:         dp++;
     301:     if (*cp == 0 && *dp++ == '.') {
     302:         --i;
     303:         while (i > 0 && *dp)
     304:             if (--i, *dp++ == '.')
     305:                 return (*dp++ == 'C' && *dp++ == 0);
     306:         return (1);
     307:     }
     308:     return (0);
     309: }

#### Defined functions

find defined in line 260; used 3 times

- in line 227, 236, 245

findin defined in line 269; used 2 times

- in line 257, 266

findv defined in line 250; used 3 times

- in line 229, 238, 247

getlist defined in line 145; used 3 times

- in line 106-114(3)

itsit defined in line 288; used 2 times

- in line 279, 293

lookbin defined in line 232; used 1 times

- in line 205

lookman defined in line 241; used 1 times

- in line 213

looksrc defined in line 223; used 1 times

- in line 197

lookup defined in line 172; used 1 times

- in line 141

main defined in line 86; never used
zerof defined in line 162; used 3 times

- in line 118, 127-132(2)

#### Defined variables

Bcnt defined in line 78; used 2 times

- in line 110, 238

Bflag defined in line 77; used 3 times

- in line 110, 235-238(2)

Mcnt defined in line 80; used 2 times

- in line 114, 247

Mflag defined in line 79; used 3 times

- in line 114, 244-247(2)

Scnt defined in line 76; used 2 times

- in line 106, 229

Sflag defined in line 75; used 3 times

- in line 106, 226-229(2)

bflag defined in line 73; used 4 times

- in line 128, 165-166(2), 204

bindirs defined in line 20; used 1 times

- in line 236

copyright defined in line 8; never used
count defined in line 168; used 7 times

- in line 190, 198-214(5), 280

mandirs defined in line 34; used 1 times

- in line 245

mflag defined in line 74; used 4 times

- in line 133, 165-166(2), 212

print defined in line 169; used 11 times

- in line 189-199(5), 206-207(2), 214-219(3), 281

sccsid defined in line 12; never used
sflag defined in line 72; used 4 times

- in line 119, 165-166(2), 196

srcdirs defined in line 48; used 1 times

- in line 227

uflag defined in line 81; used 5 times

- in line 123, 188, 198, 206, 214

Last modified: 1996-10-24 Generated: 2016-12-26 | Generated by src2html V0.67 page hit count: 992 |