1 // Include files /*{{{*/
4 #include <apt-pkg/configuration.h>
5 #include <apt-pkg/strutl.h>
6 #include <apt-pkg/error.h>
7 #include <apt-pkg/cachefile.h>
8 #include <apt-pkg/pkgrecords.h>
9 #include <apt-pkg/policy.h>
10 #include <apt-pkg/depcache.h>
11 #include <apt-pkg/pkgcache.h>
12 #include <apt-pkg/cacheiterators.h>
14 #include <apt-private/private-output.h>
15 #include <apt-private/private-cachefile.h>
26 #include <sys/ioctl.h>
35 std::ostream
c0out(0);
36 std::ostream
c1out(0);
37 std::ostream
c2out(0);
38 std::ofstream
devnull("/dev/null");
41 unsigned int ScreenWidth
= 80 - 1; /* - 1 for the cursor */
43 // SigWinch - Window size change signal handler /*{{{*/
44 // ---------------------------------------------------------------------
46 static void SigWinch(int)
52 if (ioctl(1, TIOCGWINSZ
, &ws
) != -1 && ws
.ws_col
>= 5)
53 ScreenWidth
= ws
.ws_col
- 1;
57 bool InitOutput(std::basic_streambuf
<char> * const out
) /*{{{*/
59 if (!isatty(STDOUT_FILENO
) && _config
->FindI("quiet", -1) == -1)
60 _config
->Set("quiet","1");
65 if (_config
->FindI("quiet",0) > 0)
66 c0out
.rdbuf(devnull
.rdbuf());
67 if (_config
->FindI("quiet",0) > 1)
68 c1out
.rdbuf(devnull
.rdbuf());
70 // deal with window size changes
71 signal(SIGWINCH
,SigWinch
);
76 _config
->Set("APT::Color", "false");
77 _config
->Set("APT::Color::Highlight", "");
78 _config
->Set("APT::Color::Neutral", "");
81 _config
->CndSet("APT::Color::Highlight", "\x1B[32m");
82 _config
->CndSet("APT::Color::Neutral", "\x1B[0m");
84 _config
->CndSet("APT::Color::Red", "\x1B[31m");
85 _config
->CndSet("APT::Color::Green", "\x1B[32m");
86 _config
->CndSet("APT::Color::Yellow", "\x1B[33m");
87 _config
->CndSet("APT::Color::Blue", "\x1B[34m");
88 _config
->CndSet("APT::Color::Magenta", "\x1B[35m");
89 _config
->CndSet("APT::Color::Cyan", "\x1B[36m");
90 _config
->CndSet("APT::Color::White", "\x1B[37m");
96 static std::string
GetArchiveSuite(pkgCacheFile
&/*CacheFile*/, pkgCache::VerIterator ver
) /*{{{*/
98 std::string suite
= "";
99 if (ver
&& ver
.FileList())
101 pkgCache::VerFileIterator VF
= ver
.FileList();
102 for (; VF
.end() == false ; ++VF
)
104 if(VF
.File() == NULL
|| VF
.File().Archive() == NULL
)
105 suite
= suite
+ "," + _("unknown");
107 suite
= suite
+ "," + VF
.File().Archive();
108 //suite = VF.File().Archive();
110 suite
= suite
.erase(0, 1);
115 static std::string
GetFlagsStr(pkgCacheFile
&CacheFile
, pkgCache::PkgIterator P
)/*{{{*/
117 pkgDepCache
*DepCache
= CacheFile
.GetDepCache();
118 pkgDepCache::StateCache
&state
= (*DepCache
)[P
];
120 std::string flags_str
;
121 if (state
.NowBroken())
123 if (P
.CurrentVer() && state
.Upgradable() && state
.CandidateVer
!= NULL
)
125 else if (P
.CurrentVer() != NULL
)
132 static std::string
GetCandidateVersion(pkgCacheFile
&CacheFile
, pkgCache::PkgIterator P
)/*{{{*/
134 pkgPolicy
*policy
= CacheFile
.GetPolicy();
135 pkgCache::VerIterator cand
= policy
->GetCandidateVer(P
);
137 return cand
? cand
.VerStr() : "(none)";
140 static std::string
GetInstalledVersion(pkgCacheFile
&/*CacheFile*/, pkgCache::PkgIterator P
)/*{{{*/
142 pkgCache::VerIterator inst
= P
.CurrentVer();
144 return inst
? inst
.VerStr() : "(none)";
147 static std::string
GetVersion(pkgCacheFile
&/*CacheFile*/, pkgCache::VerIterator V
)/*{{{*/
149 pkgCache::PkgIterator P
= V
.ParentPkg();
150 if (V
== P
.CurrentVer())
152 std::string inst_str
= DeNull(V
.VerStr());
153 #if 0 // FIXME: do we want this or something like this?
154 pkgDepCache
*DepCache
= CacheFile
.GetDepCache();
155 pkgDepCache::StateCache
&state
= (*DepCache
)[P
];
156 if (state
.Upgradable())
157 return "**"+inst_str
;
163 return DeNull(V
.VerStr());
167 static std::string
GetArchitecture(pkgCacheFile
&CacheFile
, pkgCache::PkgIterator P
)/*{{{*/
169 if (P
->CurrentVer
== 0)
171 pkgDepCache
* const DepCache
= CacheFile
.GetDepCache();
172 pkgDepCache::StateCache
const &state
= (*DepCache
)[P
];
173 if (state
.CandidateVer
!= NULL
)
175 pkgCache::VerIterator
const CandV(CacheFile
, state
.CandidateVer
);
180 pkgCache::VerIterator
const V
= P
.VersionList();
181 if (V
.end() == false)
188 return P
.CurrentVer().Arch();
191 static std::string
GetShortDescription(pkgCacheFile
&CacheFile
, pkgRecords
&records
, pkgCache::PkgIterator P
)/*{{{*/
193 pkgPolicy
*policy
= CacheFile
.GetPolicy();
195 pkgCache::VerIterator ver
;
197 ver
= P
.CurrentVer();
199 ver
= policy
->GetCandidateVer(P
);
201 std::string ShortDescription
= "(none)";
204 pkgCache::DescIterator
const Desc
= ver
.TranslatedDescription();
205 if (Desc
.end() == false)
207 pkgRecords::Parser
& parser
= records
.Lookup(Desc
.FileList());
208 ShortDescription
= parser
.ShortDesc();
211 return ShortDescription
;
214 static std::string
GetLongDescription(pkgCacheFile
&CacheFile
, pkgRecords
&records
, pkgCache::PkgIterator P
)/*{{{*/
216 pkgPolicy
*policy
= CacheFile
.GetPolicy();
218 pkgCache::VerIterator ver
;
219 if (P
->CurrentVer
!= 0)
220 ver
= P
.CurrentVer();
222 ver
= policy
->GetCandidateVer(P
);
224 std::string
const EmptyDescription
= "(none)";
225 if(ver
.end() == true)
226 return EmptyDescription
;
228 pkgCache::DescIterator
const Desc
= ver
.TranslatedDescription();
229 if (Desc
.end() == false)
231 pkgRecords::Parser
& parser
= records
.Lookup(Desc
.FileList());
232 std::string
const longdesc
= parser
.LongDesc();
233 if (longdesc
.empty() == false)
234 return SubstVar(longdesc
, "\n ", "\n ");
236 return EmptyDescription
;
239 void ListSingleVersion(pkgCacheFile
&CacheFile
, pkgRecords
&records
, /*{{{*/
240 pkgCache::VerIterator
const &V
, std::ostream
&out
,
241 std::string
const &format
)
243 pkgCache::PkgIterator
const P
= V
.ParentPkg();
244 pkgDepCache
* const DepCache
= CacheFile
.GetDepCache();
245 pkgDepCache::StateCache
const &state
= (*DepCache
)[P
];
248 if (_config
->FindB("APT::Cmd::use-format", false))
249 output
= _config
->Find("APT::Cmd::format", "${db::Status-Abbrev} ${Package} ${Version} ${Origin} ${Description}");
253 // FIXME: some of these names are really icky – and all is nowhere documented
254 output
= SubstVar(output
, "${db::Status-Abbrev}", GetFlagsStr(CacheFile
, P
));
255 output
= SubstVar(output
, "${Package}", P
.Name());
256 std::string
const ArchStr
= GetArchitecture(CacheFile
, P
);
257 output
= SubstVar(output
, "${Architecture}", ArchStr
);
258 std::string
const InstalledVerStr
= GetInstalledVersion(CacheFile
, P
);
259 output
= SubstVar(output
, "${installed:Version}", InstalledVerStr
);
260 std::string
const CandidateVerStr
= GetCandidateVersion(CacheFile
, P
);
261 output
= SubstVar(output
, "${candidate:Version}", CandidateVerStr
);
262 std::string
const VersionStr
= GetVersion(CacheFile
, V
);
263 output
= SubstVar(output
, "${Version}", VersionStr
);
264 output
= SubstVar(output
, "${Origin}", GetArchiveSuite(CacheFile
, V
));
266 std::string StatusStr
= "";
267 if (P
->CurrentVer
!= 0)
269 if (P
.CurrentVer() == V
)
271 if (state
.Upgradable() && state
.CandidateVer
!= NULL
)
272 strprintf(StatusStr
, _("[installed,upgradable to: %s]"),
273 CandidateVerStr
.c_str());
274 else if (V
.Downloadable() == false)
275 StatusStr
= _("[installed,local]");
276 else if(V
.Automatic() == true && state
.Garbage
== true)
277 StatusStr
= _("[installed,auto-removable]");
278 else if ((state
.Flags
& pkgCache::Flag::Auto
) == pkgCache::Flag::Auto
)
279 StatusStr
= _("[installed,automatic]");
281 StatusStr
= _("[installed]");
283 else if (state
.CandidateVer
== V
&& state
.Upgradable())
284 strprintf(StatusStr
, _("[upgradable from: %s]"),
285 InstalledVerStr
.c_str());
287 else if (V
.ParentPkg()->CurrentState
== pkgCache::State::ConfigFiles
)
288 StatusStr
= _("[residual-config]");
289 output
= SubstVar(output
, "${apt:Status}", StatusStr
);
290 output
= SubstVar(output
, "${color:highlight}", _config
->Find("APT::Color::Highlight", ""));
291 output
= SubstVar(output
, "${color:neutral}", _config
->Find("APT::Color::Neutral", ""));
292 output
= SubstVar(output
, "${Description}", GetShortDescription(CacheFile
, records
, P
));
293 output
= SubstVar(output
, "${LongDescription}", GetLongDescription(CacheFile
, records
, P
));
294 output
= SubstVar(output
, "${ }${ }", "${ }");
295 output
= SubstVar(output
, "${ }\n", "\n");
296 output
= SubstVar(output
, "${ }", " ");
297 if (APT::String::Endswith(output
, " ") == true)
298 output
.erase(output
.length() - 1);
303 // ShowList - Show a list /*{{{*/
304 // ---------------------------------------------------------------------
305 /* This prints out a string of space separated words with a title and
306 a two space indent line wraped to the current screen width. */
307 bool ShowList(ostream
&out
,string Title
,string List
,string VersionsList
)
309 if (List
.empty() == true)
311 // trim trailing space
312 int NonSpace
= List
.find_last_not_of(' ');
315 List
= List
.erase(NonSpace
+ 1);
316 if (List
.empty() == true)
320 // Acount for the leading space
321 int ScreenWidth
= ::ScreenWidth
- 3;
323 out
<< Title
<< endl
;
324 string::size_type Start
= 0;
325 string::size_type VersionsStart
= 0;
326 while (Start
< List
.size())
328 if(_config
->FindB("APT::Get::Show-Versions",false) == true &&
329 VersionsList
.size() > 0) {
330 string::size_type End
;
331 string::size_type VersionsEnd
;
333 End
= List
.find(' ',Start
);
334 VersionsEnd
= VersionsList
.find('\n', VersionsStart
);
336 out
<< " " << string(List
,Start
,End
- Start
) << " (" <<
337 string(VersionsList
,VersionsStart
,VersionsEnd
- VersionsStart
) <<
340 if (End
== string::npos
|| End
< Start
)
341 End
= Start
+ ScreenWidth
;
344 VersionsStart
= VersionsEnd
+ 1;
346 string::size_type End
;
348 if (Start
+ ScreenWidth
>= List
.size())
351 End
= List
.rfind(' ',Start
+ScreenWidth
);
353 if (End
== string::npos
|| End
< Start
)
354 End
= Start
+ ScreenWidth
;
355 out
<< " " << string(List
,Start
,End
- Start
) << endl
;
363 // ShowBroken - Debugging aide /*{{{*/
364 // ---------------------------------------------------------------------
365 /* This prints out the names of all the packages that are broken along
366 with the name of each each broken dependency and a quite version
369 The output looks like:
370 The following packages have unmet dependencies:
371 exim: Depends: libc6 (>= 2.1.94) but 2.1.3-10 is to be installed
372 Depends: libldap2 (>= 2.0.2-2) but it is not going to be installed
373 Depends: libsasl7 but it is not going to be installed
375 static void ShowBrokenPackage(ostream
&out
, pkgCacheFile
* const Cache
, pkgCache::PkgIterator
const &Pkg
, bool const Now
)
379 if ((*Cache
)[Pkg
].NowBroken() == false)
384 if ((*Cache
)[Pkg
].InstBroken() == false)
388 // Print out each package and the failed dependencies
389 out
<< " " << Pkg
.FullName(true) << " :";
390 unsigned const Indent
= Pkg
.FullName(true).size() + 3;
392 pkgCache::VerIterator Ver
;
395 Ver
= Pkg
.CurrentVer();
397 Ver
= (*Cache
)[Pkg
].InstVerIter(*Cache
);
399 if (Ver
.end() == true)
405 for (pkgCache::DepIterator D
= Ver
.DependsList(); D
.end() == false;)
407 // Compute a single dependency element (glob or)
408 pkgCache::DepIterator Start
;
409 pkgCache::DepIterator End
;
410 D
.GlobOr(Start
,End
); // advances D
412 if ((*Cache
)->IsImportantDep(End
) == false)
417 if (((*Cache
)[End
] & pkgDepCache::DepGNow
) == pkgDepCache::DepGNow
)
422 if (((*Cache
)[End
] & pkgDepCache::DepGInstall
) == pkgDepCache::DepGInstall
)
430 for (unsigned J
= 0; J
!= Indent
; J
++)
434 if (FirstOr
== false)
436 for (unsigned J
= 0; J
!= strlen(End
.DepType()) + 3; J
++)
440 out
<< ' ' << End
.DepType() << ": ";
443 out
<< Start
.TargetPkg().FullName(true);
445 // Show a quick summary of the version requirements
446 if (Start
.TargetVer() != 0)
447 out
<< " (" << Start
.CompType() << " " << Start
.TargetVer() << ")";
449 /* Show a summary of the target package if possible. In the case
450 of virtual packages we show nothing */
451 pkgCache::PkgIterator Targ
= Start
.TargetPkg();
452 if (Targ
->ProvidesList
== 0)
455 pkgCache::VerIterator Ver
= (*Cache
)[Targ
].InstVerIter(*Cache
);
457 Ver
= Targ
.CurrentVer();
459 if (Ver
.end() == false)
462 ioprintf(out
,_("but %s is installed"),Ver
.VerStr());
464 ioprintf(out
,_("but %s is to be installed"),Ver
.VerStr());
468 if ((*Cache
)[Targ
].CandidateVerIter(*Cache
).end() == true)
470 if (Targ
->ProvidesList
== 0)
471 out
<< _("but it is not installable");
473 out
<< _("but it is a virtual package");
476 out
<< (Now
?_("but it is not installed"):_("but it is not going to be installed"));
490 void ShowBroken(ostream
&out
, CacheFile
&Cache
, bool const Now
)
492 if (Cache
->BrokenCount() == 0)
495 out
<< _("The following packages have unmet dependencies:") << endl
;
496 SortedPackageUniverse
Universe(Cache
);
497 for (auto const &Pkg
: Universe
)
498 ShowBrokenPackage(out
, &Cache
, Pkg
, Now
);
500 void ShowBroken(ostream
&out
, pkgCacheFile
&Cache
, bool const Now
)
502 if (Cache
->BrokenCount() == 0)
505 out
<< _("The following packages have unmet dependencies:") << endl
;
506 APT::PackageUniverse
Universe(Cache
);
507 for (auto const &Pkg
: Universe
)
508 ShowBrokenPackage(out
, &Cache
, Pkg
, Now
);
511 // ShowNew - Show packages to newly install /*{{{*/
512 void ShowNew(ostream
&out
,CacheFile
&Cache
)
514 SortedPackageUniverse
Universe(Cache
);
515 ShowList(out
,_("The following NEW packages will be installed:"), Universe
,
516 [&Cache
](pkgCache::PkgIterator
const &Pkg
) { return Cache
[Pkg
].NewInstall(); },
518 CandidateVersion(&Cache
));
521 // ShowDel - Show packages to delete /*{{{*/
522 void ShowDel(ostream
&out
,CacheFile
&Cache
)
524 SortedPackageUniverse
Universe(Cache
);
525 ShowList(out
,_("The following packages will be REMOVED:"), Universe
,
526 [&Cache
](pkgCache::PkgIterator
const &Pkg
) { return Cache
[Pkg
].Delete(); },
527 [&Cache
](pkgCache::PkgIterator
const &Pkg
)
529 std::string str
= PrettyFullName(Pkg
);
530 if (((*Cache
)[Pkg
].iFlags
& pkgDepCache::Purge
) == pkgDepCache::Purge
)
534 CandidateVersion(&Cache
));
537 // ShowKept - Show kept packages /*{{{*/
538 void ShowKept(ostream
&out
,CacheFile
&Cache
)
540 SortedPackageUniverse
Universe(Cache
);
541 ShowList(out
,_("The following packages have been kept back:"), Universe
,
542 [&Cache
](pkgCache::PkgIterator
const &Pkg
)
544 return Cache
[Pkg
].Upgrade() == false &&
545 Cache
[Pkg
].Upgradable() == true &&
546 Pkg
->CurrentVer
!= 0 &&
547 Cache
[Pkg
].Delete() == false;
550 CurrentToCandidateVersion(&Cache
));
553 // ShowUpgraded - Show upgraded packages /*{{{*/
554 void ShowUpgraded(ostream
&out
,CacheFile
&Cache
)
556 SortedPackageUniverse
Universe(Cache
);
557 ShowList(out
,_("The following packages will be upgraded:"), Universe
,
558 [&Cache
](pkgCache::PkgIterator
const &Pkg
)
560 return Cache
[Pkg
].Upgrade() == true && Cache
[Pkg
].NewInstall() == false;
563 CurrentToCandidateVersion(&Cache
));
566 // ShowDowngraded - Show downgraded packages /*{{{*/
567 // ---------------------------------------------------------------------
569 bool ShowDowngraded(ostream
&out
,CacheFile
&Cache
)
571 SortedPackageUniverse
Universe(Cache
);
572 return ShowList(out
,_("The following packages will be DOWNGRADED:"), Universe
,
573 [&Cache
](pkgCache::PkgIterator
const &Pkg
)
575 return Cache
[Pkg
].Downgrade() == true && Cache
[Pkg
].NewInstall() == false;
578 CurrentToCandidateVersion(&Cache
));
581 // ShowHold - Show held but changed packages /*{{{*/
582 bool ShowHold(ostream
&out
,CacheFile
&Cache
)
584 SortedPackageUniverse
Universe(Cache
);
585 return ShowList(out
,_("The following held packages will be changed:"), Universe
,
586 [&Cache
](pkgCache::PkgIterator
const &Pkg
)
588 return Pkg
->SelectedState
== pkgCache::State::Hold
&&
589 Cache
[Pkg
].InstallVer
!= (pkgCache::Version
*)Pkg
.CurrentVer();
592 CurrentToCandidateVersion(&Cache
));
595 // ShowEssential - Show an essential package warning /*{{{*/
596 // ---------------------------------------------------------------------
597 /* This prints out a warning message that is not to be ignored. It shows
598 all essential packages and their dependents that are to be removed.
599 It is insanely risky to remove the dependents of an essential package! */
600 struct APT_HIDDEN PrettyFullNameWithDue
{
601 std::map
<unsigned long long, pkgCache::PkgIterator
> due
;
602 PrettyFullNameWithDue() {}
603 std::string
operator() (pkgCache::PkgIterator
const &Pkg
)
605 std::string
const A
= PrettyFullName(Pkg
);
606 std::map
<unsigned long long, pkgCache::PkgIterator
>::const_iterator d
= due
.find(Pkg
->ID
);
610 std::string
const B
= PrettyFullName(d
->second
);
611 std::ostringstream outstr
;
612 ioprintf(outstr
, _("%s (due to %s)"), A
.c_str(), B
.c_str());
616 bool ShowEssential(ostream
&out
,CacheFile
&Cache
)
618 std::vector
<bool> Added(Cache
->Head().PackageCount
, false);
619 APT::PackageDeque pkglist
;
620 PrettyFullNameWithDue withdue
;
622 SortedPackageUniverse
Universe(Cache
);
623 for (pkgCache::PkgIterator
const &I
: Universe
)
625 if ((I
->Flags
& pkgCache::Flag::Essential
) != pkgCache::Flag::Essential
&&
626 (I
->Flags
& pkgCache::Flag::Important
) != pkgCache::Flag::Important
)
629 // The essential package is being removed
630 if (Cache
[I
].Delete() == false)
633 if (Added
[I
->ID
] == false)
639 if (I
->CurrentVer
== 0)
642 // Print out any essential package depenendents that are to be removed
643 for (pkgCache::DepIterator D
= I
.CurrentVer().DependsList(); D
.end() == false; ++D
)
645 // Skip everything but depends
646 if (D
->Type
!= pkgCache::Dep::PreDepends
&&
647 D
->Type
!= pkgCache::Dep::Depends
)
650 pkgCache::PkgIterator P
= D
.SmartTargetPkg();
651 if (Cache
[P
].Delete() == true)
653 if (Added
[P
->ID
] == true)
658 withdue
.due
[P
->ID
] = I
;
662 return ShowList(out
,_("WARNING: The following essential packages will be removed.\n"
663 "This should NOT be done unless you know exactly what you are doing!"),
664 pkglist
, &AlwaysTrue
, withdue
, &EmptyString
);
667 // Stats - Show some statistics /*{{{*/
668 // ---------------------------------------------------------------------
670 void Stats(ostream
&out
,pkgDepCache
&Dep
)
672 unsigned long Upgrade
= 0;
673 unsigned long Downgrade
= 0;
674 unsigned long Install
= 0;
675 unsigned long ReInstall
= 0;
676 for (pkgCache::PkgIterator I
= Dep
.PkgBegin(); I
.end() == false; ++I
)
678 if (Dep
[I
].NewInstall() == true)
682 if (Dep
[I
].Upgrade() == true)
685 if (Dep
[I
].Downgrade() == true)
689 if (Dep
[I
].Delete() == false && (Dep
[I
].iFlags
& pkgDepCache::ReInstall
) == pkgDepCache::ReInstall
)
693 ioprintf(out
,_("%lu upgraded, %lu newly installed, "),
697 ioprintf(out
,_("%lu reinstalled, "),ReInstall
);
699 ioprintf(out
,_("%lu downgraded, "),Downgrade
);
701 ioprintf(out
,_("%lu to remove and %lu not upgraded.\n"),
702 Dep
.DelCount(),Dep
.KeepCount());
704 if (Dep
.BadCount() != 0)
705 ioprintf(out
,_("%lu not fully installed or removed.\n"),
709 // YnPrompt - Yes No Prompt. /*{{{*/
710 // ---------------------------------------------------------------------
711 /* Returns true on a Yes.*/
712 bool YnPrompt(bool Default
)
714 /* nl_langinfo does not support LANGUAGE setting, so we unset it here
715 to have the help-message (hopefully) match the expected characters */
716 char * language
= getenv("LANGUAGE");
717 if (language
!= NULL
)
718 language
= strdup(language
);
719 if (language
!= NULL
)
720 unsetenv("LANGUAGE");
723 // TRANSLATOR: Yes/No question help-text: defaulting to Y[es]
724 // e.g. "Do you want to continue? [Y/n] "
725 // The user has to answer with an input matching the
726 // YESEXPR/NOEXPR defined in your l10n.
727 c2out
<< " " << _("[Y/n]") << " " << std::flush
;
729 // TRANSLATOR: Yes/No question help-text: defaulting to N[o]
730 // e.g. "Should this file be removed? [y/N] "
731 // The user has to answer with an input matching the
732 // YESEXPR/NOEXPR defined in your l10n.
733 c2out
<< " " << _("[y/N]") << " " << std::flush
;
735 if (language
!= NULL
)
737 setenv("LANGUAGE", language
, 0);
741 if (_config
->FindB("APT::Get::Assume-Yes",false) == true)
743 // TRANSLATOR: "Yes" answer printed for a yes/no question if --assume-yes is set
744 c1out
<< _("Y") << std::endl
;
747 else if (_config
->FindB("APT::Get::Assume-No",false) == true)
749 // TRANSLATOR: "No" answer printed for a yes/no question if --assume-no is set
750 c1out
<< _("N") << std::endl
;
754 char response
[1024] = "";
755 std::cin
.getline(response
, sizeof(response
));
760 if (strlen(response
) == 0)
766 Res
= regcomp(&Pattern
, nl_langinfo(YESEXPR
),
767 REG_EXTENDED
|REG_ICASE
|REG_NOSUB
);
771 regerror(Res
,&Pattern
,Error
,sizeof(Error
));
772 return _error
->Error(_("Regex compilation error - %s"),Error
);
775 Res
= regexec(&Pattern
, response
, 0, NULL
, 0);
781 // AnalPrompt - Annoying Yes No Prompt. /*{{{*/
782 // ---------------------------------------------------------------------
783 /* Returns true on a Yes.*/
784 bool AnalPrompt(const char *Text
)
787 std::cin
.getline(Buf
,sizeof(Buf
));
788 if (strcmp(Buf
,Text
) == 0)
794 std::string
PrettyFullName(pkgCache::PkgIterator
const &Pkg
)
796 return Pkg
.FullName(true);
798 std::string
CandidateVersion(pkgCacheFile
* const Cache
, pkgCache::PkgIterator
const &Pkg
)
800 return (*Cache
)[Pkg
].CandVersion
;
802 std::function
<std::string(pkgCache::PkgIterator
const &)> CandidateVersion(pkgCacheFile
* const Cache
)
804 return std::bind(static_cast<std::string(*)(pkgCacheFile
* const, pkgCache::PkgIterator
const&)>(&CandidateVersion
), Cache
, std::placeholders::_1
);
806 std::string
CurrentToCandidateVersion(pkgCacheFile
* const Cache
, pkgCache::PkgIterator
const &Pkg
)
808 return std::string((*Cache
)[Pkg
].CurVersion
) + " => " + (*Cache
)[Pkg
].CandVersion
;
810 std::function
<std::string(pkgCache::PkgIterator
const &)> CurrentToCandidateVersion(pkgCacheFile
* const Cache
)
812 return std::bind(static_cast<std::string(*)(pkgCacheFile
* const, pkgCache::PkgIterator
const&)>(&CurrentToCandidateVersion
), Cache
, std::placeholders::_1
);
814 bool AlwaysTrue(pkgCache::PkgIterator
const &)
818 std::string
EmptyString(pkgCache::PkgIterator
const &)
820 return std::string();