int main(int argc, char*argv[]){ refresh(START); char *rawFile,*csvfile,*sysDate; const char url[] = "http://codapi.zappos.biz/menus"; float budgetVal; sysDate = (char*)malloc(sizeof(char)*20); memset(sysDate,'\0',20); budgetVal = validator(argc, argv); //check the validity of the input arguments rawFile = readURL(url); //Read the content from the website and get the name of the file parseFile(rawFile); //Performs parsing of the JSON data on the file name stored in rawFile sysDate = systemDate(); //Find the system date and save it in sysDate variable. //Debugging statements //strcpy(sysDate,"2015-05-11"); returnBestList(sysDate,directoryExam()); //Use the sysdate to find the appropriate files and then perform operations. purgeFiles(directoryExam()); //Maintenance :) deleteFile(rawFile); refresh(STOP); return 0; }
PtexTexture* PtexReaderCache::get(const char* filename, Ptex::String& error) { AutoLockCache locker(cachelock); // lookup reader in map PtexReader* reader = _files[filename]; if (reader) { // -1 means previous open attempt failed if (intptr_t(reader) == -1) return 0; reader->ref(); return reader; } else { bool ok = true; // get open lock and make sure we still need to open // temporarily release cache lock while we open acquire open lock cachelock.unlock(); AutoMutex openlocker(openlock); cachelock.lock(); // lookup entry again (it might have changed in another thread) PtexReader** entry = &_files[filename]; if (*entry) { // another thread opened it while we were waiting if (intptr_t(*entry) == -1) return 0; (*entry)->ref(); return *entry; } // make a new reader reader = new PtexReader((void**)entry, this, _premultiply, _io); // temporarily release cache lock while we open the file cachelock.unlock(); std::string tmppath; const char* pathToOpen = filename; if (!_io) { bool isAbsolute = (filename[0] == '/' #ifdef WINDOWS || filename[0] == '\\' || (isalpha(filename[0]) && filename[1] == ':') #endif ); if (!isAbsolute && !_searchdirs.empty()) { // file is relative, search in searchpath tmppath.reserve(256); // minimize reallocs (will grow automatically) bool found = false; struct stat statbuf; for (size_t i = 0, size = _searchdirs.size(); i < size; i++) { tmppath = _searchdirs[i]; tmppath += "/"; tmppath += filename; if (stat(tmppath.c_str(), &statbuf) == 0) { found = true; pathToOpen = tmppath.c_str(); break; } } if (!found) { std::string errstr = "Can't find ptex file: "; errstr += filename; error = errstr.c_str(); ok = false; } } } if (ok) ok = reader->open(pathToOpen, error); // reacquire cache lock cachelock.lock(); if (!ok) { // open failed, clear parent ptr and unref to delete *entry = reader; // to pass parent check in orphan() reader->orphan(); reader->unref(); *entry = (PtexReader*)-1; // flag for future lookups return 0; } // successful open, record in _files map entry *entry = reader; // clean up unused files purgeFiles(); // Cleanup map every so often so it doesn't get HUGE // from being filled with blank entries from dead files. // Note: this must be done while we still have the open lock! if (++_cleanupCount >= 1000) { _cleanupCount = 0; removeBlankEntries(); } } return reader; }