home *** CD-ROM | disk | FTP | other *** search
- /* ==( bench/srchpath.c )== */
- /* ----------------------------------------------- */
- /* Pro-C Copyright (C) 1988 - 1990 Vestronix Inc. */
- /* Modification to this source is not supported */
- /* by Vestronix Inc. */
- /* All Rights Reserved */
- /* ----------------------------------------------- */
- /* Written Nig 19-Dec-89 */
- /* Modified Geo 1-Feb-90 See comments below */
- /* ----------------------------------------------- */
- /* %W% (%H% %T%) */
-
- /*
- * Modifications
- *
- */
-
- # include <stdio.h>
- # include <bench.h>
-
-
- /*
- * GEO, I am sure that this isn't satisfactory in some
- * cases, perhaps you can have a look at it for me. Nig
- */
- # ifdef MSDOS
- # define PATHSEPERATOR ";"
- # else
- # define PATHSEPERATOR ":"
- # endif
-
-
- /*
- * Scan the PATH as defined by the environment, and
- * return the full name with path if found on the
- * path, or the file name without path if not found
- * on the path.
- */
- void search_path(fname, srchpath, ext)
- char *fname, *srchpath, *ext;
- {
- char path[256];
- char envpath[256];
- char *str;
- char *token;
-
- strcpy(srchpath, fname);
- stripext(srchpath);
-
- str = getenv("PATH");
- if (str != NULL)
- strncpy(envpath, str, sizeof(envpath));
-
- token = strtok(envpath, PATHSEPERATOR);
-
- while (token != NULL)
- {
- strcpy(path, token);
- strcat(path, DIRSLASHES);
- strcat(path, fname);
- strcat(path, ext);
-
- if (access(path, 0) == 0)
- {
- /* Pathname exists - not checking R/W for now */
- stripext(path);
- strcpy(srchpath, path);
- break;
- }
- token = strtok(NULL, PATHSEPERATOR);
- }
- }
-
-
- void stripext(str)
- char *str;
- {
- char *ptr;
- int done = 0;
-
- for(ptr = str + strlen(str) - 1; ptr > str; ptr--)
- {
- if (*ptr == '/' || *ptr == '\\')
- break;
- if (*ptr == '.' && *(ptr - 1) != '/' && *(ptr - 1) != '\\')
- {
- *ptr = '\0';
- break;
- }
- }
- }
-
- void addslash(str)
- char *str;
- {
- /* Doesn't check empty strings */
- str += strlen(str) - 1;
-
- if (*str == DIRSLASH)
- return;
-
- *++str = DIRSLASH;
- *++str = '\0';
- }
-
- void eatslash(str)
- char *str;
- {
- str += strlen(str) - 1;
-
- if (*str != DIRSLASH)
- return;
-
- *str = '\0';
- }
-