pcc@minster.york.ac.uk (05/18/89)
following is a modified version of `which` which was posted to the atari source group. have fun pete cooper -----------------------------cut here-------------------------------- # To unbundle, sh this file echo 'readme' >&2 sed 's/^-//' >readme << 'End of readme' -This is an ST adaptation of a "which" program somone posted to -net.sources many years ago to replace the agonisingly slow -BSD "which" script with a program. I've used it on our un*x -system for years, and finally decided I couldn't do without -it on the ST any longer.. Anyway, here it is (with source, -its trivial enough.) To use it just say - -% which haha - -and it'll add in the ".prg" or ".tos" or ".ttp" while checking for the file. -(it'll look for all three.) It works with the Mark Williams C "msh" PATH, -but you can easily modify it for your favourite shell, just change the comma -in the #define for DELIMETERat the top to whatever the delimeter is for -the PATH in your shell. - --ravi -(ravi@mcnc.org) End of readme echo 'which.c' >&2 sed 's/^-//' >which.c << 'End of which.c' -#define DELIMETER ':' - -#include <stdio.h> - -char *getenv(); -char *index(); - -int -main(ac,av) -char **av; -{ - char *path, *cp; - char buf[400]; - char prog[400]; - char patbuf[512]; - int quit, none; - - if (ac < 2) { - fprintf(stderr, "Usage: %s cmd [cmd, ..]\n", *av); - exit(1); - } - av[ac] = 0; - for(av++ ; *av; av++) { - - quit = 0; - none = 1; - if ((path = getenv("PATH")) == NULL) { - fprintf(stderr, "Null path.\n"); - exit(0); - } - strcpy(patbuf, path); - path = patbuf; - cp = path; - - while(1) { - cp = index(path, DELIMETER); - if (cp == NULL) - quit++; - else - *cp = '\0'; - - if (strcmp(path,"") == (char *)NULL && quit == 0) { - sprintf(buf, "%s./%s", path, *av); - } else - sprintf(buf, "%s/%s", path, *av); - - /* fprintf(stderr,"Trying %s, path %s\n",buf,path); */ - - path = ++cp; - - if (access(buf, 1) == 0) { - printf("%s\n", buf); - none = 0; - } - - sprintf(prog, "%s.%s", buf, "prg"); - if (access(prog, 1) == 0) { - printf("%s\n", prog); - none = 0; - } - - sprintf(prog, "%s.%s", buf, "ttp"); - if (access(prog, 1) == 0) { - printf("%s\n", prog); - none = 0; - } - - sprintf(prog, "%s.%s", buf, "tos"); - if (access(prog, 1) == 0) { - printf("%s\n", prog); - none = 0; - } - if (quit) { - if (none) - printf("No %s in %s\n", *av, getenv("PATH")); - break; - } - } - } - exit(0); -} - - End of which.c Newsgroups: comp.os.minix