gbool GUrlCache::AddCacheDirectory(const char *dir,CStringArray &readCacheDirs) { CString directory; directory = dir; directory.TrimRight(); directory.TrimLeft(); if (directory.IsEmpty()) return FALSE; // if (strprefix(directory,"cdrom") || strprefix(directory,"CDROM")) { // replace cd rom with found cdroms int i=0; const char *x = directory; x+=strlen("cdrom"); // get cdrom id if (*x >= '0' && *x <'9') { i = (*x - '0'); x++; } // skip the : if (*x == ':') x++; if (i<cdroms.GetSize()) { CString dir = cdroms.GetAt(i); // strip of prefix if (*x == '\\') x++; else if (*x == '/') x++; directory = dir + CString(x); } else return FALSE; // no cdrom } // filter out duplicates for (int i=0; i<readCacheDirs.GetSize(); i++) { if (readCacheDirs.GetAt(i) == directory) return FALSE; } if (ExistsDirectory(directory)) { readCacheDirs.Add(directory); return TRUE; } return FALSE; }
static char * findHome(const char *symbols, int argc, const char **argv) { const char *home = NULL; char envbuf[MAXPATHLEN]; char plp[MAXPATHLEN]; const char *val; if ( (val=longopt("home", argc, argv)) ) { if ( (home=PrologPath(val, plp, sizeof(plp))) ) return store_string(home); return NULL; } if ( (val = exec_var("homevar")) && (home = Getenv(val, envbuf, sizeof(envbuf))) && (home = PrologPath(home, plp, sizeof(plp))) ) return store_string(home); if ( (val = exec_var("home")) && (home = PrologPath(val, plp, sizeof(plp))) ) return store_string(home); #ifdef PLHOMEVAR_1 if ( !(home = Getenv(PLHOMEVAR_1, envbuf, sizeof(envbuf))) ) { #ifdef PLHOMEVAR_2 home = Getenv(PLHOMEVAR_2, envbuf, sizeof(envbuf)); #endif } if ( home && (home = PrologPath(home, plp, sizeof(plp))) && ExistsDirectory(home) ) return store_string(home); #endif #ifdef PLHOMEFILE if ( (home = symbols) ) { char buf[MAXPATHLEN]; char parent[MAXPATHLEN]; IOSTREAM *fd; strcpy(parent, DirName(DirName(AbsoluteFile(home, buf), buf), buf)); Ssprintf(buf, "%s/" PLHOMEFILE, parent); if ( (fd = Sopen_file(buf, "r")) ) { if ( Sfgets(buf, sizeof(buf), fd) ) { size_t l = strlen(buf); while(l > 0 && buf[l-1] <= ' ') l--; buf[l] = EOS; #if O_XOS { char buf2[MAXPATHLEN]; _xos_canonical_filename(buf, buf2, MAXPATHLEN, 0); strcpy(buf, buf2); } #endif if ( !IsAbsolutePath(buf) ) { char buf2[MAXPATHLEN]; Ssprintf(buf2, "%s/%s", parent, buf); home = AbsoluteFile(buf2, plp); } else home = AbsoluteFile(buf, plp); if ( ExistsDirectory(home) ) { Sclose(fd); return store_string(home); } } Sclose(fd); } } #endif /*PLHOMEFILE*/ if ( (home = PrologPath(PLHOME, plp, sizeof(plp))) && ExistsDirectory(home) ) return store_string(home); return NULL; }
static char * findHome(char *symbols) { char *home = NULL; char envbuf[MAXPATHLEN]; char plp[MAXPATHLEN]; const char *val; if ( (val = exec_var("homevar")) && (home = getenv3(val, envbuf, sizeof(envbuf))) && (home = PrologPath(home, plp)) ) return store_string(home); if ( (val = exec_var("home")) && (home = PrologPath(home, plp)) ) return store_string(home); if ( !(home = getenv3("SWI_HOME_DIR", envbuf, sizeof(envbuf))) ) home = getenv3("SWIPL", envbuf, sizeof(envbuf)); if ( home && (home = PrologPath(home, plp)) && ExistsDirectory(home) ) return store_string(home); if ( (home = symbols) ) { char buf[MAXPATHLEN]; char parent[MAXPATHLEN]; IOSTREAM *fd; strcpy(parent, DirName(DirName(AbsoluteFile(home, buf), buf), buf)); Ssprintf(buf, "%s/swipl", parent); if ( (fd = Sopen_file(buf, "r")) ) { if ( Sfgets(buf, sizeof(buf), fd) ) { int l = strlen(buf); while(l > 0 && buf[l-1] <= ' ') l--; buf[l] = EOS; #if O_XOS { char buf2[MAXPATHLEN]; _xos_canonical_filename(buf, buf2); strcpy(buf, buf2); } #endif if ( !IsAbsolutePath(buf) ) { char buf2[MAXPATHLEN]; Ssprintf(buf2, "%s/%s", parent, buf); home = AbsoluteFile(buf2, plp); } else home = AbsoluteFile(buf, plp); if ( ExistsDirectory(home) ) { Sclose(fd); return store_string(home); } } Sclose(fd); } } if ( (home = PrologPath(PLHOME, plp)) && ExistsDirectory(home) ) return store_string(home); return NULL; }
bool FileSystem::Exists(const std::string & path) { return ExistsFile(path) || ExistsDirectory(path); }