char *FILE_SearchPaths( char *path, char *subpath, char *name ) { static STRING buff; char **list; int paths,item,subitem; char *file=NULL; BOOL found; STRING func; // Make sure FILE API is started... if( !FILE_API_check() ) { return(NULL); } // First check if local file exists... if( FILE_Exist(name) ) { return(name); } // Now do more complicated search path... strncpy(func,STR_stringf("FILE_SearchsPath(path=%s,file=%s)",path,name),sizeof(STRING)); // Extract list of paths... list = STR_tokens(path,";",paths); // Make sure paths were parsed... if( paths == 0 ) { FILE_errorf("%s Cannot parse paths.\n",func); return(NULL); } for( found=FALSE,item=0; ((item < paths) && !found); item++ ) { for( subitem=0; ((subitem < 2) && !found); subitem++ ) { file = NULL; switch( subitem ) { case 0 : // Search for file in path + subpath... if( !STR_null(subpath,STRLEN) ) { strncpy(file=buff,STR_stringf("%s\\%s\\%s",list[item],subpath,name),STRLEN); } break; case 1 : // Search for file in path... strncpy(file=buff,STR_stringf("%s\\%s",list[item],name),STRLEN); break; } if( file != NULL ) { found = FILE_Exist(file); FILE_debugf("FILE_SearchPath(...) [%02d] %s %s\n",item,file,STR_YesNo(found)); } } } if( !found ) { FILE_errorf("%s Cannot find file.\n",func); return(NULL); } FILE_messgf("%s OK.\n[%s]\n",func,file); return(file); }
/** * Returns True if file or directory does not exist. Returns False if file * exists although not necessarily accessible in context of the current * process. */ Bool FILE_NonExist(Str fname) { return !FILE_Exist(fname); }