apt-cache.cc 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682
  1. // -*- mode: cpp; mode: fold -*-
  2. // Description /*{{{*/
  3. // $Id: apt-cache.cc,v 1.33 1999/04/12 04:21:20 jgg Exp $
  4. /* ######################################################################
  5. apt-cache - Manages the cache files
  6. apt-cache provides some functions fo manipulating the cache files.
  7. It uses the command line interface common to all the APT tools. The
  8. only really usefull function right now is dumpavail which is used
  9. by the dselect method. Everything else is ment as a debug aide.
  10. Returns 100 on failure, 0 on success.
  11. ##################################################################### */
  12. /*}}}*/
  13. // Include Files /*{{{*/
  14. #include <apt-pkg/error.h>
  15. #include <apt-pkg/pkgcachegen.h>
  16. #include <apt-pkg/deblistparser.h>
  17. #include <apt-pkg/init.h>
  18. #include <apt-pkg/progress.h>
  19. #include <apt-pkg/sourcelist.h>
  20. #include <apt-pkg/cmndline.h>
  21. #include <apt-pkg/strutl.h>
  22. #include <apt-pkg/pkgrecords.h>
  23. #include <config.h>
  24. #include <iostream.h>
  25. #include <unistd.h>
  26. #include <errno.h>
  27. #include <regex.h>
  28. /*}}}*/
  29. pkgCache *GCache = 0;
  30. // UnMet - Show unmet dependencies /*{{{*/
  31. // ---------------------------------------------------------------------
  32. /* */
  33. bool UnMet(CommandLine &CmdL)
  34. {
  35. pkgCache &Cache = *GCache;
  36. bool Important = _config->FindB("APT::Cache::Important",false);
  37. for (pkgCache::PkgIterator P = Cache.PkgBegin(); P.end() == false; P++)
  38. {
  39. for (pkgCache::VerIterator V = P.VersionList(); V.end() == false; V++)
  40. {
  41. bool Header = false;
  42. for (pkgCache::DepIterator D = V.DependsList(); D.end() == false;)
  43. {
  44. // Collect or groups
  45. pkgCache::DepIterator Start;
  46. pkgCache::DepIterator End;
  47. D.GlobOr(Start,End);
  48. /* cout << "s: Check " << Start.TargetPkg().Name() << ',' <<
  49. End.TargetPkg().Name() << endl;*/
  50. // Skip conflicts and replaces
  51. if (End->Type != pkgCache::Dep::PreDepends &&
  52. End->Type != pkgCache::Dep::Depends &&
  53. End->Type != pkgCache::Dep::Suggests &&
  54. End->Type != pkgCache::Dep::Recommends)
  55. continue;
  56. // Important deps only
  57. if (Important == true)
  58. if (End->Type != pkgCache::Dep::PreDepends &&
  59. End->Type != pkgCache::Dep::Depends)
  60. continue;
  61. // Verify the or group
  62. bool OK = false;
  63. pkgCache::DepIterator RealStart = Start;
  64. do
  65. {
  66. // See if this dep is Ok
  67. pkgCache::Version **VList = Start.AllTargets();
  68. if (*VList != 0)
  69. {
  70. OK = true;
  71. delete [] VList;
  72. break;
  73. }
  74. delete [] VList;
  75. if (Start == End)
  76. break;
  77. Start++;
  78. }
  79. while (1);
  80. // The group is OK
  81. if (OK == true)
  82. continue;
  83. // Oops, it failed..
  84. if (Header == false)
  85. cout << "Package " << P.Name() << " version " <<
  86. V.VerStr() << " has an unmet dep:" << endl;
  87. Header = true;
  88. // Print out the dep type
  89. cout << " " << End.DepType() << ": ";
  90. // Show the group
  91. Start = RealStart;
  92. do
  93. {
  94. cout << Start.TargetPkg().Name();
  95. if (Start.TargetVer() != 0)
  96. cout << " (" << Start.CompType() << " " << Start.TargetVer() <<
  97. ")";
  98. if (Start == End)
  99. break;
  100. cout << " | ";
  101. Start++;
  102. }
  103. while (1);
  104. cout << endl;
  105. }
  106. }
  107. }
  108. return true;
  109. }
  110. /*}}}*/
  111. // DumpPackage - Show a dump of a package record /*{{{*/
  112. // ---------------------------------------------------------------------
  113. /* */
  114. bool DumpPackage(CommandLine &CmdL)
  115. {
  116. pkgCache &Cache = *GCache;
  117. for (const char **I = CmdL.FileList + 1; *I != 0; I++)
  118. {
  119. pkgCache::PkgIterator Pkg = Cache.FindPkg(*I);
  120. if (Pkg.end() == true)
  121. {
  122. _error->Warning("Unable to locate package %s",*I);
  123. continue;
  124. }
  125. cout << "Package: " << Pkg.Name() << endl;
  126. cout << "Versions: ";
  127. for (pkgCache::VerIterator Cur = Pkg.VersionList(); Cur.end() != true; Cur++)
  128. {
  129. cout << Cur.VerStr();
  130. for (pkgCache::VerFileIterator Vf = Cur.FileList(); Vf.end() == false; Vf++)
  131. cout << "(" << Vf.File().FileName() << ")";
  132. cout << ',';
  133. }
  134. cout << endl;
  135. cout << "Reverse Depends: " << endl;
  136. for (pkgCache::DepIterator D = Pkg.RevDependsList(); D.end() != true; D++)
  137. cout << " " << D.ParentPkg().Name() << ',' << D.TargetPkg().Name() << endl;
  138. cout << "Dependencies: " << endl;
  139. for (pkgCache::VerIterator Cur = Pkg.VersionList(); Cur.end() != true; Cur++)
  140. {
  141. cout << Cur.VerStr() << " - ";
  142. for (pkgCache::DepIterator Dep = Cur.DependsList(); Dep.end() != true; Dep++)
  143. cout << Dep.TargetPkg().Name() << " (" << (int)Dep->CompareOp << " " << Dep.TargetVer() << ") ";
  144. cout << endl;
  145. }
  146. cout << "Provides: " << endl;
  147. for (pkgCache::VerIterator Cur = Pkg.VersionList(); Cur.end() != true; Cur++)
  148. {
  149. cout << Cur.VerStr() << " - ";
  150. for (pkgCache::PrvIterator Prv = Cur.ProvidesList(); Prv.end() != true; Prv++)
  151. cout << Prv.ParentPkg().Name() << " ";
  152. cout << endl;
  153. }
  154. cout << "Reverse Provides: " << endl;
  155. for (pkgCache::PrvIterator Prv = Pkg.ProvidesList(); Prv.end() != true; Prv++)
  156. cout << Prv.OwnerPkg().Name() << " " << Prv.OwnerVer().VerStr();
  157. cout << endl;
  158. }
  159. return true;
  160. }
  161. /*}}}*/
  162. // Stats - Dump some nice statistics /*{{{*/
  163. // ---------------------------------------------------------------------
  164. /* */
  165. bool Stats(CommandLine &Cmd)
  166. {
  167. pkgCache &Cache = *GCache;
  168. cout << "Total Package Names : " << Cache.Head().PackageCount << " (" <<
  169. SizeToStr(Cache.Head().PackageCount*Cache.Head().PackageSz) << ')' << endl;
  170. pkgCache::PkgIterator I = Cache.PkgBegin();
  171. int Normal = 0;
  172. int Virtual = 0;
  173. int NVirt = 0;
  174. int DVirt = 0;
  175. int Missing = 0;
  176. for (;I.end() != true; I++)
  177. {
  178. if (I->VersionList != 0 && I->ProvidesList == 0)
  179. {
  180. Normal++;
  181. continue;
  182. }
  183. if (I->VersionList != 0 && I->ProvidesList != 0)
  184. {
  185. NVirt++;
  186. continue;
  187. }
  188. if (I->VersionList == 0 && I->ProvidesList != 0)
  189. {
  190. // Only 1 provides
  191. if (I.ProvidesList()->NextProvides == 0)
  192. {
  193. DVirt++;
  194. }
  195. else
  196. Virtual++;
  197. continue;
  198. }
  199. if (I->VersionList == 0 && I->ProvidesList == 0)
  200. {
  201. Missing++;
  202. continue;
  203. }
  204. }
  205. cout << " Normal Packages: " << Normal << endl;
  206. cout << " Pure Virtual Packages: " << Virtual << endl;
  207. cout << " Single Virtual Packages: " << DVirt << endl;
  208. cout << " Mixed Virtual Packages: " << NVirt << endl;
  209. cout << " Missing: " << Missing << endl;
  210. cout << "Total Distinct Versions: " << Cache.Head().VersionCount << " (" <<
  211. SizeToStr(Cache.Head().VersionCount*Cache.Head().VersionSz) << ')' << endl;
  212. cout << "Total Dependencies: " << Cache.Head().DependsCount << " (" <<
  213. SizeToStr(Cache.Head().DependsCount*Cache.Head().DependencySz) << ')' << endl;
  214. cout << "Total Ver/File relations: " << Cache.Head().VerFileCount << " (" <<
  215. SizeToStr(Cache.Head().VerFileCount*Cache.Head().VerFileSz) << ')' << endl;
  216. cout << "Total Provides Mappings: " << Cache.Head().ProvidesCount << " (" <<
  217. SizeToStr(Cache.Head().ProvidesCount*Cache.Head().ProvidesSz) << ')' << endl;
  218. // String list stats
  219. unsigned long Size = 0;
  220. unsigned long Count = 0;
  221. for (pkgCache::StringItem *I = Cache.StringItemP + Cache.Head().StringList;
  222. I!= Cache.StringItemP; I = Cache.StringItemP + I->NextItem)
  223. {
  224. Count++;
  225. Size += strlen(Cache.StrP + I->String);
  226. }
  227. cout << "Total Globbed Strings: " << Count << " (" << SizeToStr(Size) << ')' << endl;
  228. unsigned long Slack = 0;
  229. for (int I = 0; I != 7; I++)
  230. Slack += Cache.Head().Pools[I].ItemSize*Cache.Head().Pools[I].Count;
  231. cout << "Total Slack space: " << SizeToStr(Slack) << endl;
  232. unsigned long Total = 0;
  233. Total = Slack + Size + Cache.Head().DependsCount*Cache.Head().DependencySz +
  234. Cache.Head().VersionCount*Cache.Head().VersionSz +
  235. Cache.Head().PackageCount*Cache.Head().PackageSz +
  236. Cache.Head().VerFileCount*Cache.Head().VerFileSz +
  237. Cache.Head().ProvidesCount*Cache.Head().ProvidesSz;
  238. cout << "Total Space Accounted for: " << SizeToStr(Total) << endl;
  239. return true;
  240. }
  241. /*}}}*/
  242. // Check - Check some things about the cache /*{{{*/
  243. // ---------------------------------------------------------------------
  244. /* Debug aide mostly */
  245. bool Check(CommandLine &Cmd)
  246. {
  247. pkgCache &Cache = *GCache;
  248. pkgCache::PkgIterator Pkg = Cache.PkgBegin();
  249. for (;Pkg.end() != true; Pkg++)
  250. {
  251. if (Pkg.Section() == 0 && Pkg->VersionList != 0)
  252. cout << "Bad section " << Pkg.Name() << endl;
  253. for (pkgCache::VerIterator Cur = Pkg.VersionList();
  254. Cur.end() != true; Cur++)
  255. {
  256. if (Cur->Priority < 1 || Cur->Priority > 5)
  257. cout << "Bad prio " << Pkg.Name() << ',' << Cur.VerStr() << " == " << (int)Cur->Priority << endl;
  258. }
  259. }
  260. return true;
  261. }
  262. /*}}}*/
  263. // Dump - show everything /*{{{*/
  264. // ---------------------------------------------------------------------
  265. /* */
  266. bool Dump(CommandLine &Cmd)
  267. {
  268. pkgCache &Cache = *GCache;
  269. for (pkgCache::PkgIterator P = Cache.PkgBegin(); P.end() == false; P++)
  270. {
  271. cout << "Package: " << P.Name() << endl;
  272. for (pkgCache::VerIterator V = P.VersionList(); V.end() == false; V++)
  273. {
  274. cout << " Version: " << V.VerStr() << endl;
  275. cout << " File: " << V.FileList().File().FileName() << endl;
  276. for (pkgCache::DepIterator D = V.DependsList(); D.end() == false; D++)
  277. cout << " Depends: " << D.TargetPkg().Name() << ' ' << D.TargetVer() << endl;
  278. }
  279. }
  280. for (pkgCache::PkgFileIterator F(Cache); F.end() == false; F++)
  281. {
  282. cout << "File: " << F.FileName() << endl;
  283. cout << " Size: " << F->Size << endl;
  284. cout << " ID: " << F->ID << endl;
  285. cout << " Flags: " << F->Flags << endl;
  286. cout << " Time: " << TimeRFC1123(F->mtime) << endl;
  287. cout << " Archive: " << F.Archive() << endl;
  288. cout << " Component: " << F.Component() << endl;
  289. cout << " Version: " << F.Version() << endl;
  290. cout << " Origin: " << F.Origin() << endl;
  291. cout << " Label: " << F.Label() << endl;
  292. cout << " Architecture: " << F.Architecture() << endl;
  293. }
  294. return true;
  295. }
  296. /*}}}*/
  297. // DumpAvail - Print out the available list /*{{{*/
  298. // ---------------------------------------------------------------------
  299. /* This is needed to make dpkg --merge happy */
  300. bool DumpAvail(CommandLine &Cmd)
  301. {
  302. pkgCache &Cache = *GCache;
  303. unsigned char *Buffer = new unsigned char[Cache.HeaderP->MaxVerFileSize];
  304. for (pkgCache::PkgFileIterator I = Cache.FileBegin(); I.end() == false; I++)
  305. {
  306. if ((I->Flags & pkgCache::Flag::NotSource) != 0)
  307. continue;
  308. if (I.IsOk() == false)
  309. {
  310. delete [] Buffer;
  311. return _error->Error("Package file %s is out of sync.",I.FileName());
  312. }
  313. FileFd PkgF(I.FileName(),FileFd::ReadOnly);
  314. if (_error->PendingError() == true)
  315. {
  316. delete [] Buffer;
  317. return false;
  318. }
  319. /* Write all of the records from this package file, we search the entire
  320. structure to find them */
  321. for (pkgCache::PkgIterator P = Cache.PkgBegin(); P.end() == false; P++)
  322. {
  323. // Find the proper version to use. We should probably use the DepCache.
  324. pkgCache::VerIterator V = Cache.GetCandidateVer(P,false);
  325. if (V.end() == true || V.FileList().File() != I)
  326. continue;
  327. // Read the record and then write it out again.
  328. if (PkgF.Seek(V.FileList()->Offset) == false ||
  329. PkgF.Read(Buffer,V.FileList()->Size) == false ||
  330. write(STDOUT_FILENO,Buffer,V.FileList()->Size) != V.FileList()->Size)
  331. {
  332. delete [] Buffer;
  333. return false;
  334. }
  335. }
  336. }
  337. return true;
  338. }
  339. /*}}}*/
  340. // DoAdd - Perform an adding operation /*{{{*/
  341. // ---------------------------------------------------------------------
  342. /* */
  343. bool DoAdd(CommandLine &CmdL)
  344. {
  345. // Make sure there is at least one argument
  346. if (CmdL.FileSize() <= 1)
  347. return _error->Error("You must give at least one file name");
  348. // Open the cache
  349. FileFd CacheF(_config->FindFile("Dir::Cache::pkgcache"),FileFd::WriteAny);
  350. if (_error->PendingError() == true)
  351. return false;
  352. DynamicMMap Map(CacheF,MMap::Public);
  353. if (_error->PendingError() == true)
  354. return false;
  355. OpTextProgress Progress(*_config);
  356. pkgCacheGenerator Gen(Map,Progress);
  357. if (_error->PendingError() == true)
  358. return false;
  359. unsigned long Length = CmdL.FileSize() - 1;
  360. for (const char **I = CmdL.FileList + 1; *I != 0; I++)
  361. {
  362. Progress.OverallProgress(I - CmdL.FileList,Length,1,"Generating cache");
  363. Progress.SubProgress(Length);
  364. // Do the merge
  365. FileFd TagF(*I,FileFd::ReadOnly);
  366. debListParser Parser(TagF);
  367. if (_error->PendingError() == true)
  368. return _error->Error("Problem opening %s",*I);
  369. if (Gen.SelectFile(*I) == false)
  370. return _error->Error("Problem with SelectFile");
  371. if (Gen.MergeList(Parser) == false)
  372. return _error->Error("Problem with MergeList");
  373. }
  374. Progress.Done();
  375. GCache = &Gen.GetCache();
  376. Stats(CmdL);
  377. return true;
  378. }
  379. /*}}}*/
  380. // DisplayRecord - Displays the complete record for the package /*{{{*/
  381. // ---------------------------------------------------------------------
  382. /* This displays the package record from the proper package index file.
  383. It is not used by DumpAvail for performance reasons. */
  384. bool DisplayRecord(pkgCache::VerIterator V)
  385. {
  386. // Find an appropriate file
  387. pkgCache::VerFileIterator Vf = V.FileList();
  388. for (; Vf.end() == false; Vf++)
  389. if ((Vf.File()->Flags & pkgCache::Flag::NotSource) == 0)
  390. break;
  391. if (Vf.end() == true)
  392. Vf = V.FileList();
  393. // Check and load the package list file
  394. pkgCache::PkgFileIterator I = Vf.File();
  395. if (I.IsOk() == false)
  396. return _error->Error("Package file %s is out of sync.",I.FileName());
  397. FileFd PkgF(I.FileName(),FileFd::ReadOnly);
  398. if (_error->PendingError() == true)
  399. return false;
  400. // Read the record and then write it out again.
  401. unsigned char *Buffer = new unsigned char[GCache->HeaderP->MaxVerFileSize];
  402. if (PkgF.Seek(V.FileList()->Offset) == false ||
  403. PkgF.Read(Buffer,V.FileList()->Size) == false ||
  404. write(STDOUT_FILENO,Buffer,V.FileList()->Size) != V.FileList()->Size)
  405. {
  406. delete [] Buffer;
  407. return false;
  408. }
  409. delete [] Buffer;
  410. return true;
  411. }
  412. /*}}}*/
  413. // Search - Perform a search /*{{{*/
  414. // ---------------------------------------------------------------------
  415. /* This searches the package names and pacakge descriptions for a pattern */
  416. bool Search(CommandLine &CmdL)
  417. {
  418. pkgCache &Cache = *GCache;
  419. bool ShowFull = _config->FindB("APT::Cache::ShowFull",false);
  420. bool NamesOnly = _config->FindB("APT::Cache::NamesOnly",false);
  421. // Make sure there is at least one argument
  422. if (CmdL.FileSize() != 2)
  423. return _error->Error("You must give exactly one pattern");
  424. // Compile the regex pattern
  425. regex_t Pattern;
  426. if (regcomp(&Pattern,CmdL.FileList[1],REG_EXTENDED | REG_ICASE |
  427. REG_NOSUB) != 0)
  428. return _error->Error("Regex compilation error");
  429. // Create the text record parser
  430. pkgRecords Recs(Cache);
  431. if (_error->PendingError() == true)
  432. return false;
  433. // Search package names
  434. pkgCache::PkgIterator I = Cache.PkgBegin();
  435. for (;I.end() != true; I++)
  436. {
  437. // We search against the install version as that makes the most sense..
  438. pkgCache::VerIterator V = Cache.GetCandidateVer(I);
  439. if (V.end() == true)
  440. continue;
  441. pkgRecords::Parser &P = Recs.Lookup(V.FileList());
  442. if (regexec(&Pattern,I.Name(),0,0,0) == 0 ||
  443. (NamesOnly == false &&
  444. regexec(&Pattern,P.LongDesc().c_str(),0,0,0) == 0))
  445. {
  446. if (ShowFull == true)
  447. DisplayRecord(V);
  448. else
  449. cout << I.Name() << " - " << P.ShortDesc() << endl;
  450. }
  451. }
  452. regfree(&Pattern);
  453. return true;
  454. }
  455. /*}}}*/
  456. // ShowPackage - Dump the package record to the screen /*{{{*/
  457. // ---------------------------------------------------------------------
  458. /* */
  459. bool ShowPackage(CommandLine &CmdL)
  460. {
  461. pkgCache &Cache = *GCache;
  462. for (const char **I = CmdL.FileList + 1; *I != 0; I++)
  463. {
  464. pkgCache::PkgIterator Pkg = Cache.FindPkg(*I);
  465. if (Pkg.end() == true)
  466. {
  467. _error->Warning("Unable to locate package %s",*I);
  468. continue;
  469. }
  470. // Find the proper version to use. We should probably use the DepCache.
  471. pkgCache::VerIterator V = Cache.GetCandidateVer(Pkg);
  472. if (V.end() == true || V.FileList().end() == true)
  473. continue;
  474. if (DisplayRecord(V) == false)
  475. return false;
  476. }
  477. return true;
  478. }
  479. /*}}}*/
  480. // GenCaches - Call the main cache generator /*{{{*/
  481. // ---------------------------------------------------------------------
  482. /* */
  483. bool GenCaches(CommandLine &Cmd)
  484. {
  485. OpTextProgress Progress(*_config);
  486. pkgSourceList List;
  487. List.ReadMainList();
  488. return pkgMakeStatusCache(List,Progress);
  489. }
  490. /*}}}*/
  491. // ShowHelp - Show a help screen /*{{{*/
  492. // ---------------------------------------------------------------------
  493. /* */
  494. bool ShowHelp(CommandLine &Cmd)
  495. {
  496. cout << PACKAGE << ' ' << VERSION << " for " << ARCHITECTURE <<
  497. " compiled on " << __DATE__ << " " << __TIME__ << endl;
  498. if (_config->FindB("version") == true)
  499. return 100;
  500. cout << "Usage: apt-cache [options] command" << endl;
  501. cout << " apt-cache [options] add file1 [file1 ...]" << endl;
  502. cout << " apt-cache [options] showpkg pkg1 [pkg2 ...]" << endl;
  503. cout << endl;
  504. cout << "apt-cache is a low-level tool used to manipulate APT's binary" << endl;
  505. cout << "cache files stored in " << _config->FindFile("Dir::Cache") << endl;
  506. cout << "It is not ment for ordinary use only as a debug aide." << endl;
  507. cout << endl;
  508. cout << "Commands:" << endl;
  509. cout << " add - Add an package file to the source cache" << endl;
  510. cout << " gencaches - Build both the package and source cache" << endl;
  511. cout << " showpkg - Show some general information for a single package" << endl;
  512. cout << " stats - Show some basic statistics" << endl;
  513. cout << " dump - Show the entire file in a terse form" << endl;
  514. cout << " dumpavail - Print an available file to stdout" << endl;
  515. cout << " unmet - Show unmet dependencies" << endl;
  516. cout << " check - Check the cache a bit" << endl;
  517. cout << " search - Search the package list for a regex pattern" << endl;
  518. cout << " show - Show a readable record for the package" << endl;
  519. cout << endl;
  520. cout << "Options:" << endl;
  521. cout << " -h This help text." << endl;
  522. cout << " -p=? The package cache. [" << _config->FindFile("Dir::Cache::pkgcache") << ']' << endl;
  523. cout << " -s=? The source cache. [" << _config->FindFile("Dir::Cache::srcpkgcache") << ']' << endl;
  524. cout << " -q Disable progress indicator." << endl;
  525. cout << " -i Show only important deps for the unmet command." << endl;
  526. cout << " -c=? Read this configuration file" << endl;
  527. cout << " -o=? Set an arbitary configuration option, eg -o dir::cache=/tmp" << endl;
  528. cout << "See the apt-cache(8) and apt.conf(5) manual pages for more information." << endl;
  529. return 100;
  530. }
  531. /*}}}*/
  532. // CacheInitialize - Initialize things for apt-cache /*{{{*/
  533. // ---------------------------------------------------------------------
  534. /* */
  535. void CacheInitialize()
  536. {
  537. _config->Set("quiet",0);
  538. _config->Set("help",false);
  539. }
  540. /*}}}*/
  541. int main(int argc,const char *argv[])
  542. {
  543. CommandLine::Args Args[] = {
  544. {'h',"help","help",0},
  545. {'v',"version","version",0},
  546. {'p',"pkg-cache","Dir::Cache::pkgcache",CommandLine::HasArg},
  547. {'s',"src-cache","Dir::Cache::srcpkgcache",CommandLine::HasArg},
  548. {'q',"quiet","quiet",CommandLine::IntLevel},
  549. {'i',"important","APT::Cache::Important",0},
  550. {'f',"full","APT::Cache::ShowFull",0},
  551. {0,"names-only","APT::Cache::NamesOnly",0},
  552. {'c',"config-file",0,CommandLine::ConfigFile},
  553. {'o',"option",0,CommandLine::ArbItem},
  554. {0,0,0,0}};
  555. CommandLine::Dispatch CmdsA[] = {{"help",&ShowHelp},
  556. {"add",&DoAdd},
  557. {"gencaches",&GenCaches},
  558. {0,0}};
  559. CommandLine::Dispatch CmdsB[] = {{"showpkg",&DumpPackage},
  560. {"stats",&Stats},
  561. {"dump",&Dump},
  562. {"dumpavail",&DumpAvail},
  563. {"unmet",&UnMet},
  564. {"check",&Check},
  565. {"search",&Search},
  566. {"show",&ShowPackage},
  567. {0,0}};
  568. CacheInitialize();
  569. // Parse the command line and initialize the package library
  570. CommandLine CmdL(Args,_config);
  571. if (pkgInitialize(*_config) == false ||
  572. CmdL.Parse(argc,argv) == false)
  573. {
  574. _error->DumpErrors();
  575. return 100;
  576. }
  577. // See if the help should be shown
  578. if (_config->FindB("help") == true ||
  579. CmdL.FileSize() == 0)
  580. return ShowHelp(CmdL);
  581. // Deal with stdout not being a tty
  582. if (ttyname(STDOUT_FILENO) == 0 && _config->FindI("quiet",0) < 1)
  583. _config->Set("quiet","1");
  584. if (CmdL.DispatchArg(CmdsA,false) == false && _error->PendingError() == false)
  585. {
  586. // Open the cache file
  587. FileFd CacheF(_config->FindFile("Dir::Cache::pkgcache"),FileFd::ReadOnly);
  588. MMap Map(CacheF,MMap::Public | MMap::ReadOnly);
  589. if (_error->PendingError() == false)
  590. {
  591. pkgCache Cache(Map);
  592. GCache = &Cache;
  593. if (_error->PendingError() == false)
  594. CmdL.DispatchArg(CmdsB);
  595. }
  596. }
  597. // Print any errors or warnings found during parsing
  598. if (_error->empty() == false)
  599. {
  600. bool Errors = _error->PendingError();
  601. _error->DumpErrors();
  602. return Errors == true?100:0;
  603. }
  604. return 0;
  605. }