jmsellens@watrose.UUCP (John M Sellens) (04/07/84)
X - bug killer These routines look for files along the PATH. Used by 'Make'; requires 'Path' (see adjacent articles). Most useful for finding files that you want to execute. - John ----------------------------------------------------------------- /* Routines in DeSmet C to find files. Requires DOS 2.0. Imbedded assembler code makes portability difficult. Used by 'Make'. Requires 'Path'. */ /* Written by John M Sellens, April, 1984 Code is all original except where indicated otherwise. Until August, 1984: jmsellens@watrose.UUCP 107 - 180 Brybeck Cres. Kitchener, Ontario N2M 5G4 After August, 1984: c/o 1135 Lansdowne Ave. SW Calgary, Alberta T2S 1A4 (c) Copyright 1984 John M Sellens Permission is granted to use, distribute and/or modify this code unless done for direct commercial profit. If you find these routines useful, modest contributions (monetary or otherwise) will be gratefully accepted. Author's name, address and this notice must be included in any copies. */ #include <stdio.h> find(src,dest) char *src, *dest; { /* look for a file (src) by following the PATH string if the file is found, copy its full name into dest and return TRUE; otherwise return FALSE. No guar- antee what will be in dest if FALSE. No guarantee that it will behave reasonably if the path string is silly. If the src string contains a ':' or a '\', the PATH string is not followed. */ char *index(); char **paths; int i; /* see if src exists just as it is */ if (exist(src)) { strcpy(dest,src); return(TRUE); } if ( (paths = parse_path(get_path())) == NULL) return(FALSE); /* no path set, so can't be anywhere else */ /* if has a ':' or a '\', don't search PATH */ if ( (index(src,':')!=NULL) || (index(src,'\\')!=NULL) ) return(FALSE); /* now try each path one by one */ for (i=0; paths[i] != NULL; i++) { strcpy(dest,paths[i]); if (dest[strlen(dest)-1] != '\\') strcat(dest,"\\"); strcat(dest,src); if (exist(dest)) { free(paths); return(TRUE); } } free(paths); return(FALSE); } exist(f) char *f; { /* takes an ASCIIZ string and tests for existence of a 'normal' file with that name. */ /* dangerous coding - assumes that if doesn't use CX */ #asm xor cx,cx ;set zero to look for only normal files # if (_os(0x4E,f) == 0) return(TRUE); else return(FALSE); }