po: Update German man pages translation
[dpkg.git] / dselect / pkgsublist.cc
blobccfc7f556fb278d9bbe4e3840b32db52d6ef9b0e
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 varbuf& vb= possi->up->up->clientdata->relations;
112 vb(possi->ed->name);
113 vb(_(" does not appear to be available\n"));
116 bool
117 packagelist::add(dependency *depends, showpriority displayimportance)
119 debug(dbg_general, "packagelist[%p]::add(dependency[%p])", this, depends);
121 if (alreadydone(&depsdone, depends))
122 return false;
124 const char *comma= "";
125 varbuf depinfo;
126 depinfo(depends->up->set->name);
127 depinfo(' ');
128 depinfo(gettext(relatestrings[depends->type]));
129 depinfo(' ');
130 deppossi *possi;
131 for (possi=depends->list;
132 possi;
133 possi=possi->next, comma=(possi && possi->next ? ", " : _(" or "))) {
134 depinfo(comma);
135 depinfo(possi->ed->name);
136 if (possi->verrel != DPKG_RELATION_NONE) {
137 switch (possi->verrel) {
138 case DPKG_RELATION_LE:
139 depinfo(" (<= ");
140 break;
141 case DPKG_RELATION_GE:
142 depinfo(" (>= ");
143 break;
144 case DPKG_RELATION_LT:
145 depinfo(" (<< ");
146 break;
147 case DPKG_RELATION_GT:
148 depinfo(" (>> ");
149 break;
150 case DPKG_RELATION_EQ:
151 depinfo(" (= ");
152 break;
153 default:
154 internerr("unknown dpkg_relation %d", possi->verrel);
156 depinfo(versiondescribe(&possi->version, vdew_nonambig));
157 depinfo(")");
160 depinfo('\n');
161 add(depends->up, depinfo.string(), displayimportance);
162 for (possi=depends->list; possi; possi=possi->next) {
163 add(&possi->ed->pkg, depinfo.string(), displayimportance);
164 if (depends->type != dep_provides) {
165 /* Providers are not relevant if we are looking at a provider
166 * relationship already. */
167 deppossi *provider;
168 for (provider = possi->ed->depended.available;
169 provider;
170 provider = provider->rev_next) {
171 if (provider->up->type != dep_provides) continue;
172 add(provider->up->up, depinfo.string(), displayimportance);
173 add(provider->up,displayimportance);
177 return true;
180 void repeatedlydisplay(packagelist *sub,
181 showpriority initial,
182 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();
187 for (;;) {
188 pkginfo **newl;
189 keybindings *kb;
191 /* Reset manual_install flag now that resolvesuggest() has seen it. */
192 manual_install = false;
193 newl= sub->display();
194 if (!newl) break;
195 debug(dbg_general, "repeatedlydisplay(packagelist[%p]) newl", sub);
196 kb= sub->bindings; delete sub;
197 sub= new packagelist(kb,newl);
198 if (sub->resolvesuggest() <= 1) break;
199 if (!sub->deletelessimp_anyleft(dp_must)) break;
200 debug(dbg_general, "repeatedlydisplay(packagelist[%p]) again", sub);
202 if (unredisplay) unredisplay->startdisplay();
204 debug(dbg_general, "repeatedlydisplay(packagelist[%p]) done", sub);
205 delete sub;
208 int packagelist::deletelessimp_anyleft(showpriority than) {
209 debug(dbg_general, "packagelist[%p]::dli_al(%d): nitems=%d",
210 this, than, nitems);
211 int insat, runthr;
212 for (runthr=0, insat=0;
213 runthr < nitems;
214 runthr++) {
215 if (table[runthr]->dpriority < than) {
216 table[runthr]->free(recursive);
217 } else {
218 if (insat != runthr) table[insat]= table[runthr];
219 insat++;
222 nitems= insat;
223 debug(dbg_general, "packagelist[%p]::dli_al(%d) done; nitems=%d",
224 this, than, nitems);
225 return nitems;