home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
GEMini Atari
/
GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso
/
files
/
program
/
lynxlib
/
wheris.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-10-23
|
3KB
|
96 lines
/* This source file is part of the LynxLib miscellaneous library by
Robert Fischer, and is Copyright 1990 by Robert Fischer. It costs no
money, and you may not make money off of it, but you may redistribute
it. It comes with ABSOLUTELY NO WARRANTY. See the file LYNXLIB.DOC
for more details.
To contact the author:
Robert Fischer \\80 Killdeer Rd \\Hamden, CT 06517 USA
(203) 288-9599 fischer-robert@cs.yale.edu */
#include <stddef.h>
#include <e_osbind.h>
extern char *getenv();
/* ------------------------------------------------------- */
BOOLEAN existf(n) /* Finds out if file n exists */
char *n;
{
TRANS_BUF buf;
TRANS_BUF *old;
BOOLEAN ret;
old = Fgetdta();
Fsetdta(&buf);
ret = (Fsfirst(n, READ_ONLY | HIDDEN | SYSTEM | CLOSED) == E_OK);
Fsetdta(old);
if (ret) ret = ((buf.attrib & FOLDER) == 0);
return ret;
}
/* ------------------------------------------------------- */
search_env(envvar, fname, fullname, use_this)
/* Searches all the directories in the environment variable */
/* envvar and tests each one, according to use_this(), to see */
/* if it is wanted. When use_this() returns TRUE, it quits */
char *envvar; /* The environment variable to search on */
char *fname; /* The file leaf name */
char *fullname; /* The full pathname to output */
BOOLEAN (*use_this)();
/* Routine to determine which file names to keep & which to throw out */
/* Returns a TRUE to stop the execution */
{
char *envstr;
char *i, *j, *k, *pptr;
/* Check if the environment variable doesn't exist */
if ((envstr = getenv(envvar)) == NULL) {
fullname[0] = '\0';
return;
}
for (pptr = envstr; *pptr != '\0'; ) {
for (i = pptr, j = fullname;
*i != '\0' && *i != ',';
i++, j++)
*j = *i;
/* Put a . for the current directory */
if (j == fullname) *j++ = '.';
/* Play the backslash game */
if (*(j-1) != '\\') *j++ = '\\';
/* strcat */
for (k = fname; *k != '\0'; k++, j++) *j = *k;
*j = '\0';
if ((*use_this)(fullname)) return;
/* Increment pptr */
if (*i != '\0') i++;
pptr = i;
}
fullname[0] = '\0';
}
/* ------------------------------------------------------ */
wheris(envvar, fname, fullname)
/* Finds an already made file from an environment variable */
char *envvar; /* The environment variable to search on */
char *fname; /* The file leaf name */
char *fullname; /* The full pathname to output */
{
search_env(envvar, fname, fullname, &existf);
}
/* ------------------------------------------------------ */
BOOLEAN ret_true()
{
return TRUE;
}
first_path(envvar, fname, fullname)
/* Matches fname with the first directory in envvar */
char *envvar; /* The environment variable to search on */
char *fname; /* The file leaf name */
char *fullname; /* The full pathname to output */
{
search_env(envvar, fname, fullname, &ret_true);
}