void make_header(FILE *file, int commands, int data) { char command_num[MAX_LINE_SIZE], data_num[MAX_LINE_SIZE]; int num = commands - 100; in_base(num, 4, command_num); in_base(data, 4, data_num); fprintf(file, "%s %s\n", command_num, data_num); }
void make_file(int IC, FILE *data_file, FILE *final_file) { char data_line[MAX_LINE_SIZE], address[MAX_LINE_SIZE]; reset_str(address, MAX_LINE_SIZE); reset_str(data_line, MAX_LINE_SIZE); rewind(data_file); while (!feof(data_file)) { reset_str(data_line, MAX_LINE_SIZE); fgets(data_line, MAX_LINE_SIZE, data_file); in_base(IC, 4, address); if (data_line[0] != '\0') fprintf(final_file, "%s %s", address, data_line); IC++; } }
bool scan(CommandLine &CmdL) { pkgCacheFile Cache; OpTextProgress Prog(*_config); if (!Cache.BuildCaches(&Prog, false)) return false; if (!Cache.BuildPolicy(&Prog)) return false; // remember original current and candidate versions std::vector<scan_info> info(Cache.GetPkgCache()->Head().PackageCount); for (pkgCache::PkgIterator pkg = Cache.GetPkgCache()->PkgBegin(); !pkg.end(); ++pkg) { info[pkg->ID].orig_cur = pkg.CurrentVer(); info[pkg->ID].orig_cand = Cache.GetPolicy()->GetCandidateVer(pkg); } // read in our state APT::PackageList no; APT::VersionList yes; pkgCache::State::VerPriority reference_priority = pkgCache::State::Required; { APT::CacheSetHelper helper; read_file(_config->FindFile("Disposal::State::No", "no.txt").c_str(), [&](const std::string &s) { helper.PackageFrom(APT::CacheSetHelper::STRING, &no, Cache, s); }); read_file(_config->FindFile("Disposal::State::Yes", "yes.txt").c_str(), [&](const std::string &s) { // hhhh debian's "standard" task is done by priority if (s == "Priority: required") { reference_priority = pkgCache::State::Required; return; } else if (s == "Priority: important") { reference_priority = pkgCache::State::Important; return; } else if (s == "Priority: standard") { reference_priority = pkgCache::State::Standard; return; } APT::VersionContainerInterface::FromString(&yes, Cache, s, APT::CacheSetHelper::CANDIDATE, helper); }); // show messages from packages not found, but don't bail _error->DumpErrors(); } // pretend nothing is installed for (pkgCache::PkgIterator pkg = Cache.GetPkgCache()->PkgBegin(); !pkg.end(); ++pkg) { pkg->CurrentVer = 0; } if (!Cache.BuildDepCache(&Prog)) return false; { pkgDepCache::ActionGroup group(Cache); pkgProblemResolver Fix(Cache); APT::PackageSet autoInstall; // fill in the original candidate versions for (pkgCache::PkgIterator pkg = Cache.GetPkgCache()->PkgBegin(); !pkg.end(); ++pkg) { if (info[pkg->ID].orig_cand != NULL) { Cache->SetCandidateVersion(pkgCache::VerIterator(Cache, info[pkg->ID].orig_cand)); } } // shallow-install base packages for (pkgCache::PkgIterator pkg = Cache.GetPkgCache()->PkgBegin(); !pkg.end(); ++pkg) { if (in_base(Cache, pkg, reference_priority)) { Fix.Protect(pkg); Cache->MarkInstall(pkg, false); autoInstall.insert(pkg); } } // prevent install of "no" packages for (const pkgCache::PkgIterator pkg : no) { info[pkg->ID].in_no = true; Fix.Protect(pkg); Fix.Remove(pkg); Cache->MarkProtected(pkg); } // shallow-install the "yes" packages for (const pkgCache::VerIterator ver : yes) { const pkgCache::PkgIterator pkg = ver.ParentPkg(); info[pkg->ID].in_yes = true; Fix.Protect(pkg); Cache->SetCandidateVersion(ver); Cache->MarkInstall(pkg, false); autoInstall.insert(pkg); } // install everyone's dependencies for (const pkgCache::PkgIterator pkg : autoInstall) { if (Cache[pkg].InstBroken() || Cache[pkg].InstPolicyBroken()) Cache->MarkInstall(pkg); } // problems happen all the time Fix.Resolve(); } if (Cache->BrokenCount() != 0) { std::cerr << Cache->BrokenCount() << " broken" << std::endl; } // the problem resolver might decide not to install a package we recursively marked for installation // it doesn't recursively unmark that package's dependencies { pkgDepCache::ActionGroup group(Cache); for (pkgCache::PkgIterator pkg = Cache.GetPkgCache()->PkgBegin(); !pkg.end(); ++pkg) { if (Cache[pkg].Garbage) { Cache->MarkDelete(pkg, false, 0, false); } } } // DoAutoRemove in private-install.cc does stuff when BrokenCount or PolicyBrokenCount are nonzero // restore current state for (pkgCache::PkgIterator pkg = Cache.GetPkgCache()->PkgBegin(); !pkg.end(); ++pkg) { pkg->CurrentVer = info[pkg->ID].orig_cur == NULL ? 0 : info[pkg->ID].orig_cur - Cache.GetPkgCache()->VerP; pkgDepCache::StateCache &P = Cache[pkg]; if (P.InstallVer == pkg.CurrentVer()) P.Mode = pkgDepCache::ModeKeep; else if (P.InstallVer == NULL && pkg.CurrentVer().IsGood()) P.Mode = pkgDepCache::ModeDelete; P.Update(pkg, Cache); } Cache->Update(); // compare with simulation bool silence = true; for (pkgCache::PkgIterator pkg = Cache.GetPkgCache()->PkgBegin(); !pkg.end(); ++pkg) { pkgDepCache::StateCache &P = Cache[pkg]; if (P.NewInstall()) { if (!notable_new_install(Cache, info, pkg)) std::cout << " "; std::cout << pkg.Name() << '+' << std::endl; silence = false; } else if (P.Delete()) { if (!notable_remove(Cache, info, pkg)) std::cout << " "; std::cout << pkg.Name() << '-' << std::endl; silence = false; } } if (silence) std::cerr << "no changes" << std::endl; return true; }