]>
git.saurik.com Git - apt.git/blob - cmdline/apt-get.cc
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: apt-get.cc,v 1.75 1999/09/09 06:27:42 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/algorithms.h>
34 #include <apt-pkg/acquire-item.h>
35 #include <apt-pkg/dpkgpm.h>
36 #include <apt-pkg/strutl.h>
37 #include <apt-pkg/clean.h>
38 #include <apt-pkg/srcrecords.h>
39 #include <apt-pkg/version.h>
40 #include <apt-pkg/cachefile.h>
44 #include "acqprogress.h"
48 #include <sys/ioctl.h>
61 ofstream
devnull("/dev/null");
62 unsigned int ScreenWidth
= 80;
64 // class CacheFile - Cover class for some dependency cache functions /*{{{*/
65 // ---------------------------------------------------------------------
67 class CacheFile
: public pkgCacheFile
69 static pkgCache
*SortCache
;
70 static int NameComp(const void *a
,const void *b
);
73 pkgCache::Package
**List
;
76 bool CheckDeps(bool AllowBroken
= false);
77 bool Open(bool WithLock
= true)
79 OpTextProgress
Prog(*_config
);
80 if (pkgCacheFile::Open(Prog
,WithLock
) == false)
85 CacheFile() : List(0) {};
89 // YnPrompt - Yes No Prompt. /*{{{*/
90 // ---------------------------------------------------------------------
91 /* Returns true on a Yes.*/
94 if (_config
->FindB("APT::Get::Assume-Yes",false) == true)
102 read(STDIN_FILENO
,&C
,1);
103 while (C
!= '\n' && Jnk
!= '\n') read(STDIN_FILENO
,&Jnk
,1);
105 if (!(C
== 'Y' || C
== 'y' || C
== '\n' || C
== '\r'))
110 // AnalPrompt - Annoying Yes No Prompt. /*{{{*/
111 // ---------------------------------------------------------------------
112 /* Returns true on a Yes.*/
113 bool AnalPrompt(const char *Text
)
116 cin
.getline(Buf
,sizeof(Buf
));
117 if (strcmp(Buf
,Text
) == 0)
122 // ShowList - Show a list /*{{{*/
123 // ---------------------------------------------------------------------
124 /* This prints out a string of space seperated words with a title and
125 a two space indent line wraped to the current screen width. */
126 bool ShowList(ostream
&out
,string Title
,string List
)
128 if (List
.empty() == true)
131 // Acount for the leading space
132 int ScreenWidth
= ::ScreenWidth
- 3;
134 out
<< Title
<< endl
;
135 string::size_type Start
= 0;
136 while (Start
< List
.size())
138 string::size_type End
;
139 if (Start
+ ScreenWidth
>= List
.size())
142 End
= List
.rfind(' ',Start
+ScreenWidth
);
144 if (End
== string::npos
|| End
< Start
)
145 End
= Start
+ ScreenWidth
;
146 out
<< " " << string(List
,Start
,End
- Start
) << endl
;
152 // ShowBroken - Debugging aide /*{{{*/
153 // ---------------------------------------------------------------------
154 /* This prints out the names of all the packages that are broken along
155 with the name of each each broken dependency and a quite version
157 void ShowBroken(ostream
&out
,CacheFile
&Cache
)
159 out
<< "Sorry, but the following packages have unmet dependencies:" << endl
;
160 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
162 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
164 if (Cache
[I
].InstBroken() == false)
167 // Print out each package and the failed dependencies
168 out
<<" " << I
.Name() << ":";
169 int Indent
= strlen(I
.Name()) + 3;
171 if (Cache
[I
].InstVerIter(Cache
).end() == true)
177 for (pkgCache::DepIterator D
= Cache
[I
].InstVerIter(Cache
).DependsList(); D
.end() == false;)
179 // Compute a single dependency element (glob or)
180 pkgCache::DepIterator Start
;
181 pkgCache::DepIterator End
;
184 if (Cache
->IsImportantDep(End
) == false ||
185 (Cache
[End
] & pkgDepCache::DepGInstall
) == pkgDepCache::DepGInstall
)
189 for (int J
= 0; J
!= Indent
; J
++)
193 out
<< ' ' << End
.DepType() << ": " << End
.TargetPkg().Name();
195 // Show a quick summary of the version requirements
196 if (End
.TargetVer() != 0)
197 out
<< " (" << End
.CompType() << " " << End
.TargetVer() <<
200 /* Show a summary of the target package if possible. In the case
201 of virtual packages we show nothing */
203 pkgCache::PkgIterator Targ
= End
.TargetPkg();
204 if (Targ
->ProvidesList
== 0)
207 pkgCache::VerIterator Ver
= Cache
[Targ
].InstVerIter(Cache
);
208 if (Ver
.end() == false)
209 out
<< Ver
.VerStr() << " is installed";
212 if (Cache
[Targ
].CandidateVerIter(Cache
).end() == true)
214 if (Targ
->ProvidesList
== 0)
215 out
<< "it is not installable";
217 out
<< "it is a virtual package";
220 out
<< "it is not installed";
229 // ShowNew - Show packages to newly install /*{{{*/
230 // ---------------------------------------------------------------------
232 void ShowNew(ostream
&out
,CacheFile
&Cache
)
234 /* Print out a list of packages that are going to be removed extra
235 to what the user asked */
237 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
239 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
240 if (Cache
[I
].NewInstall() == true)
241 List
+= string(I
.Name()) + " ";
244 ShowList(out
,"The following NEW packages will be installed:",List
);
247 // ShowDel - Show packages to delete /*{{{*/
248 // ---------------------------------------------------------------------
250 void ShowDel(ostream
&out
,CacheFile
&Cache
)
252 /* Print out a list of packages that are going to be removed extra
253 to what the user asked */
255 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
257 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
258 if (Cache
[I
].Delete() == true)
260 if ((Cache
[I
].iFlags
& pkgDepCache::Purge
) == pkgDepCache::Purge
)
261 List
+= string(I
.Name()) + "* ";
263 List
+= string(I
.Name()) + " ";
267 ShowList(out
,"The following packages will be REMOVED:",List
);
270 // ShowKept - Show kept packages /*{{{*/
271 // ---------------------------------------------------------------------
273 void ShowKept(ostream
&out
,CacheFile
&Cache
)
276 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
278 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
281 if (Cache
[I
].Upgrade() == true || Cache
[I
].Upgradable() == false ||
282 I
->CurrentVer
== 0 || Cache
[I
].Delete() == true)
285 List
+= string(I
.Name()) + " ";
287 ShowList(out
,"The following packages have been kept back",List
);
290 // ShowUpgraded - Show upgraded packages /*{{{*/
291 // ---------------------------------------------------------------------
293 void ShowUpgraded(ostream
&out
,CacheFile
&Cache
)
296 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
298 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
301 if (Cache
[I
].Upgrade() == false || Cache
[I
].NewInstall() == true)
304 List
+= string(I
.Name()) + " ";
306 ShowList(out
,"The following packages will be upgraded",List
);
309 // ShowHold - Show held but changed packages /*{{{*/
310 // ---------------------------------------------------------------------
312 bool ShowHold(ostream
&out
,CacheFile
&Cache
)
315 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
317 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
318 if (Cache
[I
].InstallVer
!= (pkgCache::Version
*)I
.CurrentVer() &&
319 I
->SelectedState
== pkgCache::State::Hold
)
320 List
+= string(I
.Name()) + " ";
323 return ShowList(out
,"The following held packages will be changed:",List
);
326 // ShowEssential - Show an essential package warning /*{{{*/
327 // ---------------------------------------------------------------------
328 /* This prints out a warning message that is not to be ignored. It shows
329 all essential packages and their dependents that are to be removed.
330 It is insanely risky to remove the dependents of an essential package! */
331 bool ShowEssential(ostream
&out
,CacheFile
&Cache
)
334 bool *Added
= new bool[Cache
->HeaderP
->PackageCount
];
335 for (unsigned int I
= 0; I
!= Cache
->HeaderP
->PackageCount
; I
++)
338 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
340 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
341 if ((I
->Flags
& pkgCache::Flag::Essential
) != pkgCache::Flag::Essential
)
344 // The essential package is being removed
345 if (Cache
[I
].Delete() == true)
347 if (Added
[I
->ID
] == false)
350 List
+= string(I
.Name()) + " ";
354 if (I
->CurrentVer
== 0)
357 // Print out any essential package depenendents that are to be removed
358 for (pkgDepCache::DepIterator D
= I
.CurrentVer().DependsList(); D
.end() == false; D
++)
360 // Skip everything but depends
361 if (D
->Type
!= pkgCache::Dep::PreDepends
&&
362 D
->Type
!= pkgCache::Dep::Depends
)
365 pkgCache::PkgIterator P
= D
.SmartTargetPkg();
366 if (Cache
[P
].Delete() == true)
368 if (Added
[P
->ID
] == true)
373 sprintf(S
,"%s (due to %s) ",P
.Name(),I
.Name());
380 if (List
.empty() == false)
381 out
<< "WARNING: The following essential packages will be removed" << endl
;
382 return ShowList(out
,"This should NOT be done unless you know exactly what you are doing!",List
);
385 // Stats - Show some statistics /*{{{*/
386 // ---------------------------------------------------------------------
388 void Stats(ostream
&out
,pkgDepCache
&Dep
)
390 unsigned long Upgrade
= 0;
391 unsigned long Install
= 0;
392 for (pkgCache::PkgIterator I
= Dep
.PkgBegin(); I
.end() == false; I
++)
394 if (Dep
[I
].NewInstall() == true)
397 if (Dep
[I
].Upgrade() == true)
401 out
<< Upgrade
<< " packages upgraded, " <<
402 Install
<< " newly installed, " <<
403 Dep
.DelCount() << " to remove and " <<
404 Dep
.KeepCount() << " not upgraded." << endl
;
406 if (Dep
.BadCount() != 0)
407 out
<< Dep
.BadCount() << " packages not fully installed or removed." << endl
;
411 // CacheFile::NameComp - QSort compare by name /*{{{*/
412 // ---------------------------------------------------------------------
414 pkgCache
*CacheFile::SortCache
= 0;
415 int CacheFile::NameComp(const void *a
,const void *b
)
417 if (*(pkgCache::Package
**)a
== 0 || *(pkgCache::Package
**)b
== 0)
418 return *(pkgCache::Package
**)a
- *(pkgCache::Package
**)b
;
420 const pkgCache::Package
&A
= **(pkgCache::Package
**)a
;
421 const pkgCache::Package
&B
= **(pkgCache::Package
**)b
;
423 return strcmp(SortCache
->StrP
+ A
.Name
,SortCache
->StrP
+ B
.Name
);
426 // CacheFile::Sort - Sort by name /*{{{*/
427 // ---------------------------------------------------------------------
429 void CacheFile::Sort()
432 List
= new pkgCache::Package
*[Cache
->Head().PackageCount
];
433 memset(List
,0,sizeof(*List
)*Cache
->Head().PackageCount
);
434 pkgCache::PkgIterator I
= Cache
->PkgBegin();
435 for (;I
.end() != true; I
++)
439 qsort(List
,Cache
->Head().PackageCount
,sizeof(*List
),NameComp
);
442 // CacheFile::Open - Open the cache file /*{{{*/
443 // ---------------------------------------------------------------------
444 /* This routine generates the caches and then opens the dependency cache
445 and verifies that the system is OK. */
446 bool CacheFile::CheckDeps(bool AllowBroken
)
448 if (_error
->PendingError() == true)
451 // Check that the system is OK
452 if (Cache
->DelCount() != 0 || Cache
->InstCount() != 0)
453 return _error
->Error("Internal Error, non-zero counts");
455 // Apply corrections for half-installed packages
456 if (pkgApplyStatus(*Cache
) == false)
460 if (Cache
->BrokenCount() == 0 || AllowBroken
== true)
463 // Attempt to fix broken things
464 if (_config
->FindB("APT::Get::Fix-Broken",false) == true)
466 c1out
<< "Correcting dependencies..." << flush
;
467 if (pkgFixBroken(*Cache
) == false || Cache
->BrokenCount() != 0)
469 c1out
<< " failed." << endl
;
470 ShowBroken(c1out
,*this);
472 return _error
->Error("Unable to correct dependencies");
474 if (pkgMinimizeUpgrade(*Cache
) == false)
475 return _error
->Error("Unable to minimize the upgrade set");
477 c1out
<< " Done" << endl
;
481 c1out
<< "You might want to run `apt-get -f install' to correct these." << endl
;
482 ShowBroken(c1out
,*this);
484 return _error
->Error("Unmet dependencies. Try using -f.");
491 // InstallPackages - Actually download and install the packages /*{{{*/
492 // ---------------------------------------------------------------------
493 /* This displays the informative messages describing what is going to
494 happen and then calls the download routines */
495 bool InstallPackages(CacheFile
&Cache
,bool ShwKept
,bool Ask
= true,bool Saftey
= true)
497 if (_config
->FindB("APT::Get::Purge",false) == true)
499 pkgCache::PkgIterator I
= Cache
->PkgBegin();
500 for (; I
.end() == false; I
++)
502 if (I
.Purge() == false && Cache
[I
].Mode
== pkgDepCache::ModeDelete
)
503 Cache
->MarkDelete(I
,true);
508 bool Essential
= false;
510 // Show all the various warning indicators
511 ShowDel(c1out
,Cache
);
512 ShowNew(c1out
,Cache
);
514 ShowKept(c1out
,Cache
);
515 Fail
|= !ShowHold(c1out
,Cache
);
516 if (_config
->FindB("APT::Get::Show-Upgraded",false) == true)
517 ShowUpgraded(c1out
,Cache
);
518 Essential
= !ShowEssential(c1out
,Cache
);
523 if (Cache
->BrokenCount() != 0)
525 ShowBroken(c1out
,Cache
);
526 return _error
->Error("Internal Error, InstallPackages was called with broken packages!");
529 if (Cache
->DelCount() == 0 && Cache
->InstCount() == 0 &&
530 Cache
->BadCount() == 0)
533 // Run the simulator ..
534 if (_config
->FindB("APT::Get::Simulate") == true)
536 pkgSimulate
PM(Cache
);
537 pkgPackageManager::OrderResult Res
= PM
.DoInstall();
538 if (Res
== pkgPackageManager::Failed
)
540 if (Res
!= pkgPackageManager::Completed
)
541 return _error
->Error("Internal Error, Ordering didn't finish");
545 // Create the text record parser
546 pkgRecords
Recs(Cache
);
547 if (_error
->PendingError() == true)
550 // Lock the archive directory
552 if (_config
->FindB("Debug::NoLocking",false) == false)
554 Lock
.Fd(GetLock(_config
->FindDir("Dir::Cache::Archives") + "lock"));
555 if (_error
->PendingError() == true)
556 return _error
->Error("Unable to lock the download directory");
559 // Create the download object
560 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
561 pkgAcquire
Fetcher(&Stat
);
563 // Read the source list
565 if (List
.ReadMainList() == false)
566 return _error
->Error("The list of sources could not be read.");
568 // Create the package manager and prepare to download
570 if (PM
.GetArchives(&Fetcher
,&List
,&Recs
) == false ||
571 _error
->PendingError() == true)
574 // Display statistics
575 unsigned long FetchBytes
= Fetcher
.FetchNeeded();
576 unsigned long FetchPBytes
= Fetcher
.PartialPresent();
577 unsigned long DebBytes
= Fetcher
.TotalNeeded();
578 if (DebBytes
!= Cache
->DebSize())
580 c0out
<< DebBytes
<< ',' << Cache
->DebSize() << endl
;
581 c0out
<< "How odd.. The sizes didn't match, email apt@packages.debian.org" << endl
;
584 // Check for enough free space
586 string OutputDir
= _config
->FindDir("Dir::Cache::Archives");
587 if (statfs(OutputDir
.c_str(),&Buf
) != 0)
588 return _error
->Errno("statfs","Couldn't determine free space in %s",
590 if (unsigned(Buf
.f_bfree
) < (FetchBytes
- FetchPBytes
)/Buf
.f_bsize
)
591 return _error
->Error("Sorry, you don't have enough free space in %s",
595 c1out
<< "Need to get ";
596 if (DebBytes
!= FetchBytes
)
597 c1out
<< SizeToStr(FetchBytes
) << "B/" << SizeToStr(DebBytes
) << 'B';
599 c1out
<< SizeToStr(DebBytes
) << 'B';
601 c1out
<< " of archives. After unpacking ";
604 if (Cache
->UsrSize() >= 0)
605 c1out
<< SizeToStr(Cache
->UsrSize()) << "B will be used." << endl
;
607 c1out
<< SizeToStr(-1*Cache
->UsrSize()) << "B will be freed." << endl
;
609 if (_error
->PendingError() == true)
613 if (_config
->FindI("quiet",0) >= 2 ||
614 _config
->FindB("APT::Get::Assume-Yes",false) == true)
616 if (Fail
== true && _config
->FindB("APT::Get::Force-Yes",false) == false)
617 return _error
->Error("There are problems and -y was used without --force-yes");
620 if (Essential
== true && Saftey
== true)
622 c2out
<< "You are about to do something potentially harmful" << endl
;
623 c2out
<< "To continue type in the phrase 'Yes, I understand this may be bad'" << endl
;
624 c2out
<< " ?] " << flush
;
625 if (AnalPrompt("Yes, I understand this may be bad") == false)
627 c2out
<< "Abort." << endl
;
633 // Prompt to continue
634 if (Ask
== true || Fail
== true)
636 if (_config
->FindI("quiet",0) < 2 &&
637 _config
->FindB("APT::Get::Assume-Yes",false) == false)
639 c2out
<< "Do you want to continue? [Y/n] " << flush
;
641 if (YnPrompt() == false)
643 c2out
<< "Abort." << endl
;
650 // Just print out the uris an exit if the --print-uris flag was used
651 if (_config
->FindB("APT::Get::Print-URIs") == true)
653 pkgAcquire::UriIterator I
= Fetcher
.UriBegin();
654 for (; I
!= Fetcher
.UriEnd(); I
++)
655 cout
<< '\'' << I
->URI
<< "' " << flNotDir(I
->Owner
->DestFile
) << ' ' <<
656 I
->Owner
->FileSize
<< ' ' << I
->Owner
->MD5Sum() << endl
;
663 if (_config
->FindB("APT::Get::No-Download",false) == false)
664 if( Fetcher
.Run() == pkgAcquire::Failed
)
669 bool Transient
= false;
670 for (pkgAcquire::Item
**I
= Fetcher
.ItemsBegin(); I
!= Fetcher
.ItemsEnd(); I
++)
672 if ((*I
)->Status
== pkgAcquire::Item::StatDone
&&
673 (*I
)->Complete
== true)
678 if ((*I
)->Status
== pkgAcquire::Item::StatIdle
)
685 cerr
<< "Failed to fetch " << (*I
)->DescURI() << endl
;
686 cerr
<< " " << (*I
)->ErrorText
<< endl
;
690 if (_config
->FindB("APT::Get::Download-Only",false) == true)
692 if (Failed
== true && _config
->FindB("APT::Get::Fix-Missing",false) == false)
693 return _error
->Error("Some files failed to download");
697 if (Failed
== true && _config
->FindB("APT::Get::Fix-Missing",false) == false)
699 /*if (Transient == true)
701 c2out << "Upgrading with disk swapping is not supported in this version." << endl;
702 c2out << "Try running multiple times with --fix-missing" << endl;
705 return _error
->Error("Unable to fetch some archives, maybe try with --fix-missing?");
708 if (Transient
== true && Failed
== true)
709 return _error
->Error("--fix-missing and media swapping is not currently supported");
711 // Try to deal with missing package files
712 if (Failed
== true && PM
.FixMissing() == false)
714 cerr
<< "Unable to correct missing packages." << endl
;
715 return _error
->Error("Aborting Install.");
719 pkgPackageManager::OrderResult Res
= PM
.DoInstall();
720 if (Res
== pkgPackageManager::Failed
|| _error
->PendingError() == true)
722 if (Res
== pkgPackageManager::Completed
)
725 // Reload the fetcher object and loop again for media swapping
727 if (PM
.GetArchives(&Fetcher
,&List
,&Recs
) == false)
733 // DoUpdate - Update the package lists /*{{{*/
734 // ---------------------------------------------------------------------
736 bool DoUpdate(CommandLine
&)
738 // Get the source list
740 if (List
.ReadMainList() == false)
743 // Lock the list directory
745 if (_config
->FindB("Debug::NoLocking",false) == false)
747 Lock
.Fd(GetLock(_config
->FindDir("Dir::State::Lists") + "lock"));
748 if (_error
->PendingError() == true)
749 return _error
->Error("Unable to lock the list directory");
752 // Create the download object
753 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
754 pkgAcquire
Fetcher(&Stat
);
756 // Populate it with the source selection
757 pkgSourceList::const_iterator I
;
758 for (I
= List
.begin(); I
!= List
.end(); I
++)
760 new pkgAcqIndex(&Fetcher
,I
);
761 if (_error
->PendingError() == true)
766 if (Fetcher
.Run() == pkgAcquire::Failed
)
770 for (pkgAcquire::Item
**I
= Fetcher
.ItemsBegin(); I
!= Fetcher
.ItemsEnd(); I
++)
772 if ((*I
)->Status
== pkgAcquire::Item::StatDone
)
780 // Clean out any old list files
781 if (_config
->FindB("APT::Get::List-Cleanup",false) == false)
783 if (Fetcher
.Clean(_config
->FindDir("Dir::State::lists")) == false ||
784 Fetcher
.Clean(_config
->FindDir("Dir::State::lists") + "partial/") == false)
788 // Prepare the cache.
790 if (Cache
.Open() == false)
794 return _error
->Error("Some index files failed to download, they have been ignored, or old ones used instead.");
798 // DoUpgrade - Upgrade all packages /*{{{*/
799 // ---------------------------------------------------------------------
800 /* Upgrade all packages without installing new packages or erasing old
802 bool DoUpgrade(CommandLine
&CmdL
)
805 if (Cache
.Open() == false || Cache
.CheckDeps() == false)
809 if (pkgAllUpgrade(Cache
) == false)
811 ShowBroken(c1out
,Cache
);
812 return _error
->Error("Internal Error, AllUpgrade broke stuff");
815 return InstallPackages(Cache
,true);
818 // DoInstall - Install packages from the command line /*{{{*/
819 // ---------------------------------------------------------------------
820 /* Install named packages */
821 bool DoInstall(CommandLine
&CmdL
)
824 if (Cache
.Open() == false || Cache
.CheckDeps(CmdL
.FileSize() != 1) == false)
827 // Enter the special broken fixing mode if the user specified arguments
828 bool BrokenFix
= false;
829 if (Cache
->BrokenCount() != 0)
832 unsigned int ExpectedInst
= 0;
833 unsigned int Packages
= 0;
834 pkgProblemResolver
Fix(Cache
);
836 bool DefRemove
= false;
837 if (strcasecmp(CmdL
.FileList
[0],"remove") == 0)
840 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++)
842 // Duplicate the string
843 unsigned int Length
= strlen(*I
);
845 if (Length
>= sizeof(S
))
849 // See if we are removing the package
850 bool Remove
= DefRemove
;
851 while (Cache
->FindPkg(S
).end() == true)
853 // Handle an optional end tag indicating what to do
854 if (S
[Length
- 1] == '-')
861 if (S
[Length
- 1] == '+')
870 // Locate the package
871 pkgCache::PkgIterator Pkg
= Cache
->FindPkg(S
);
873 if (Pkg
.end() == true)
874 return _error
->Error("Couldn't find package %s",S
);
876 // Handle the no-upgrade case
877 if (_config
->FindB("APT::Get::no-upgrade",false) == true &&
878 Pkg
->CurrentVer
!= 0)
880 c1out
<< "Skipping " << Pkg
.Name() << ", it is already installed and no-upgrade is set." << endl
;
884 // Check if there is something new to install
885 pkgDepCache::StateCache
&State
= (*Cache
)[Pkg
];
886 if (State
.CandidateVer
== 0)
888 if (Pkg
->ProvidesList
!= 0)
890 c1out
<< "Package " << S
<< " is a virtual package provided by:" << endl
;
892 pkgCache::PrvIterator I
= Pkg
.ProvidesList();
893 for (; I
.end() == false; I
++)
895 pkgCache::PkgIterator Pkg
= I
.OwnerPkg();
897 if ((*Cache
)[Pkg
].CandidateVerIter(*Cache
) == I
.OwnerVer())
899 if ((*Cache
)[Pkg
].Install() == true && (*Cache
)[Pkg
].NewInstall() == false)
900 c1out
<< " " << Pkg
.Name() << " " << I
.OwnerVer().VerStr() <<
901 " [Installed]"<< endl
;
903 c1out
<< " " << Pkg
.Name() << " " << I
.OwnerVer().VerStr() << endl
;
906 c1out
<< "You should explicly select one to install." << endl
;
910 c1out
<< "Package " << S
<< " has no available version, but exists in the database." << endl
;
911 c1out
<< "This typically means that the package was mentioned in a dependency and " << endl
;
912 c1out
<< "never uploaded, or that it is an obsolete package." << endl
;
915 pkgCache::DepIterator Dep
= Pkg
.RevDependsList();
916 for (; Dep
.end() == false; Dep
++)
918 if (Dep
->Type
!= pkgCache::Dep::Replaces
)
920 List
+= string(Dep
.ParentPkg().Name()) + " ";
922 ShowList(c1out
,"However the following packages replace it:",List
);
925 return _error
->Error("Package %s has no installation candidate",S
);
932 Cache
->MarkDelete(Pkg
,_config
->FindB("APT::Get::Purge",false));
937 Cache
->MarkInstall(Pkg
,false);
938 if (State
.Install() == false)
939 c1out
<< "Sorry, " << S
<< " is already the newest version" << endl
;
943 // Install it with autoinstalling enabled.
944 if (State
.InstBroken() == true && BrokenFix
== false)
945 Cache
->MarkInstall(Pkg
,true);
948 /* If we are in the Broken fixing mode we do not attempt to fix the
949 problems. This is if the user invoked install without -f and gave
951 if (BrokenFix
== true && Cache
->BrokenCount() != 0)
953 c1out
<< "You might want to run `apt-get -f install' to correct these:" << endl
;
954 ShowBroken(c1out
,Cache
);
956 return _error
->Error("Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution).");
959 // Call the scored problem resolver
960 Fix
.InstallProtect();
961 if (Fix
.Resolve(true) == false)
964 // Now we check the state of the packages,
965 if (Cache
->BrokenCount() != 0)
967 c1out
<< "Some packages could not be installed. This may mean that you have" << endl
;
968 c1out
<< "requested an impossible situation or if you are using the unstable" << endl
;
969 c1out
<< "distribution that some required packages have not yet been created" << endl
;
970 c1out
<< "or been moved out of Incoming." << endl
;
974 c1out
<< "Since you only requested a single operation it is extremely likely that" << endl
;
975 c1out
<< "the package is simply not installable and a bug report against" << endl
;
976 c1out
<< "that package should be filed." << endl
;
979 c1out
<< "The following information may help to resolve the situation:" << endl
;
981 ShowBroken(c1out
,Cache
);
982 return _error
->Error("Sorry, broken packages");
985 /* Print out a list of packages that are going to be installed extra
986 to what the user asked */
987 if (Cache
->InstCount() != ExpectedInst
)
990 for (unsigned J
= 0; J
< Cache
->Head().PackageCount
; J
++)
992 pkgCache::PkgIterator
I(Cache
,Cache
.List
[J
]);
993 if ((*Cache
)[I
].Install() == false)
997 for (J
= CmdL
.FileList
+ 1; *J
!= 0; J
++)
998 if (strcmp(*J
,I
.Name()) == 0)
1002 List
+= string(I
.Name()) + " ";
1005 ShowList(c1out
,"The following extra packages will be installed:",List
);
1008 // See if we need to prompt
1009 if (Cache
->InstCount() == ExpectedInst
&& Cache
->DelCount() == 0)
1010 return InstallPackages(Cache
,false,false);
1012 return InstallPackages(Cache
,false);
1015 // DoDistUpgrade - Automatic smart upgrader /*{{{*/
1016 // ---------------------------------------------------------------------
1017 /* Intelligent upgrader that will install and remove packages at will */
1018 bool DoDistUpgrade(CommandLine
&CmdL
)
1021 if (Cache
.Open() == false || Cache
.CheckDeps() == false)
1024 c0out
<< "Calculating Upgrade... " << flush
;
1025 if (pkgDistUpgrade(*Cache
) == false)
1027 c0out
<< "Failed" << endl
;
1028 ShowBroken(c1out
,Cache
);
1032 c0out
<< "Done" << endl
;
1034 return InstallPackages(Cache
,true);
1037 // DoDSelectUpgrade - Do an upgrade by following dselects selections /*{{{*/
1038 // ---------------------------------------------------------------------
1039 /* Follows dselect's selections */
1040 bool DoDSelectUpgrade(CommandLine
&CmdL
)
1043 if (Cache
.Open() == false || Cache
.CheckDeps() == false)
1046 // Install everything with the install flag set
1047 pkgCache::PkgIterator I
= Cache
->PkgBegin();
1048 for (;I
.end() != true; I
++)
1050 /* Install the package only if it is a new install, the autoupgrader
1051 will deal with the rest */
1052 if (I
->SelectedState
== pkgCache::State::Install
)
1053 Cache
->MarkInstall(I
,false);
1056 /* Now install their deps too, if we do this above then order of
1057 the status file is significant for | groups */
1058 for (I
= Cache
->PkgBegin();I
.end() != true; I
++)
1060 /* Install the package only if it is a new install, the autoupgrader
1061 will deal with the rest */
1062 if (I
->SelectedState
== pkgCache::State::Install
)
1063 Cache
->MarkInstall(I
,true);
1066 // Apply erasures now, they override everything else.
1067 for (I
= Cache
->PkgBegin();I
.end() != true; I
++)
1070 if (I
->SelectedState
== pkgCache::State::DeInstall
||
1071 I
->SelectedState
== pkgCache::State::Purge
)
1072 Cache
->MarkDelete(I
,I
->SelectedState
== pkgCache::State::Purge
);
1075 /* Resolve any problems that dselect created, allupgrade cannot handle
1076 such things. We do so quite agressively too.. */
1077 if (Cache
->BrokenCount() != 0)
1079 pkgProblemResolver
Fix(Cache
);
1081 // Hold back held packages.
1082 if (_config
->FindB("APT::Ingore-Hold",false) == false)
1084 for (pkgCache::PkgIterator I
= Cache
->PkgBegin(); I
.end() == false; I
++)
1086 if (I
->SelectedState
== pkgCache::State::Hold
)
1094 if (Fix
.Resolve() == false)
1096 ShowBroken(c1out
,Cache
);
1097 return _error
->Error("Internal Error, problem resolver broke stuff");
1101 // Now upgrade everything
1102 if (pkgAllUpgrade(Cache
) == false)
1104 ShowBroken(c1out
,Cache
);
1105 return _error
->Error("Internal Error, problem resolver broke stuff");
1108 return InstallPackages(Cache
,false);
1111 // DoClean - Remove download archives /*{{{*/
1112 // ---------------------------------------------------------------------
1114 bool DoClean(CommandLine
&CmdL
)
1117 Fetcher
.Clean(_config
->FindDir("Dir::Cache::archives"));
1118 Fetcher
.Clean(_config
->FindDir("Dir::Cache::archives") + "partial/");
1122 // DoAutoClean - Smartly remove downloaded archives /*{{{*/
1123 // ---------------------------------------------------------------------
1124 /* This is similar to clean but it only purges things that cannot be
1125 downloaded, that is old versions of cached packages. */
1126 class LogCleaner
: public pkgArchiveCleaner
1129 virtual void Erase(const char *File
,string Pkg
,string Ver
,struct stat
&St
)
1131 cout
<< "Del " << Pkg
<< " " << Ver
<< " [" << SizeToStr(St
.st_size
) << "B]" << endl
;
1133 if (_config
->FindB("APT::Get::Simulate") == false)
1138 bool DoAutoClean(CommandLine
&CmdL
)
1141 if (Cache
.Open() == false)
1146 return Cleaner
.Go(_config
->FindDir("Dir::Cache::archives"),*Cache
) &&
1147 Cleaner
.Go(_config
->FindDir("Dir::Cache::archives") + "partial/",*Cache
);
1150 // DoCheck - Perform the check operation /*{{{*/
1151 // ---------------------------------------------------------------------
1152 /* Opening automatically checks the system, this command is mostly used
1154 bool DoCheck(CommandLine
&CmdL
)
1163 // DoSource - Fetch a source archive /*{{{*/
1164 // ---------------------------------------------------------------------
1165 /* Fetch souce packages */
1173 bool DoSource(CommandLine
&CmdL
)
1176 if (Cache
.Open(false) == false)
1179 if (CmdL
.FileSize() <= 1)
1180 return _error
->Error("Must specify at least one package to fetch source for");
1182 // Read the source list
1184 if (List
.ReadMainList() == false)
1185 return _error
->Error("The list of sources could not be read.");
1187 // Create the text record parsers
1188 pkgRecords
Recs(Cache
);
1189 pkgSrcRecords
SrcRecs(List
);
1190 if (_error
->PendingError() == true)
1193 // Create the download object
1194 AcqTextStatus
Stat(ScreenWidth
,_config
->FindI("quiet",0));
1195 pkgAcquire
Fetcher(&Stat
);
1197 DscFile
*Dsc
= new DscFile
[CmdL
.FileSize()];
1199 // Load the requestd sources into the fetcher
1201 for (const char **I
= CmdL
.FileList
+ 1; *I
!= 0; I
++, J
++)
1205 /* Lookup the version of the package we would install if we were to
1206 install a version and determine the source package name, then look
1207 in the archive for a source package of the same name. In theory
1208 we could stash the version string as well and match that too but
1209 today there aren't multi source versions in the archive. */
1210 pkgCache::PkgIterator Pkg
= Cache
->FindPkg(*I
);
1211 if (Pkg
.end() == false)
1213 pkgCache::VerIterator Ver
= Cache
->GetCandidateVer(Pkg
);
1214 if (Ver
.end() == false)
1216 pkgRecords::Parser
&Parse
= Recs
.Lookup(Ver
.FileList());
1217 Src
= Parse
.SourcePkg();
1221 // No source package name..
1222 if (Src
.empty() == true)
1226 pkgSrcRecords::Parser
*Last
= 0;
1227 unsigned long Offset
= 0;
1229 bool IsMatch
= false;
1231 // Iterate over all of the hits
1232 pkgSrcRecords::Parser
*Parse
;
1234 while ((Parse
= SrcRecs
.Find(Src
.c_str(),false)) != 0)
1236 string Ver
= Parse
->Version();
1238 // Skip name mismatches
1239 if (IsMatch
== true && Parse
->Package() != Src
)
1242 // Newer version or an exact match
1243 if (Last
== 0 || pkgVersionCompare(Version
,Ver
) < 0 ||
1244 (Parse
->Package() == Src
&& IsMatch
== false))
1246 IsMatch
= Parse
->Package() == Src
;
1248 Offset
= Parse
->Offset();
1254 return _error
->Error("Unable to find a source package for %s",Src
.c_str());
1257 vector
<pkgSrcRecords::File
> Lst
;
1258 if (Last
->Jump(Offset
) == false || Last
->Files(Lst
) == false)
1261 // Load them into the fetcher
1262 for (vector
<pkgSrcRecords::File
>::const_iterator I
= Lst
.begin();
1263 I
!= Lst
.end(); I
++)
1265 // Try to guess what sort of file it is we are getting.
1267 if (I
->Path
.find(".dsc") != string::npos
)
1270 Dsc
[J
].Package
= Last
->Package();
1271 Dsc
[J
].Version
= Last
->Version();
1272 Dsc
[J
].Dsc
= flNotDir(I
->Path
);
1275 if (I
->Path
.find(".tar.gz") != string::npos
)
1277 if (I
->Path
.find(".diff.gz") != string::npos
)
1280 // Diff only mode only fetches .diff files
1281 if (_config
->FindB("APT::Get::Diff-Only",false) == true &&
1285 // Tar only mode only fetches .tar files
1286 if (_config
->FindB("APT::Get::Tar-Only",false) == true &&
1290 new pkgAcqFile(&Fetcher
,Last
->Source()->ArchiveURI(I
->Path
),
1291 I
->MD5Hash
,I
->Size
,Last
->Source()->SourceInfo(Src
,
1292 Last
->Version(),Comp
),Src
);
1296 // Display statistics
1297 unsigned long FetchBytes
= Fetcher
.FetchNeeded();
1298 unsigned long FetchPBytes
= Fetcher
.PartialPresent();
1299 unsigned long DebBytes
= Fetcher
.TotalNeeded();
1301 // Check for enough free space
1303 string OutputDir
= ".";
1304 if (statfs(OutputDir
.c_str(),&Buf
) != 0)
1305 return _error
->Errno("statfs","Couldn't determine free space in %s",
1307 if (unsigned(Buf
.f_bfree
) < (FetchBytes
- FetchPBytes
)/Buf
.f_bsize
)
1308 return _error
->Error("Sorry, you don't have enough free space in %s",
1312 c1out
<< "Need to get ";
1313 if (DebBytes
!= FetchBytes
)
1314 c1out
<< SizeToStr(FetchBytes
) << "B/" << SizeToStr(DebBytes
) << 'B';
1316 c1out
<< SizeToStr(DebBytes
) << 'B';
1317 c1out
<< " of source archives." << endl
;
1319 if (_config
->FindB("APT::Get::Simulate",false) == true)
1321 for (unsigned I
= 0; I
!= J
; I
++)
1322 cout
<< "Fetch Source " << Dsc
[I
].Package
<< endl
;
1326 // Just print out the uris an exit if the --print-uris flag was used
1327 if (_config
->FindB("APT::Get::Print-URIs") == true)
1329 pkgAcquire::UriIterator I
= Fetcher
.UriBegin();
1330 for (; I
!= Fetcher
.UriEnd(); I
++)
1331 cout
<< '\'' << I
->URI
<< "' " << flNotDir(I
->Owner
->DestFile
) << ' ' <<
1332 I
->Owner
->FileSize
<< ' ' << I
->Owner
->MD5Sum() << endl
;
1337 if (Fetcher
.Run() == pkgAcquire::Failed
)
1340 // Print error messages
1341 bool Failed
= false;
1342 for (pkgAcquire::Item
**I
= Fetcher
.ItemsBegin(); I
!= Fetcher
.ItemsEnd(); I
++)
1344 if ((*I
)->Status
== pkgAcquire::Item::StatDone
&&
1345 (*I
)->Complete
== true)
1348 cerr
<< "Failed to fetch " << (*I
)->DescURI() << endl
;
1349 cerr
<< " " << (*I
)->ErrorText
<< endl
;
1353 return _error
->Error("Failed to fetch some archives.");
1355 if (_config
->FindB("APT::Get::Download-only",false) == true)
1358 // Unpack the sources
1359 pid_t Process
= ExecFork();
1363 for (unsigned I
= 0; I
!= J
; I
++)
1365 string Dir
= Dsc
[I
].Package
+ '-' + pkgBaseVersion(Dsc
[I
].Version
.c_str());
1367 // Diff only mode only fetches .diff files
1368 if (_config
->FindB("APT::Get::Diff-Only",false) == true ||
1369 _config
->FindB("APT::Get::Tar-Only",false) == true)
1372 // See if the package is already unpacked
1374 if (stat(Dir
.c_str(),&Stat
) == 0 &&
1375 S_ISDIR(Stat
.st_mode
) != 0)
1377 c0out
<< "Skipping unpack of already unpacked source in " << Dir
<< endl
;
1383 snprintf(S
,sizeof(S
),"%s -x %s",
1384 _config
->Find("Dir::Bin::dpkg-source","dpkg-source").c_str(),
1385 Dsc
[I
].Dsc
.c_str());
1388 cerr
<< "Unpack command '" << S
<< "' failed." << endl
;
1393 // Try to compile it with dpkg-buildpackage
1394 if (_config
->FindB("APT::Get::Compile",false) == true)
1396 // Call dpkg-buildpackage
1398 snprintf(S
,sizeof(S
),"cd %s && %s %s",
1400 _config
->Find("Dir::Bin::dpkg-buildpackage","dpkg-buildpackage").c_str(),
1401 _config
->Find("DPkg::Build-Options","-b -uc").c_str());
1405 cerr
<< "Build command '" << S
<< "' failed." << endl
;
1414 // Wait for the subprocess
1416 while (waitpid(Process
,&Status
,0) != Process
)
1420 return _error
->Errno("waitpid","Couldn't wait for subprocess");
1423 if (WIFEXITED(Status
) == 0 || WEXITSTATUS(Status
) != 0)
1424 return _error
->Error("Child process failed");
1430 // ShowHelp - Show a help screen /*{{{*/
1431 // ---------------------------------------------------------------------
1433 bool ShowHelp(CommandLine
&CmdL
)
1435 cout
<< PACKAGE
<< ' ' << VERSION
<< " for " << ARCHITECTURE
<<
1436 " compiled on " << __DATE__
<< " " << __TIME__
<< endl
;
1437 if (_config
->FindB("version") == true)
1440 cout
<< "Usage: apt-get [options] command" << endl
;
1441 cout
<< " apt-get [options] install pkg1 [pkg2 ...]" << endl
;
1443 cout
<< "apt-get is a simple command line interface for downloading and" << endl
;
1444 cout
<< "installing packages. The most frequently used commands are update" << endl
;
1445 cout
<< "and install." << endl
;
1447 cout
<< "Commands:" << endl
;
1448 cout
<< " update - Retrieve new lists of packages" << endl
;
1449 cout
<< " upgrade - Perform an upgrade" << endl
;
1450 cout
<< " install - Install new packages (pkg is libc6 not libc6.deb)" << endl
;
1451 cout
<< " remove - Remove packages" << endl
;
1452 cout
<< " source - Download source archives" << endl
;
1453 cout
<< " dist-upgrade - Distribution upgrade, see apt-get(8)" << endl
;
1454 cout
<< " dselect-upgrade - Follow dselect selections" << endl
;
1455 cout
<< " clean - Erase downloaded archive files" << endl
;
1456 cout
<< " autoclean - Erase old downloaded archive files" << endl
;
1457 cout
<< " check - Verify that there are no broken dependencies" << endl
;
1459 cout
<< "Options:" << endl
;
1460 cout
<< " -h This help text." << endl
;
1461 cout
<< " -q Loggable output - no progress indicator" << endl
;
1462 cout
<< " -qq No output except for errors" << endl
;
1463 cout
<< " -d Download only - do NOT install or unpack archives" << endl
;
1464 cout
<< " -s No-act. Perform ordering simulation" << endl
;
1465 cout
<< " -y Assume Yes to all queries and do not prompt" << endl
;
1466 cout
<< " -f Attempt to continue if the integrity check fails" << endl
;
1467 cout
<< " -m Attempt to continue if archives are unlocatable" << endl
;
1468 cout
<< " -u Show a list of upgraded packages as well" << endl
;
1469 cout
<< " -b Build the source package after fetching it" << endl
;
1470 cout
<< " -c=? Read this configuration file" << endl
;
1471 cout
<< " -o=? Set an arbitary configuration option, eg -o dir::cache=/tmp" << endl
;
1472 cout
<< "See the apt-get(8), sources.list(5) and apt.conf(5) manual" << endl
;
1473 cout
<< "pages for more information and options." << endl
;
1477 // GetInitialize - Initialize things for apt-get /*{{{*/
1478 // ---------------------------------------------------------------------
1480 void GetInitialize()
1482 _config
->Set("quiet",0);
1483 _config
->Set("help",false);
1484 _config
->Set("APT::Get::Download-Only",false);
1485 _config
->Set("APT::Get::Simulate",false);
1486 _config
->Set("APT::Get::Assume-Yes",false);
1487 _config
->Set("APT::Get::Fix-Broken",false);
1488 _config
->Set("APT::Get::Force-Yes",false);
1489 _config
->Set("APT::Get::APT::Get::No-List-Cleanup",true);
1492 // SigWinch - Window size change signal handler /*{{{*/
1493 // ---------------------------------------------------------------------
1497 // Riped from GNU ls
1501 if (ioctl(1, TIOCGWINSZ
, &ws
) != -1 && ws
.ws_col
>= 5)
1502 ScreenWidth
= ws
.ws_col
- 1;
1507 int main(int argc
,const char *argv
[])
1509 CommandLine::Args Args
[] = {
1510 {'h',"help","help",0},
1511 {'v',"version","version",0},
1512 {'q',"quiet","quiet",CommandLine::IntLevel
},
1513 {'q',"silent","quiet",CommandLine::IntLevel
},
1514 {'d',"download-only","APT::Get::Download-Only",0},
1515 {'b',"compile","APT::Get::Compile",0},
1516 {'b',"build","APT::Get::Compile",0},
1517 {'s',"simulate","APT::Get::Simulate",0},
1518 {'s',"just-print","APT::Get::Simulate",0},
1519 {'s',"recon","APT::Get::Simulate",0},
1520 {'s',"no-act","APT::Get::Simulate",0},
1521 {'y',"yes","APT::Get::Assume-Yes",0},
1522 {'y',"assume-yes","APT::Get::Assume-Yes",0},
1523 {'f',"fix-broken","APT::Get::Fix-Broken",0},
1524 {'u',"show-upgraded","APT::Get::Show-Upgraded",0},
1525 {'m',"ignore-missing","APT::Get::Fix-Missing",0},
1526 {0,"no-download","APT::Get::No-Download",0},
1527 {0,"fix-missing","APT::Get::Fix-Missing",0},
1528 {0,"ignore-hold","APT::Ingore-Hold",0},
1529 {0,"no-upgrade","APT::Get::no-upgrade",0},
1530 {0,"force-yes","APT::Get::force-yes",0},
1531 {0,"print-uris","APT::Get::Print-URIs",0},
1532 {0,"diff-only","APT::Get::Diff-Only",0},
1533 {0,"tar-only","APT::Get::tar-Only",0},
1534 {0,"purge","APT::Get::Purge",0},
1535 {0,"list-cleanup","APT::Get::List-Cleanup",0},
1536 {'c',"config-file",0,CommandLine::ConfigFile
},
1537 {'o',"option",0,CommandLine::ArbItem
},
1539 CommandLine::Dispatch Cmds
[] = {{"update",&DoUpdate
},
1540 {"upgrade",&DoUpgrade
},
1541 {"install",&DoInstall
},
1542 {"remove",&DoInstall
},
1543 {"dist-upgrade",&DoDistUpgrade
},
1544 {"dselect-upgrade",&DoDSelectUpgrade
},
1546 {"autoclean",&DoAutoClean
},
1548 {"source",&DoSource
},
1552 // Parse the command line and initialize the package library
1553 CommandLine
CmdL(Args
,_config
);
1554 if (pkgInitialize(*_config
) == false ||
1555 CmdL
.Parse(argc
,argv
) == false)
1557 _error
->DumpErrors();
1561 // See if the help should be shown
1562 if (_config
->FindB("help") == true ||
1563 _config
->FindB("version") == true ||
1564 CmdL
.FileSize() == 0)
1565 return ShowHelp(CmdL
);
1567 // Deal with stdout not being a tty
1568 if (ttyname(STDOUT_FILENO
) == 0 && _config
->FindI("quiet",0) < 1)
1569 _config
->Set("quiet","1");
1571 // Setup the output streams
1572 c0out
.rdbuf(cout
.rdbuf());
1573 c1out
.rdbuf(cout
.rdbuf());
1574 c2out
.rdbuf(cout
.rdbuf());
1575 if (_config
->FindI("quiet",0) > 0)
1576 c0out
.rdbuf(devnull
.rdbuf());
1577 if (_config
->FindI("quiet",0) > 1)
1578 c1out
.rdbuf(devnull
.rdbuf());
1580 // Setup the signals
1581 signal(SIGPIPE
,SIG_IGN
);
1582 signal(SIGWINCH
,SigWinch
);
1585 // Match the operation
1586 CmdL
.DispatchArg(Cmds
);
1588 // Print any errors or warnings found during parsing
1589 if (_error
->empty() == false)
1591 bool Errors
= _error
->PendingError();
1592 _error
->DumpErrors();
1593 return Errors
== true?100:0;