void Globber::FindFilesInDirectoryRecursive(const path& directory, const opString& ext, set<path>& foundfiles) { // does this directory exist? if (!exists(directory)) return; directory_iterator end_itr; // default construction yields past-the-end for (directory_iterator itr(directory); itr != end_itr; ++itr) { if (is_directory(*itr)) { FindFilesInDirectoryRecursive(*itr, ext, foundfiles); } else { // get the path opstring.. path path_found = *itr; // does the extension match? if (extension(path_found) == ext) foundfiles.insert(path_found); } } }
bool Globber::Glob(const opParameters& p) { //NOTE: Here's what we're trying to do here // first we find all the oh files // then we find where all the ocpp files SHOULD be // then we find where all the ooh files SHOULD be // now, we only want to include an oh file in the index // if the matching ooh and ocpp files exist (because maybe its not in the project anymore // ...orphaned or whatever) // and we only want to update the indexes if they're out of date (if no ooh files changed why update it?) // so, only if the above conditions hold do we include an oh file in the index and print the index. //NOTE: we must replace all '\' characters with '/' or else // boost filesystem will complain. // that is done in opParameters now. //TEST: these are test inputs, the real ones should be parameter derived opString outputdir = p.GeneratedDirectory.GetValue(); //TODO: it only supports oh files, should definitely do this differently. // the issue is .doh file output, it looks like an oh file (maybe use .h?) opString extension = "oh"; //NOTE: heres the new process... //I need to recursively find all ooh files //within the output directory //we only want ooh files with matching ocpp files //once we have narrowed these down, //we only want to include ooh/ocpp files with matching oh files //so back-convert all these paths //and do checks, this builds our validohfiles vector, //which is now usable. path outputpath = p.GeneratedDirectory.GetString(); set<path> oohfiles; set<path> ocppfiles; FindFilesInDirectoryRecursive(outputpath,".ooh",oohfiles); FindFilesInDirectoryRecursive(outputpath,".ocpp",ocppfiles); typedef set<path>::const_iterator pathit; // find the valid oh files vector<ohfileinfo> validohfiles; pathit oohend = oohfiles.end(); for(pathit oohit = oohfiles.begin(); oohit != oohend; ++oohit) { pathit ocppend = ocppfiles.end(); for(pathit ocppit = ocppfiles.begin(); ocppit != ocppend; ++ocppit) { //now we want to remove their extensions path oohpath = (*oohit); path ocpppath = (*ocppit); opString ocppstring = ocpppath.string(); opString oohstring = oohpath.string(); ocppstring = ocppstring.RLeft(5); oohstring = oohstring.RLeft(4); //potential oh file! if(ocppstring == oohstring) { //now convert the path... opString ohstring = oohstring; ohstring = opDriver::FromGeneratedPath(ohstring); //ohstring = ohstring.Replace("_up/","../"); //ohstring = ohstring.Right(outputpath.string() + "/"); path ohpath = ohstring.GetString(); //found a valid oh file! if(exists(ohpath)) { if( opString(ohpath.leaf().c_str()).Right('.') == extension) validohfiles.push_back(ohfileinfo(ohpath,oohpath,ocpppath)); } } } } //find the dialect doh files // pathit dohend = dohfiles.end(); // for(pathit dohit = dohfiles.begin(); dohit != dohend; ++dohit) // { // //check if the .ooh file exists... // //if it does we'll use it?? // } //TODO: hook it up to spheroid... // now I need to add a test .oh file // from spheroid, and gradually pound // the data statement grammar into a usable condition // - past this, we want sectioned streams (which aren't required, but enable other later things) //now we have all the valid filenames! if(validohfiles.size() && p.Verbose) { for(size_t i = 0; i < validohfiles.size(); i++) Log(opString("Globber: found oh file : ") + validohfiles[i].ohfilepath.string()); } //now we need to check whether to build any of the indexes.. //1. //determine whether or not to update the ooh index (only if there is an ooh newer than an oh) //so, we need to iterate over all the ooh paths //and see if any of the files are newer than this.. path headerindex = outputpath / "Generated.oohindex"; UpdateIndex<true>(validohfiles,headerindex,p); //2. //we always build the ocpp index //determine whether or not to update the ocpp index (yes always) path sourceindex = outputpath / "Generated.ocppindex"; UpdateIndex<false>(validohfiles,sourceindex,p); return true; }