bool findIncludeFile (util::String const & inclname, util::String const & name, bool sys, util::String & fullname) { // if absolute then no need to search path bool result = false; if (isAbsolute (name)) { if (exists (name)) { result = true; fullname = name; } } // otherwise search in curent dir if not sys else if (! sys && findInDir (getPath (inclname), name, fullname)) { result = true; } else { // search in path list util::StringVector const & path_set = conf::getOptionValue (conf::opt_incl_path_set); result = std::find_if (path_set.begin (), path_set.end (), FindInDir (name, fullname)) != path_set.end (); } return result; }
static std::string GetCaseInsensitiveFilename(const std::string fileName, const char DIR_SEP) { auto splitPaths = Strings::SplitList(fileName, DIR_SEP); if (splitPaths.empty()) return ""; std::string root = splitPaths.front(); splitPaths.pop_front(); std::string path = findInDir(root, Strings::SplitList(fileName, DIR_SEP), DIR_SEP); return path; }
int findCollinear3(const int* iboard, int player,int posIn25) { int idir,dir; int threes; ASSERT(posIn25 > 0 || posIn25 < 25); for(idir=0;idir<4;idir++){ dir = directions[idir]; threes = 1; threes += findInDir(iboard, player,posIn25+dir, dir); //printf("player:%c pos:%d idir:%d 3s: %d\n", player, posIn25, dir, threes); threes += findInDir(iboard, player,posIn25-dir, -1*dir); //printf("player:%c pos:%d idir:-%d total 3s: %d\n", player, posIn25, dir, threes); //printf("\n"); if(threes == 3){ //printf("found 3 in row\n\n"); //printf("player:%c pos:%d idir:%d total 3s: %d\n", player, posIn25, dir, threes); break; } } return threes; }
std::string findInDir(std::string parent, std::list<std::string> remainingPath, const char DIR_SEP) { Directory d(parent); std::string name = remainingPath.front(); remainingPath.pop_front(); //Strip out any excess blank entries (otherwise paths like "./directory//file" would break) while (name == "") { if (remainingPath.empty()) return parent; name = remainingPath.front(); remainingPath.pop_front(); } struct dirent entry , *result = NULL; while (true) { int err = readdir_r(d.d, &entry, &result); if (err) { std::cerr << "Readdir() failed with \"" << err << "\"\n"; return ""; } if (!result) { break; } std::string entName(entry.d_name); if (Strings::CompareCaseInsensitive(name, entName) == 0) { std::string entPath = parent + DIR_SEP + entName; if (remainingPath.empty()) return entPath; else return findInDir(entPath, remainingPath, DIR_SEP); } } return ""; }