]>
git.saurik.com Git - apt.git/blob - cmdline/apt-get.cc
d9aa9cebe4d9841db84e9c160518e158ee772e37
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: apt-get.cc,v 1.6 1998/11/11 23:45:56 jgg Exp $
4 /* ######################################################################
6 apt-get - Cover for dpkg
8 This is an allout cover for dpkg implementing a safer front end. It is
9 based largely on libapt-pkg.
11 The syntax is different,
12 apt-get [opt] command [things]
14 update - Resyncronize the package files from their sources
15 upgrade - Smart-Download the newest versions of all packages
16 dselect-upgrade - Follows dselect's changes to the Status: field
17 and installes new and removes old packages
18 dist-upgrade - Powerfull upgrader designed to handle the issues with
20 install - Download and install a given package (by name, not by .deb)
21 check - Update the package cache and check for broken packages
22 clean - Erase the .debs downloaded to /var/cache/apt/archives and
25 ##################################################################### */
27 // Include Files /*{{{*/
28 #include <apt-pkg/error.h>
29 #include <apt-pkg/cmndline.h>
30 #include <apt-pkg/init.h>
31 #include <apt-pkg/depcache.h>
32 #include <apt-pkg/sourcelist.h>
33 #include <apt-pkg/pkgcachegen.h>
34 #include <apt-pkg/algorithms.h>
35 #include <apt-pkg/acquire-item.h>
39 #include "acqprogress.h"
47 ofstream
devnull("/dev/null");
48 unsigned int ScreenWidth
= 80;
50 // ShowList - Show a list /*{{{*/
51 // ---------------------------------------------------------------------
52 /* This prints out a string of space seperated words with a title and
53 a two space indent line wraped to the current screen width. */
54 void ShowList(ostream
&out
,string Title
,string List
)
56 if (List
.empty() == true)
59 // Acount for the leading space
60 int ScreenWidth
= ::ScreenWidth
- 3;
63 string::size_type Start
= 0;
64 while (Start
< List
.size())
66 string::size_type End
;
67 if (Start
+ ScreenWidth
>= List
.size())
70 End
= List
.rfind(' ',Start
+ScreenWidth
);
72 if (End
== string::npos
|| End
< Start
)
73 End
= Start
+ ScreenWidth
;
74 out
<< " " << string(List
,Start
,End
- Start
) << endl
;
79 // ShowBroken - Debugging aide /*{{{*/
80 // ---------------------------------------------------------------------
81 /* This prints out the names of all the packages that are broken along
82 with the name of each each broken dependency and a quite version
84 void ShowBroken(ostream
&out
,pkgDepCache
&Cache
)
86 out
<< "Sorry, but the following packages are broken - this means they have unmet" << endl
;
87 out
<< "dependencies:" << endl
;
88 pkgCache::PkgIterator I
= Cache
.PkgBegin();
89 for (;I
.end() != true; I
++)
91 if (Cache
[I
].InstBroken() == false)
94 // Print out each package and the failed dependencies
95 out
<<" " << I
.Name() << ":";
96 int Indent
= strlen(I
.Name()) + 3;
98 if (Cache
[I
].InstVerIter(Cache
).end() == true)
104 for (pkgCache::DepIterator D
= Cache
[I
].InstVerIter(Cache
).DependsList(); D
.end() == false; D
++)
106 if (Cache
.IsImportantDep(D
) == false || (Cache
[D
] &
107 pkgDepCache::DepInstall
) != 0)
111 for (int J
= 0; J
!= Indent
; J
++)
115 if (D
->Type
== pkgCache::Dep::Conflicts
)
116 out
<< " Conflicts:" << D
.TargetPkg().Name();
118 out
<< " Depends:" << D
.TargetPkg().Name();
120 // Show a quick summary of the version requirements
121 if (D
.TargetVer() != 0)
122 out
<< " (" << D
.CompType() << " " << D
.TargetVer() <<
125 /* Show a summary of the target package if possible. In the case
126 of virtual packages we show nothing */
128 pkgCache::PkgIterator Targ
= D
.TargetPkg();
129 if (Targ
->ProvidesList
== 0)
132 pkgCache::VerIterator Ver
= Cache
[Targ
].InstVerIter(Cache
);
133 if (Ver
.end() == false)
134 out
<< Ver
.VerStr() << " is installed";
137 if (Cache
[Targ
].CandidateVerIter(Cache
).end() == true)
139 if (Targ
->ProvidesList
== 0)
140 out
<< "it is not installable";
142 out
<< "it is a virtual package";
145 out
<< "it is not installed";
154 // ShowNew - Show packages to newly install /*{{{*/
155 // ---------------------------------------------------------------------
157 void ShowNew(ostream
&out
,pkgDepCache
&Dep
)
159 /* Print out a list of packages that are going to be removed extra
160 to what the user asked */
161 pkgCache::PkgIterator I
= Dep
.PkgBegin();
163 for (;I
.end() != true; I
++)
164 if (Dep
[I
].NewInstall() == true)
165 List
+= string(I
.Name()) + " ";
166 ShowList(out
,"The following NEW packages will be installed:",List
);
169 // ShowDel - Show packages to delete /*{{{*/
170 // ---------------------------------------------------------------------
172 void ShowDel(ostream
&out
,pkgDepCache
&Dep
)
174 /* Print out a list of packages that are going to be removed extra
175 to what the user asked */
176 pkgCache::PkgIterator I
= Dep
.PkgBegin();
178 for (;I
.end() != true; I
++)
179 if (Dep
[I
].Delete() == true)
180 List
+= string(I
.Name()) + " ";
181 ShowList(out
,"The following packages will be REMOVED:",List
);
184 // ShowKept - Show kept packages /*{{{*/
185 // ---------------------------------------------------------------------
187 void ShowKept(ostream
&out
,pkgDepCache
&Dep
)
189 pkgCache::PkgIterator I
= Dep
.PkgBegin();
191 for (;I
.end() != true; I
++)
194 if (Dep
[I
].Upgrade() == true || Dep
[I
].Upgradable() == false ||
195 I
->CurrentVer
== 0 || Dep
[I
].Delete() == true)
198 List
+= string(I
.Name()) + " ";
200 ShowList(out
,"The following packages have been kept back",List
);
203 // ShowUpgraded - Show upgraded packages /*{{{*/
204 // ---------------------------------------------------------------------
206 void ShowUpgraded(ostream
&out
,pkgDepCache
&Dep
)
208 pkgCache::PkgIterator I
= Dep
.PkgBegin();
210 for (;I
.end() != true; I
++)
213 if (Dep
[I
].Upgrade() == false || Dep
[I
].NewInstall() == true)
216 List
+= string(I
.Name()) + " ";
218 ShowList(out
,"The following packages will be upgraded",List
);
221 // ShowHold - Show held but changed packages /*{{{*/
222 // ---------------------------------------------------------------------
224 void ShowHold(ostream
&out
,pkgDepCache
&Dep
)
226 pkgCache::PkgIterator I
= Dep
.PkgBegin();
228 for (;I
.end() != true; I
++)
230 if (Dep
[I
].InstallVer
!= (pkgCache::Version
*)I
.CurrentVer() &&
231 I
->SelectedState
== pkgCache::State::Hold
)
232 List
+= string(I
.Name()) + " ";
235 ShowList(out
,"The following held packages will be changed:",List
);
238 // ShowEssential - Show an essential package warning /*{{{*/
239 // ---------------------------------------------------------------------
240 /* This prints out a warning message that is not to be ignored. It shows
241 all essential packages and their dependents that are to be removed.
242 It is insanely risky to remove the dependents of an essential package! */
243 void ShowEssential(ostream
&out
,pkgDepCache
&Dep
)
245 pkgCache::PkgIterator I
= Dep
.PkgBegin();
247 bool *Added
= new bool[Dep
.HeaderP
->PackageCount
];
248 for (unsigned int I
= 0; I
!= Dep
.HeaderP
->PackageCount
; I
++)
251 for (;I
.end() != true; I
++)
253 if ((I
->Flags
& pkgCache::Flag::Essential
) != pkgCache::Flag::Essential
)
256 // The essential package is being removed
257 if (Dep
[I
].Delete() == true)
259 if (Added
[I
->ID
] == false)
262 List
+= string(I
.Name()) + " ";
266 if (I
->CurrentVer
== 0)
269 // Print out any essential package depenendents that are to be removed
270 for (pkgDepCache::DepIterator D
= I
.CurrentVer().DependsList(); D
.end() == false; D
++)
272 pkgCache::PkgIterator P
= D
.SmartTargetPkg();
273 if (Dep
[P
].Delete() == true)
275 if (Added
[P
->ID
] == true)
278 List
+= string(P
.Name()) + " ";
283 if (List
.empty() == false)
284 out
<< "WARNING: The following essential packages will be removed" << endl
;
285 ShowList(out
,"This should NOT be done unless you know exactly what you are doing!",List
);
290 // Stats - Show some statistics /*{{{*/
291 // ---------------------------------------------------------------------
293 void Stats(ostream
&out
,pkgDepCache
&Dep
)
295 unsigned long Upgrade
= 0;
296 unsigned long Install
= 0;
297 for (pkgCache::PkgIterator I
= Dep
.PkgBegin(); I
.end() == false; I
++)
299 if (Dep
[I
].NewInstall() == true)
302 if (Dep
[I
].Upgrade() == true)
306 out
<< Upgrade
<< " packages upgraded, " <<
307 Install
<< " newly installed, " <<
308 Dep
.DelCount() << " to remove and " <<
309 Dep
.KeepCount() << " not upgraded." << endl
;
311 if (Dep
.BadCount() != 0)
312 out
<< Dep
.BadCount() << " packages not fully installed or removed." << endl
;
316 // class CacheFile - Cover class for some dependency cache functions /*{{{*/
317 // ---------------------------------------------------------------------
327 inline operator pkgDepCache
&() {return *Cache
;};
328 inline pkgDepCache
*operator ->() {return Cache
;};
329 inline pkgDepCache
&operator *() {return *Cache
;};
332 CacheFile() : File(0), Map(0), Cache(0) {};
341 // CacheFile::Open - Open the cache file /*{{{*/
342 // ---------------------------------------------------------------------
343 /* This routine generates the caches and then opens the dependency cache
344 and verifies that the system is OK. */
345 bool CacheFile::Open()
347 // Create a progress class
348 OpTextProgress
Progress(*_config
);
350 // Read the source list
352 if (List
.ReadMainList() == false)
353 return _error
->Error("The list of sources could not be read.");
355 // Build all of the caches
356 pkgMakeStatusCache(List
,Progress
);
357 if (_error
->PendingError() == true)
358 return _error
->Error("The package lists or status file could not be parsed or opened.");
362 // Open the cache file
363 File
= new FileFd(_config
->FindFile("Dir::Cache::pkgcache"),FileFd::ReadOnly
);
364 if (_error
->PendingError() == true)
367 Map
= new MMap(*File
,MMap::Public
| MMap::ReadOnly
);
368 if (_error
->PendingError() == true)
371 Cache
= new pkgDepCache(*Map
,Progress
);
372 if (_error
->PendingError() == true)
377 // Check that the system is OK
378 if (Cache
->DelCount() != 0 || Cache
->InstCount() != 0)
379 return _error
->Error("Internal Error, non-zero counts");
381 // Apply corrections for half-installed packages
382 if (pkgApplyStatus(*Cache
) == false)
386 if (Cache
->BrokenCount() == 0)
389 // Attempt to fix broken things
390 if (_config
->FindB("APT::Get::Fix-Broken",false) == true)
392 c1out
<< "Correcting dependencies..." << flush
;
393 if (pkgFixBroken(*Cache
) == false || Cache
->BrokenCount() != 0)
395 c1out
<< " failed." << endl
;
396 ShowBroken(c1out
,*this);
398 return _error
->Error("Unable to correct dependencies");
400 if (pkgMinimizeUpgrade(*Cache
) == false)
401 return _error
->Error("Unable to minimize the upgrade set");
403 c1out
<< " Done" << endl
;
407 c1out
<< "You might want to run `apt-get -f install' to correct these." << endl
;
408 ShowBroken(c1out
,*this);
410 return _error
->Error("Unmet dependencies. Try using -f.");
417 // InstallPackages - Actually download and install the packages /*{{{*/
418 // ---------------------------------------------------------------------
419 /* This displays the informative messages describing what is going to
420 happen and then calls the download routines */
421 bool InstallPackages(pkgDepCache
&Cache
,bool ShwKept
)
423 ShowDel(c1out
,Cache
);
424 ShowNew(c1out
,Cache
);
426 ShowKept(c1out
,Cache
);
427 ShowHold(c1out
,Cache
);
428 if (_config
->FindB("APT::Get::Show-Upgraded",false) == true)
429 ShowUpgraded(c1out
,Cache
);
430 ShowEssential(c1out
,Cache
);
434 if (Cache
.BrokenCount() != 0)
436 ShowBroken(c1out
,Cache
);
437 return _error
->Error("Internal Error, InstallPackages was called with broken packages!");
440 if (Cache
.DelCount() == 0 && Cache
.InstCount() == 0 &&
441 Cache
.BadCount() == 0)
448 // DoUpdate - Update the package lists /*{{{*/
449 // ---------------------------------------------------------------------
451 bool DoUpdate(CommandLine
&)
453 // Get the source list
455 if (List
.ReadMainList() == false)
458 // Create the download object
459 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
460 pkgAcquire
Fetcher(&Stat
);
462 // Populate it with the source selection
463 pkgSourceList::const_iterator I
;
464 for (I
= List
.begin(); I
!= List
.end(); I
++)
466 new pkgAcqIndex(&Fetcher
,I
);
467 if (_error
->PendingError() == true)
472 if (Fetcher
.Run() == false)
475 // Prepare the cache.
477 if (Cache
.Open() == false)
483 // DoUpgrade - Upgrade all packages /*{{{*/
484 // ---------------------------------------------------------------------
485 /* Upgrade all packages without installing new packages or erasing old
487 bool DoUpgrade(CommandLine
&CmdL
)
490 if (Cache
.Open() == false)
494 if (pkgAllUpgrade(Cache
) == false)
496 ShowBroken(c1out
,Cache
);
497 return _error
->Error("Internal Error, AllUpgrade broke stuff");
500 return InstallPackages(Cache
,true);
503 // DoInstall - Install packages from the command line /*{{{*/
504 // ---------------------------------------------------------------------
505 /* Install named packages */
506 bool DoInstall(CommandLine
&CmdL
)
509 if (Cache
.Open() == false)
512 int ExpectedInst
= 0;
514 pkgProblemResolver
Fix(Cache
);
516 bool DefRemove
= false;
517 if (strcasecmp(CmdL
.FileList
[0],"remove") == 0)
520 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
522 // Duplicate the string
523 unsigned int Length
= strlen(*I
);
525 if (Length
>= sizeof(S
))
529 // See if we are removing the package
530 bool Remove
= DefRemove
;
531 if (S
[Length
- 1] == '-')
536 if (S
[Length
- 1] == '+')
542 // Locate the package
543 pkgCache::PkgIterator Pkg
= Cache
->FindPkg(S
);
545 if (Pkg
.end() == true)
546 return _error
->Error("Couldn't find package %s",S
);
548 // Check if there is something new to install
549 pkgDepCache::StateCache
&State
= (*Cache
)[Pkg
];
550 if (State
.CandidateVer
== 0)
552 if (Pkg
->ProvidesList
!= 0)
554 c1out
<< "Package " << S
<< " is a virtual package provided by:" << endl
;
556 pkgCache::PrvIterator I
= Pkg
.ProvidesList();
557 for (; I
.end() == false; I
++)
559 pkgCache::PkgIterator Pkg
= I
.OwnerPkg();
561 if ((*Cache
)[Pkg
].CandidateVerIter(*Cache
) == I
.OwnerVer())
562 c1out
<< " " << Pkg
.Name() << " " << I
.OwnerVer().VerStr() << endl
;
564 if ((*Cache
)[Pkg
].InstVerIter(*Cache
) == I
.OwnerVer())
565 c1out
<< " " << Pkg
.Name() << " " << I
.OwnerVer().VerStr() <<
566 " [Installed]"<< endl
;
568 c1out
<< "You should explicly select one to install." << endl
;
572 c1out
<< "Package " << S
<< " has no available version, but exists in the database." << endl
;
573 c1out
<< "This typically means that the package was mentioned in a dependency and " << endl
;
574 c1out
<< "never uploaded, or that it is an obsolete package." << endl
;
577 return _error
->Error("Package %s has no installation candidate",S
);
584 Cache
->MarkDelete(Pkg
);
589 Cache
->MarkInstall(Pkg
,false);
590 if (State
.Install() == false)
591 c1out
<< "Sorry, " << S
<< " is already the newest version" << endl
;
595 // Install it with autoinstalling enabled.
596 if (State
.InstBroken() == true)
597 Cache
->MarkInstall(Pkg
,true);
600 // Call the scored problem resolver
601 Fix
.InstallProtect();
602 if (Fix
.Resolve(true) == false)
605 // Now we check the state of the packages,
606 if (Cache
->BrokenCount() != 0)
608 c1out
<< "Some packages could not be installed. This may mean that you have" << endl
;
609 c1out
<< "requested an impossible situation or if you are using the unstable" << endl
;
610 c1out
<< "distribution that some required packages have not yet been created" << endl
;
611 c1out
<< "or been moved out of Incoming." << endl
;
615 c1out
<< "Since you only requested a single operation it is extremely likely that" << endl
;
616 c1out
<< "the package is simply not installable and a bug report against" << endl
;
617 c1out
<< "that package should be filed." << endl
;
620 c1out
<< "The following information may help to resolve the situation:" << endl
;
622 ShowBroken(c1out
,Cache
);
623 return _error
->Error("Sorry, broken packages");
626 /* Print out a list of packages that are going to be installed extra
627 to what the user asked */
628 if (Cache
->InstCount() != ExpectedInst
)
631 pkgCache::PkgIterator I
= Cache
->PkgBegin();
632 for (;I
.end() != true; I
++)
634 if ((*Cache
)[I
].Install() == false)
638 for (J
= CmdL
.FileList
+ 1; *J
!= 0; J
++)
639 if (strcmp(*J
,I
.Name()) == 0)
643 List
+= string(I
.Name()) + " ";
646 ShowList(c1out
,"The following extra packages will be installed:",List
);
649 return InstallPackages(Cache
,false);
652 // DoDistUpgrade - Automatic smart upgrader /*{{{*/
653 // ---------------------------------------------------------------------
654 /* Intelligent upgrader that will install and remove packages at will */
655 bool DoDistUpgrade(CommandLine
&CmdL
)
658 if (Cache
.Open() == false)
661 c0out
<< "Calculating Upgrade... " << flush
;
662 if (pkgDistUpgrade(*Cache
) == false)
664 c0out
<< "Failed" << endl
;
665 ShowBroken(c1out
,Cache
);
669 c0out
<< "Done" << endl
;
671 return InstallPackages(Cache
,true);
674 // DoDSelectUpgrade - Do an upgrade by following dselects selections /*{{{*/
675 // ---------------------------------------------------------------------
676 /* Follows dselect's selections */
677 bool DoDSelectUpgrade(CommandLine
&CmdL
)
680 if (Cache
.Open() == false)
683 // Install everything with the install flag set
684 pkgCache::PkgIterator I
= Cache
->PkgBegin();
685 for (;I
.end() != true; I
++)
687 /* Install the package only if it is a new install, the autoupgrader
688 will deal with the rest */
689 if (I
->SelectedState
== pkgCache::State::Install
)
690 Cache
->MarkInstall(I
,false);
693 /* Now install their deps too, if we do this above then order of
694 the status file is significant for | groups */
695 for (I
= Cache
->PkgBegin();I
.end() != true; I
++)
697 /* Install the package only if it is a new install, the autoupgrader
698 will deal with the rest */
699 if (I
->SelectedState
== pkgCache::State::Install
)
700 Cache
->MarkInstall(I
);
703 // Apply erasures now, they override everything else.
704 for (I
= Cache
->PkgBegin();I
.end() != true; I
++)
707 if (I
->SelectedState
== pkgCache::State::DeInstall
||
708 I
->SelectedState
== pkgCache::State::Purge
)
709 Cache
->MarkDelete(I
);
712 /* Use updates smart upgrade to do the rest, it will automatically
714 if (pkgAllUpgrade(Cache
) == false)
716 ShowBroken(c1out
,Cache
);
717 return _error
->Error("Internal Error, AllUpgrade broke stuff");
720 return InstallPackages(Cache
,false);
723 // DoClean - Remove download archives /*{{{*/
724 // ---------------------------------------------------------------------
726 bool DoClean(CommandLine
&CmdL
)
731 // DoCheck - Perform the check operation /*{{{*/
732 // ---------------------------------------------------------------------
733 /* Opening automatically checks the system, this command is mostly used
735 bool DoCheck(CommandLine
&CmdL
)
744 // ShowHelp - Show a help screen /*{{{*/
745 // ---------------------------------------------------------------------
749 cout
<< PACKAGE
<< ' ' << VERSION
<< " for " << ARCHITECTURE
<<
750 " compiled on " << __DATE__
<< " " << __TIME__
<< endl
;
752 cout
<< "Usage: apt-get [options] command" << endl
;
753 cout
<< " apt-get [options] install pkg1 [pkg2 ...]" << endl
;
755 cout
<< "apt-get is a simple command line interface for downloading and" << endl
;
756 cout
<< "installing packages. The most frequently used commands are update" << endl
;
757 cout
<< "and install." << endl
;
759 cout
<< "Commands:" << endl
;
760 cout
<< " update - Retrieve new lists of packages" << endl
;
761 cout
<< " upgrade - Perform an upgrade" << endl
;
762 cout
<< " install - Install new packages (pkg is libc6 not libc6.deb)" << endl
;
763 cout
<< " remove - Remove packages" << endl
;
764 cout
<< " dist-upgrade - Distribution upgrade, see apt-get(8)" << endl
;
765 cout
<< " dselect-upgrade - Follow dselect selections" << endl
;
766 cout
<< " clean - Erase downloaded archive files" << endl
;
767 cout
<< " check - Verify that there are no broken dependencies" << endl
;
769 cout
<< "Options:" << endl
;
770 cout
<< " -h This help text." << endl
;
771 cout
<< " -q Loggable output - no progress indicator" << endl
;
772 cout
<< " -qq No output except for errors" << endl
;
773 cout
<< " -d Download only - do NOT install or unpack archives" << endl
;
774 cout
<< " -s No-act. Perform ordering simulation" << endl
;
775 cout
<< " -y Assume Yes to all queries and do not prompt" << endl
;
776 cout
<< " -f Attempt to continue if the integrity check fails" << endl
;
777 cout
<< " -m Attempt to continue if archives are unlocatable" << endl
;
778 cout
<< " -u Show a list of upgraded packages as well" << endl
;
779 cout
<< " -c=? Read this configuration file" << endl
;
780 cout
<< " -o=? Set an arbitary configuration option, ie -o dir::cache=/tmp" << endl
;
781 cout
<< "See the apt-get(8), sources.list(8) and apt.conf(8) manual" << endl
;
782 cout
<< "pages for more information." << endl
;
786 // GetInitialize - Initialize things for apt-get /*{{{*/
787 // ---------------------------------------------------------------------
791 _config
->Set("quiet",0);
792 _config
->Set("help",false);
793 _config
->Set("APT::Get::Download-Only",false);
794 _config
->Set("APT::Get::Simulate",false);
795 _config
->Set("APT::Get::Assume-Yes",false);
796 _config
->Set("APT::Get::Fix-Broken",false);
800 int main(int argc
,const char *argv
[])
802 CommandLine::Args Args
[] = {
803 {'h',"help","help",0},
804 {'q',"quiet","quiet",CommandLine::IntLevel
},
805 {'q',"silent","quiet",CommandLine::IntLevel
},
806 {'d',"download-only","APT::Get::Download-Only",0},
807 {'s',"simulate","APT::Get::Simulate",0},
808 {'s',"just-print","APT::Get::Simulate",0},
809 {'s',"recon","APT::Get::Simulate",0},
810 {'s',"no-act","APT::Get::Simulate",0},
811 {'y',"yes","APT::Get::Assume-Yes",0},
812 {'y',"assume-yes","APT::Get::Assume-Yes",0},
813 {'f',"fix-broken","APT::Get::Fix-Broken",0},
814 {'u',"show-upgraded","APT::Get::Show-Upgraded",0},
815 {'m',"ignore-missing","APT::Get::Fix-Broken",0},
816 {0,"ignore-hold","APT::Ingore-Hold",0},
817 {'c',"config-file",0,CommandLine::ConfigFile
},
818 {'o',"option",0,CommandLine::ArbItem
},
821 // Parse the command line and initialize the package library
822 CommandLine
CmdL(Args
,_config
);
823 if (pkgInitialize(*_config
) == false ||
824 CmdL
.Parse(argc
,argv
) == false)
826 _error
->DumpErrors();
830 // See if the help should be shown
831 if (_config
->FindB("help") == true ||
832 CmdL
.FileSize() == 0)
835 // Setup the output streams
836 c0out
.rdbuf(cout
.rdbuf());
837 c1out
.rdbuf(cout
.rdbuf());
838 c2out
.rdbuf(cout
.rdbuf());
839 if (_config
->FindI("quiet",0) > 0)
840 c0out
.rdbuf(devnull
.rdbuf());
841 if (_config
->FindI("quiet",0) > 1)
842 c1out
.rdbuf(devnull
.rdbuf());
844 // Match the operation
848 bool (*Handler
)(CommandLine
&);
849 } Map
[] = {{"update",&DoUpdate
},
850 {"upgrade",&DoUpgrade
},
851 {"install",&DoInstall
},
852 {"remove",&DoInstall
},
853 {"dist-upgrade",&DoDistUpgrade
},
854 {"dselect-upgrade",&DoDSelectUpgrade
},
859 for (I
= 0; Map
[I
].Match
!= 0; I
++)
861 if (strcmp(CmdL
.FileList
[0],Map
[I
].Match
) == 0)
863 if (Map
[I
].Handler(CmdL
) == false && _error
->PendingError() == false)
864 _error
->Error("Handler silently failed");
870 if (Map
[I
].Match
== 0)
871 _error
->Error("Invalid operation %s", CmdL
.FileList
[0]);
873 // Print any errors or warnings found during parsing
874 if (_error
->empty() == false)
876 bool Errors
= _error
->PendingError();
877 _error
->DumpErrors();
879 cout
<< "Returning 100." << endl
;
880 return Errors
== true?100:0;