2 * dselect - Debian package maintenance user interface
3 * pkgsublist.cc - status modification and recursive package list handling
5 * Copyright © 1995 Ian Jackson <ijackson@chiark.greenend.org.uk>
6 * Copyright © 2007-2014 Guillem Jover <guillem@debian.org>
8 * This is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
29 #include <dpkg/i18n.h>
30 #include <dpkg/dpkg.h>
31 #include <dpkg/dpkg-db.h>
36 void packagelist::add(pkginfo *pkg) {
37 debug(dbg_general, "packagelist[%p]::add(pkginfo %s)",
38 this, pkg_name(pkg, pnaw_always));
39 if (!recursive || // never add things to top level
40 !pkg->clientdata || // don't add pure virtual packages
41 pkg->clientdata->uprec) // don't add ones already in the recursive list
43 debug(dbg_general, "packagelist[%p]::add(pkginfo %s) adding",
44 this, pkg_name(pkg, pnaw_always));
45 perpackagestate *state= &datatable[nitems];
47 state->direct= state->original= pkg->clientdata->selected;
48 state->suggested= state->selected= pkg->clientdata->selected;
49 state->spriority= sp_inherit; state->dpriority= dp_none;
50 state->uprec= pkg->clientdata;
51 state->relations.init();
52 pkg->clientdata= state;
58 packagelist::add(pkginfo *pkg, pkgwant nw)
60 debug(dbg_general, "packagelist[%p]::add(pkginfo %s, %s)",
61 this, pkg_name(pkg, pnaw_always), wantstrings[nw]);
62 add(pkg); if (!pkg->clientdata) return;
63 pkg->clientdata->direct= nw;
65 np= would_like_to_install(nw,pkg) ? sp_selecting : sp_deselecting;
66 if (pkg->clientdata->spriority > np) return;
67 debug(dbg_general, "packagelist[%p]::add(pkginfo %s, %s) setting",
68 this, pkg_name(pkg, pnaw_always), wantstrings[nw]);
69 pkg->clientdata->suggested= pkg->clientdata->selected= nw;
70 pkg->clientdata->spriority= np;
73 void packagelist::add(pkginfo *pkg, const char *extrainfo, showpriority showimp) {
74 debug(dbg_general, "packagelist[%p]::add(pkginfo %s, ..., showpriority %d)",
75 this, pkg_name(pkg, pnaw_always), showimp);
76 add(pkg); if (!pkg->clientdata) return;
77 if (pkg->clientdata->dpriority < showimp) pkg->clientdata->dpriority= showimp;
78 pkg->clientdata->relations(extrainfo);
82 packagelist::alreadydone(doneent **done, void *check)
84 doneent *search = *done;
86 while (search && search->dep != check)
87 search = search->next;
90 debug(dbg_general, "packagelist[%p]::alreadydone(%p, %p) new",
99 void packagelist::addunavailable(deppossi *possi) {
100 debug(dbg_general, "packagelist[%p]::addunavail(%p)", this, possi);
102 if (!recursive) return;
103 if (alreadydone(&unavdone,possi)) return;
105 assert(possi->up->up->clientdata);
106 assert(possi->up->up->clientdata->uprec);
108 varbuf& vb= possi->up->up->clientdata->relations;
110 vb(_(" does not appear to be available\n"));
114 packagelist::add(dependency *depends, showpriority displayimportance)
116 debug(dbg_general, "packagelist[%p]::add(dependency[%p])", this, depends);
118 if (alreadydone(&depsdone, depends))
121 const char *comma= "";
123 depinfo(depends->up->set->name);
125 depinfo(gettext(relatestrings[depends->type]));
128 for (possi=depends->list;
130 possi=possi->next, comma=(possi && possi->next ? ", " : _(" or "))) {
132 depinfo(possi->ed->name);
133 if (possi->verrel != DPKG_RELATION_NONE) {
134 switch (possi->verrel) {
135 case DPKG_RELATION_LE:
138 case DPKG_RELATION_GE:
141 case DPKG_RELATION_LT:
144 case DPKG_RELATION_GT:
147 case DPKG_RELATION_EQ:
151 internerr("unknown dpkg_relation %d", possi->verrel);
153 depinfo(versiondescribe(&possi->version, vdew_nonambig));
158 add(depends->up, depinfo.string(), displayimportance);
159 for (possi=depends->list; possi; possi=possi->next) {
160 add(&possi->ed->pkg, depinfo.string(), displayimportance);
161 if (depends->type != dep_provides) {
162 /* Providers are not relevant if we are looking at a provider
163 * relationship already. */
165 for (provider = possi->ed->depended.available;
167 provider = provider->rev_next) {
168 if (provider->up->type != dep_provides) continue;
169 add(provider->up->up, depinfo.string(), displayimportance);
170 add(provider->up,displayimportance);
177 void repeatedlydisplay(packagelist *sub,
178 showpriority initial,
179 packagelist *unredisplay) {
183 debug(dbg_general, "repeatedlydisplay(packagelist[%p])", sub);
184 if (sub->resolvesuggest() != 0 && sub->deletelessimp_anyleft(initial)) {
185 debug(dbg_general, "repeatedlydisplay(packagelist[%p]) once", sub);
186 if (unredisplay) unredisplay->enddisplay();
188 /* Reset manual_install flag now that resolvesuggest() has seen it. */
189 manual_install = false;
190 newl= sub->display();
192 debug(dbg_general, "repeatedlydisplay(packagelist[%p]) newl", sub);
193 kb= sub->bindings; delete sub;
194 sub= new packagelist(kb,newl);
195 if (sub->resolvesuggest() <= 1) break;
196 if (!sub->deletelessimp_anyleft(dp_must)) break;
197 debug(dbg_general, "repeatedlydisplay(packagelist[%p]) again", sub);
199 if (unredisplay) unredisplay->startdisplay();
201 debug(dbg_general, "repeatedlydisplay(packagelist[%p]) done", sub);
205 int packagelist::deletelessimp_anyleft(showpriority than) {
206 debug(dbg_general, "packagelist[%p]::dli_al(%d): nitems=%d",
209 for (runthr=0, insat=0;
212 if (table[runthr]->dpriority < than) {
213 table[runthr]->free(recursive);
215 if (insat != runthr) table[insat]= table[runthr];
220 debug(dbg_general, "packagelist[%p]::dli_al(%d) done; nitems=%d",