Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site tikal.UUCP Path: utzoo!watmath!clyde!cbosgd!cbdkc1!desoto!packard!hoxna!houxm!vax135!cornell!uw-beaver!tikal!larry From: larry@tikal.UUCP (Larry J. Barello) Newsgroups: net.sources Subject: Son of 'which' Message-ID: <225@tikal.UUCP> Date: Mon, 26-Aug-85 10:40:19 EDT Article-I.D.: tikal.225 Posted: Mon Aug 26 10:40:19 1985 Date-Received: Wed, 28-Aug-85 20:23:35 EDT Distribution: net Organization: Teltone Corp., Kirkland, WA Lines: 64 A week or so I posted a quick C version of the UCB shell script "which". It takes as arguments command names and searches your path for instances of them. The version I posted had some cute bugs: it didn't work if you didn't have a path or if there were a null component in the path (Thanks to Tom Truscott). To the folks with v8 shell: wish I had it, sounds like it make a lot of utilities, like this one, useless. Here is a fancified version of the original one. ..!uw-beaver!teltone!larry -------- cut here (duh) ------- #include char *getenv(); char *index(); int main(ac,av) char **av; { char *origpath, *path, *cp; char buf[200]; char patbuf[512]; int quit, found; if (ac < 2) { fprintf(stderr, "Usage: %s cmd [cmd, ..]\n", *av); exit(1); } if ((origpath = getenv("PATH")) == 0) origpath = "."; av[ac] = 0; for(av++ ; *av; av++) { strcpy(patbuf, origpath); cp = path = patbuf; quit = found = 0; while(!quit) { cp = index(path, ':'); if (cp == NULL) quit++; else *cp = '\0'; sprintf(buf, "%s/%s", (*path ? path:"."), *av); path = ++cp; if (access(buf, 1) == 0) { printf("%s\n", buf); found++; } } if (!found) printf("No %s in %s\n", *av, origpath); } exit(0); } ------------------