int test_in_mod2 (int (*mainp)(int, char **)) { int (*ifp) (void); void *p; int result = 0; /* Find function `main'. */ p = dlsym (RTLD_DEFAULT, "main"); if (p == NULL) { printf ("%s: main not found\n", __FILE__); result = 1; } else if ((int (*)(int, char **))p != mainp) { printf ("%s: wrong address returned for main\n", __FILE__); result = 1; } else printf ("%s: main correctly found\n", __FILE__); ifp = dlsym (RTLD_DEFAULT, "found_in_mod1"); if ((void *) ifp == NULL) { printf ("%s: found_in_mod1 not found\n", __FILE__); result = 1; } else if (ifp () != 1) { printf ("%s: wrong address returned for found_in_mod1\n", __FILE__); result = 1; } else printf ("%s: found_in_mod1 correctly found\n", __FILE__); ifp = dlsym (RTLD_DEFAULT, "found_in_mod2"); if ((void *) ifp == NULL) { printf ("%s: found_in_mod2 not found\n", __FILE__); result = 1; } else if (ifp () != 2) { printf ("%s: wrong address returned for found_in_mod2\n", __FILE__); result = 1; } else printf ("%s: found_in_mod2 correctly found\n", __FILE__); return result; }
int main(void) { logger::edglog.open(std::clog, glite::wms::common::logger::debug); configuration::Configuration config(opt_conf_file, configuration::ModuleType::workload_manager); configuration::WMConfiguration const* const wm_config(config.wm()); configuration::NSConfiguration const* const ns_config(config.ns()); while (true) { purchaser::ism_ii_purchaser icp(ns_config->ii_contact(), ns_config->ii_port(), ns_config->ii_dn(), ns_config->ii_timeout(), purchaser::once); try { icp(); sleep(1); ism::call_update_ism_entries()(); ism::call_dump_ism_entries()(); std::string filename(ism::get_ism_dump()); purchaser::ism_file_purchaser ifp(filename); } catch(std::exception& e) { std::cerr << e.what() << std::endl; } } return 0; }
void icarus::routes::parser::parse(std::string inputFile, icarus::routes::document &data) { boost::filesystem::path ifp(inputFile); if (boost::filesystem::exists(ifp)) { std::ifstream *s; this->istream.reset(s = new std::ifstream()); std::ios_base::iostate exceptionMask = s->exceptions() | std::ios::failbit; s->exceptions(exceptionMask); try { s->open(ifp.string()); this->run_doc(data, 0); } catch (std::ios_base::failure &e) { throw icarus::open_file( (boost::locale::format(boost::locale::translate("Cannot open file '{1}'")) % ifp).str(), &e); } } else { throw icarus::file_not_found(ifp.string()); } }
void ExtractScummMac::execute() { Common::Filename inPath(_inputPaths[0].path); Common::Filename outPath(_outputPath); if (outPath.empty()) outPath.setFullPath("./"); Common::File ifp(inPath, "rb"); // Get the length of the data file to use for consistency checks uint32 dataFileLength = ifp.size(); // Read offset and length to the file records uint32 fileRecordOffset = ifp.readUint32BE(); uint32 fileRecordLength = ifp.readUint32BE(); // Do a quick check to make sure the offset and length are good if (fileRecordOffset + fileRecordLength > dataFileLength) error("File records out of bounds"); // Do a little consistancy check on fileRecordLength if (fileRecordLength % 0x28) error("File record length not multiple of 40"); // Extract the files for (uint32 i = 0; i < fileRecordLength; i += 0x28) { // read a file record ifp.seek(fileRecordOffset + i, SEEK_SET); uint32 fileOffset = ifp.readUint32BE(); uint32 fileLength = ifp.readUint32BE(); char fileName[0x21]; ifp.read_throwsOnError(fileName, 0x20); fileName[0x20] = 0; if (!fileName[0]) error("File has no name"); print("Extracting %s...", fileName); // Consistency check. make sure the file data is in the file if (fileOffset + fileLength > dataFileLength) error("File out of bounds"); // Write a file ifp.seek(fileOffset, SEEK_SET); outPath.setFullName(fileName); Common::File ofp(outPath, "wb"); byte *buf = new byte[fileLength]; ifp.read_throwsOnError(buf, fileLength); ofp.write(buf, fileLength); delete[] buf; } }
void IFPAnimationViewerWidget::reloadAnimationFile() { if (currentAnim) { currentAnim = NULL; } if (anpk) { delete anpk; anpk = NULL; } ui.animSlider->setEnabled(false); ui.animList->clear(); QString fname = ui.animField->text(); File file(fname.toLocal8Bit().constData()); if (!file.exists()) { Engine::StringResourceCache::Entry* entry = Engine::getInstance()->getAnimationCache() ->getEntryPointer(fname.toLocal8Bit().constData()).getEntry(); if (!entry) return; anpk = ((AnimationCacheEntry*) entry)->getPackage(); } else { anpk = new AnimationPackage; IFPLoader ifp(file); IFPAnimation* ianim; while ((ianim = ifp.readAnimation()) != NULL) { Animation* anim = new Animation(ianim); anpk->addAnimation(CString(ianim->getName()).lower(), anim); delete ianim; } } for (AnimationPackage::AnimIterator it = anpk->getAnimationBegin() ; it != anpk->getAnimationEnd() ; it++) { Animation* anim = it->second; CString animName = it->first; ui.animList->addItem(animName.get()); } StaticAnimationPackagePointer* anpkPtr = new StaticAnimationPackagePointer(anpk); renderWidget->setAnimationPackagePointer(anpkPtr); }
int main() { long long n,t,a,b; int i; char s[33],temp[33]; for (scanf("%lld",&n);n;n--) { scanf("%s",&s); sscanf(s,"%lld",&a); for (i=0;i<strlen(s);i++) temp[i]=s[strlen(s)-i-1]; temp[strlen(s)]='\0'; sscanf(temp,"%lld",&b); sprintf(s,"%lld",a+b); for (t=1;ifp(s);t++) { sscanf(s,"%lld",&a); for (i=0;i<strlen(s);i++) temp[i]=s[strlen(s)-i-1]; temp[strlen(s)]='\0'; sscanf(temp,"%lld",&b); sprintf(s,"%lld",a+b); } printf("%lld %s\n",t,s); } }
Engine::StringResourceCache::Entry* AnimationCacheLoader::load(CString key) { File* file = index->find(key); if (!file) return NULL; AnimationPackage* pkg = new AnimationPackage; IFPLoader ifp(*file); IFPAnimation* ianim; while ((ianim = ifp.readAnimation()) != NULL) { Animation* anim = new Animation(ianim); pkg->addAnimation(CString(ianim->getName()).lower(), anim); delete ianim; } AnimationCacheEntry* entry = new AnimationCacheEntry(pkg); return entry; }
int main(int argc, const char *argv[]) { // Needs 3 arguments if (argc != 4) { std::cout << "Usage: <manifest>[in] <c++ file>[out] <header>[out]" << std::endl; return 1; } std::cout << "Manifest: " << argv[1] << " CPP: " << argv[2] << " Header: " << argv[3] << std::endl; std::ifstream file_manifest(argv[1]); std::ofstream file_cpp(argv[2]); std::ofstream file_h(argv[3]); if (!file_manifest.good()) { std::cout << "Failed to open manifest" << std::endl; return 1; } if (!file_cpp.good()) { std::cout << "Failed to open output CPP file" << std::endl; return 1; } if (!file_h.good()) { std::cout << "Failed to open output H file" << std::endl; return 1; } // If the manifest has a path use that as the base for finding files. std::string manifest(argv[1]); std::string path_base; std::string::size_type pos = manifest.rfind('/'); if (pos != std::string::npos) { path_base = manifest.substr(0, pos+1); } file_cpp << "#include \"libresrc.h\"\n"; std::string file; while (std::getline(file_manifest, file)) { if (file.empty()) continue; std::ifstream ifp((path_base + file).c_str(), std::ios_base::binary); if (!ifp.is_open()) { std::cout << "Error opening file: " << file << std::endl; return 1; } clean(file); file_cpp << "const unsigned char " << file << "[] = {"; size_t length = 0; for (std::istreambuf_iterator<char> it(ifp), end; it != end; ++it) { if (length > 0) file_cpp << ","; file_cpp << (unsigned int)(unsigned char)*it; ++length; } file_cpp << "};\n"; file_h << "extern const unsigned char " << file << "[" << length << "];\n"; } return 0; }
void ExtractScummMac::execute() { unsigned long file_record_off, file_record_len; unsigned long file_off, file_len; unsigned long data_file_len; char file_name[0x20]; char *buf; unsigned long i; int j; Common::Filename inpath(_inputPaths[0].path); Common::Filename outpath(_outputPath); if (outpath.empty()) outpath.setFullPath("./"); Common::File ifp(inpath, "rb"); /* Get the length of the data file to use for consistency checks */ data_file_len = ifp.size(); /* Read offset and length to the file records */ file_record_off = ifp.readUint32BE(); file_record_len = ifp.readUint32BE(); /* Do a quick check to make sure the offset and length are good */ if (file_record_off + file_record_len > data_file_len) { error("\'%s\'. file records out of bounds.", inpath.getFullPath().c_str()); } /* Do a little consistancy check on file_record_length */ if (file_record_len % 0x28) { error("\'%s\'. file record length not multiple of 40.", inpath.getFullPath().c_str()); } /* Extract the files */ for (i = 0; i < file_record_len; i += 0x28) { /* read a file record */ ifp.seek(file_record_off + i, SEEK_SET); file_off = ifp.readUint32BE(); file_len = ifp.readUint32BE(); ifp.read_throwsOnError(file_name, 0x20); if (!file_name[0]) error("\'%s\'. file has no name.", inpath.getFullPath().c_str()); print("extracting \'%s\'", file_name); /* For convenience compatibility with scummvm (and case sensitive * file systems) change the file name to lowercase. * * if i ever add the ability to pass flags on the command * line, i will make this optional, but i really don't * see the point to bothering */ for (j = 0; j < 0x20; j++) { if (!file_name[j]) { break; } #ifdef CHANGECASE file_name[j] = tolower(file_name[j]); #endif } if (j == 0x20) { file_name[0x1f] = 0; warning("\'%s\'. file name not null terminated.", file_name); print("data file \'%s\' may be not a file extract_scumm_mac can extract.", inpath.getFullPath().c_str()); } print(", saving as \'%s\'", file_name); /* Consistency check. make sure the file data is in the file */ if (file_off + file_len > data_file_len) { error("\'%s\'. file out of bounds.", inpath.getFullPath().c_str()); } /* Write a file */ ifp.seek(file_off, SEEK_SET); outpath.setFullName(file_name); Common::File ofp(outpath, "wb"); if (!(buf = (char *)malloc(file_len))) { error("Could not allocate %ld bytes of memory.", file_len); } ifp.read_throwsOnError(buf, file_len); ofp.write(buf, file_len); free(buf); } }
stat Stats::TestBloomFilter(string fname_){ std::vector<string> urlsInList_ = BruteForce(fname_); std::vector<int> present_; //indicate the relevant url is in the list or not(according to bloom filter) std::vector<int> inList_; //indicate the relevant url is actually in the list or not std::ifstream ifp(fname_.c_str()); string line; int urlcount_ = 0; if(!ifp.good()){ cout<<"Can not open input data file"<<endl; } else{ do{ getline(ifp, line); if(line.size()<=f->urlLen_ && line.size()>=f->min_urlLen_ && line.size()>0) urlcount_++; Element * e = new Element(line); if(f->QueryElement(e)) present_.push_back(1); else present_.push_back(0); bool x = false; for (int i = 0; i < urlsInList_.size(); ++i) { if(line == urlsInList_[i]){ x = true; break; } } if(x) inList_.push_back(1); else inList_.push_back(0); }while(!ifp.eof()); } ifp.close(); double ffp_; double total_present = 0; double total_inlist = 0; for (int i = 0; i < present_.size(); ++i) { if(present_[i]==1) total_present++; if(inList_[i]==1) total_inlist++; } ffp_ = 1-(total_inlist/total_present); std::ofstream logfile("testresults.log",ios::app); logfile<<"Testing: "; logfile<<"out of "<<urlcount_<<";\n\n\ttotal present(according to BloomFilter): "<<total_present<<"\n\ttotal in list: "<<total_inlist<<"\n\tffp: "<<ffp_<<endl; logfile.close(); stat a; a.present = total_present; a.inList = total_inlist; a.ffp = ffp_; a.urlcount = urlcount_; return a; }