man: Mention .buildinfo in dpkg-buildpackage --sign-command description
[dpkg.git] / dselect / pkgsublist.cc
blobc119b5c9993cecdb3d5e178a27c2ba565bf5ad8a
1 /*
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/>.
22 #include <config.h>
23 #include <compat.h>
25 #include <string.h>
26 #include <stdio.h>
28 #include <dpkg/i18n.h>
29 #include <dpkg/dpkg.h>
30 #include <dpkg/dpkg-db.h>
32 #include "dselect.h"
33 #include "bindings.h"
35 void packagelist::add(pkginfo *pkg) {
36 debug(dbg_general, "packagelist[%p]::add(pkginfo %s)",
37 this, pkg_name(pkg, pnaw_always));
38 if (!recursive || // never add things to top level
39 !pkg->clientdata || // don't add pure virtual packages
40 pkg->clientdata->uprec) // don't add ones already in the recursive list
41 return;
42 debug(dbg_general, "packagelist[%p]::add(pkginfo %s) adding",
43 this, pkg_name(pkg, pnaw_always));
44 perpackagestate *state= &datatable[nitems];
45 state->pkg= pkg;
46 state->direct= state->original= pkg->clientdata->selected;
47 state->suggested= state->selected= pkg->clientdata->selected;
48 state->spriority= sp_inherit; state->dpriority= dp_none;
49 state->uprec= pkg->clientdata;
50 state->relations.init();
51 pkg->clientdata= state;
52 table[nitems]= state;
53 nitems++;
56 void
57 packagelist::add(pkginfo *pkg, pkgwant nw)
59 debug(dbg_general, "packagelist[%p]::add(pkginfo %s, %s)",
60 this, pkg_name(pkg, pnaw_always), wantstrings[nw]);
61 add(pkg); if (!pkg->clientdata) return;
62 pkg->clientdata->direct= nw;
63 selpriority np;
64 np= would_like_to_install(nw,pkg) ? sp_selecting : sp_deselecting;
65 if (pkg->clientdata->spriority > np) return;
66 debug(dbg_general, "packagelist[%p]::add(pkginfo %s, %s) setting",
67 this, pkg_name(pkg, pnaw_always), wantstrings[nw]);
68 pkg->clientdata->suggested= pkg->clientdata->selected= nw;
69 pkg->clientdata->spriority= np;
72 void packagelist::add(pkginfo *pkg, const char *extrainfo, showpriority showimp) {
73 debug(dbg_general, "packagelist[%p]::add(pkginfo %s, ..., showpriority %d)",
74 this, pkg_name(pkg, pnaw_always), showimp);
75 add(pkg); if (!pkg->clientdata) return;
76 if (pkg->clientdata->dpriority < showimp) pkg->clientdata->dpriority= showimp;
77 pkg->clientdata->relations(extrainfo);
80 bool
81 packagelist::alreadydone(doneent **done, void *check)
83 doneent *search = *done;
85 while (search && search->dep != check)
86 search = search->next;
87 if (search)
88 return true;
89 debug(dbg_general, "packagelist[%p]::alreadydone(%p, %p) new",
90 this, done, check);
91 search= new doneent;
92 search->next= *done;
93 search->dep= check;
94 *done= search;
95 return false;
98 void packagelist::addunavailable(deppossi *possi) {
99 debug(dbg_general, "packagelist[%p]::addunavail(%p)", this, possi);
101 if (!recursive) return;
102 if (alreadydone(&unavdone,possi)) return;
104 if (possi->up->up->clientdata == nullptr)
105 internerr("deppossi from package %s has nullptr clientdata",
106 pkg_name(possi->up->up, pnaw_always));
107 if (possi->up->up->clientdata->uprec == nullptr)
108 internerr("deppossi from package %s has nullptr clientdata's uprec",
109 pkg_name(possi->up->up, pnaw_always));
111 // cppcheck-suppress[constVariable]: false positive, operator() modifies it.
112 varbuf& vb= possi->up->up->clientdata->relations;
113 vb(possi->ed->name);
114 vb(_(" does not appear to be available\n"));
117 bool
118 packagelist::add(dependency *depends, showpriority displayimportance)
120 debug(dbg_general, "packagelist[%p]::add(dependency[%p])", this, depends);
122 if (alreadydone(&depsdone, depends))
123 return false;
125 const char *comma= "";
126 varbuf depinfo;
127 depinfo(depends->up->set->name);
128 depinfo(' ');
129 depinfo(gettext(relatestrings[depends->type]));
130 depinfo(' ');
131 deppossi *possi;
132 for (possi=depends->list;
133 possi;
134 possi=possi->next, comma=(possi && possi->next ? ", " : _(" or "))) {
135 depinfo(comma);
136 depinfo(possi->ed->name);
137 if (possi->verrel != DPKG_RELATION_NONE) {
138 switch (possi->verrel) {
139 case DPKG_RELATION_LE:
140 depinfo(" (<= ");
141 break;
142 case DPKG_RELATION_GE:
143 depinfo(" (>= ");
144 break;
145 case DPKG_RELATION_LT:
146 depinfo(" (<< ");
147 break;
148 case DPKG_RELATION_GT:
149 depinfo(" (>> ");
150 break;
151 case DPKG_RELATION_EQ:
152 depinfo(" (= ");
153 break;
154 default:
155 internerr("unknown dpkg_relation %d", possi->verrel);
157 depinfo(versiondescribe(&possi->version, vdew_nonambig));
158 depinfo(")");
161 depinfo('\n');
162 add(depends->up, depinfo.string(), displayimportance);
163 for (possi=depends->list; possi; possi=possi->next) {
164 add(&possi->ed->pkg, depinfo.string(), displayimportance);
165 if (depends->type != dep_provides) {
166 /* Providers are not relevant if we are looking at a provider
167 * relationship already. */
168 deppossi *provider;
169 for (provider = possi->ed->depended.available;
170 provider;
171 provider = provider->rev_next) {
172 if (provider->up->type != dep_provides) continue;
173 add(provider->up->up, depinfo.string(), displayimportance);
174 add(provider->up,displayimportance);
178 return true;
181 void repeatedlydisplay(packagelist *sub,
182 showpriority initial,
183 packagelist *unredisplay) {
184 debug(dbg_general, "repeatedlydisplay(packagelist[%p])", sub);
185 if (sub->resolvesuggest() != 0 && sub->deletelessimp_anyleft(initial)) {
186 debug(dbg_general, "repeatedlydisplay(packagelist[%p]) once", sub);
187 if (unredisplay) unredisplay->enddisplay();
188 for (;;) {
189 pkginfo **newl;
190 keybindings *kb;
192 /* Reset manual_install flag now that resolvesuggest() has seen it. */
193 manual_install = false;
194 newl= sub->display();
195 if (!newl) break;
196 debug(dbg_general, "repeatedlydisplay(packagelist[%p]) newl", sub);
197 kb= sub->bindings; delete sub;
198 sub= new packagelist(kb,newl);
199 if (sub->resolvesuggest() <= 1) break;
200 if (!sub->deletelessimp_anyleft(dp_must)) break;
201 debug(dbg_general, "repeatedlydisplay(packagelist[%p]) again", sub);
203 if (unredisplay) unredisplay->startdisplay();
205 debug(dbg_general, "repeatedlydisplay(packagelist[%p]) done", sub);
206 delete sub;
209 int packagelist::deletelessimp_anyleft(showpriority than) {
210 debug(dbg_general, "packagelist[%p]::dli_al(%d): nitems=%d",
211 this, than, nitems);
212 int insat, runthr;
213 for (runthr=0, insat=0;
214 runthr < nitems;
215 runthr++) {
216 if (table[runthr]->dpriority < than) {
217 table[runthr]->free(recursive);
218 } else {
219 if (insat != runthr) table[insat]= table[runthr];
220 insat++;
223 nitems= insat;
224 debug(dbg_general, "packagelist[%p]::dli_al(%d) done; nitems=%d",
225 this, than, nitems);
226 return nitems;