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/>.
28 #include <dpkg/i18n.h>
29 #include <dpkg/dpkg.h>
30 #include <dpkg/dpkg-db.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
42 debug(dbg_general
, "packagelist[%p]::add(pkginfo %s) adding",
43 this, pkg_name(pkg
, pnaw_always
));
44 perpackagestate
*state
= &datatable
[nitems
];
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
;
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
;
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
);
81 packagelist::alreadydone(doneent
**done
, void *check
)
83 doneent
*search
= *done
;
85 while (search
&& search
->dep
!= check
)
86 search
= search
->next
;
89 debug(dbg_general
, "packagelist[%p]::alreadydone(%p, %p) new",
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
;
113 vb(_(" does not appear to be available\n"));
117 packagelist::add(dependency
*depends
, showpriority displayimportance
)
119 debug(dbg_general
, "packagelist[%p]::add(dependency[%p])", this, depends
);
121 if (alreadydone(&depsdone
, depends
))
124 const char *comma
= "";
126 depinfo(depends
->up
->set
->name
);
128 depinfo(gettext(relatestrings
[depends
->type
]));
131 for (possi
=depends
->list
;
133 possi
=possi
->next
, comma
=(possi
&& possi
->next
? ", " : _(" or "))) {
135 depinfo(possi
->ed
->name
);
136 if (possi
->verrel
!= DPKG_RELATION_NONE
) {
137 switch (possi
->verrel
) {
138 case DPKG_RELATION_LE
:
141 case DPKG_RELATION_GE
:
144 case DPKG_RELATION_LT
:
147 case DPKG_RELATION_GT
:
150 case DPKG_RELATION_EQ
:
154 internerr("unknown dpkg_relation %d", possi
->verrel
);
156 depinfo(versiondescribe(&possi
->version
, vdew_nonambig
));
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. */
168 for (provider
= possi
->ed
->depended
.available
;
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
);
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();
191 /* Reset manual_install flag now that resolvesuggest() has seen it. */
192 manual_install
= false;
193 newl
= sub
->display();
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
);
208 int packagelist::deletelessimp_anyleft(showpriority than
) {
209 debug(dbg_general
, "packagelist[%p]::dli_al(%d): nitems=%d",
212 for (runthr
=0, insat
=0;
215 if (table
[runthr
]->dpriority
< than
) {
216 table
[runthr
]->free(recursive
);
218 if (insat
!= runthr
) table
[insat
]= table
[runthr
];
223 debug(dbg_general
, "packagelist[%p]::dli_al(%d) done; nitems=%d",