pkgsublist.cc 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. /*
  2. * dselect - Debian package maintenance user interface
  3. * pkgsublist.cc - status modification and recursive package list handling
  4. *
  5. * Copyright © 1995 Ian Jackson <ian@chiark.greenend.org.uk>
  6. *
  7. * This is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2,
  10. * or (at your option) any later version.
  11. *
  12. * This is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public
  18. * License along with this; if not, write to the Free Software
  19. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. */
  21. #include <config.h>
  22. #include <stdio.h>
  23. #include <string.h>
  24. #include <assert.h>
  25. #include <dpkg.h>
  26. #include <dpkg-db.h>
  27. #include "dselect.h"
  28. #include "bindings.h"
  29. void packagelist::add(pkginfo *pkg) {
  30. if (debug) fprintf(debug,"packagelist[%p]::add(pkginfo %s)\n",this,pkg->name);
  31. if (!recursive || // never add things to top level
  32. !pkg->clientdata || // don't add pure virtual packages
  33. pkg->clientdata->uprec) // don't add ones already in the recursive list
  34. return;
  35. if (debug) fprintf(debug,"packagelist[%p]::add(pkginfo %s) adding\n",this,pkg->name);
  36. perpackagestate *state= &datatable[nitems];
  37. state->pkg= pkg;
  38. state->direct= state->original= pkg->clientdata->selected;
  39. state->suggested= state->selected= pkg->clientdata->selected;
  40. state->spriority= sp_inherit; state->dpriority= dp_none;
  41. state->uprec= pkg->clientdata;
  42. state->relations.init();
  43. pkg->clientdata= state;
  44. table[nitems]= state;
  45. nitems++;
  46. }
  47. void packagelist::add(pkginfo *pkg, pkginfo::pkgwant nw) {
  48. if (debug) fprintf(debug,"packagelist[%p]::add(pkginfo %s, %s)\n",
  49. this, pkg->name, wantstrings[nw]);
  50. add(pkg); if (!pkg->clientdata) return;
  51. pkg->clientdata->direct= nw;
  52. selpriority np;
  53. np= would_like_to_install(nw,pkg) ? sp_selecting : sp_deselecting;
  54. if (pkg->clientdata->spriority > np) return;
  55. if (debug) fprintf(debug,"packagelist[%p]::add(pkginfo %s, %s) setting\n",
  56. this, pkg->name, wantstrings[nw]);
  57. pkg->clientdata->suggested= pkg->clientdata->selected= nw;
  58. pkg->clientdata->spriority= np;
  59. }
  60. void packagelist::add(pkginfo *pkg, const char *extrainfo, showpriority showimp) {
  61. if (debug)
  62. fprintf(debug,"packagelist[%p]::add(pkginfo %s, \"...\", showpriority %d)\n",
  63. this,pkg->name,showimp);
  64. add(pkg); if (!pkg->clientdata) return;
  65. if (pkg->clientdata->dpriority < showimp) pkg->clientdata->dpriority= showimp;
  66. pkg->clientdata->relations(extrainfo);
  67. pkg->clientdata->relations.terminate();
  68. }
  69. int packagelist::alreadydone(doneent **done, void *check) {
  70. doneent *search = *done;
  71. while (search && search->dep != check)
  72. search = search->next;
  73. if (search) return 1;
  74. if (debug) fprintf(debug,"packagelist[%p]::alreadydone(%p,%p) new\n",
  75. this,done,check);
  76. search= new doneent;
  77. search->next= *done;
  78. search->dep= check;
  79. *done= search;
  80. return 0;
  81. }
  82. void packagelist::addunavailable(deppossi *possi) {
  83. if (debug) fprintf(debug,"packagelist[%p]::addunavail(%p)\n",this,possi);
  84. if (!recursive) return;
  85. if (alreadydone(&unavdone,possi)) return;
  86. assert(possi->up->up->clientdata);
  87. assert(possi->up->up->clientdata->uprec);
  88. varbuf& vb= possi->up->up->clientdata->relations;
  89. vb(possi->ed->name);
  90. vb(_(" does not appear to be available\n"));
  91. }
  92. int packagelist::add(dependency *depends, showpriority displayimportance) {
  93. if (debug) fprintf(debug,"packagelist[%p]::add(dependency[%p])\n",this,depends);
  94. if (alreadydone(&depsdone,depends)) return 0;
  95. const char *comma= "";
  96. varbuf info;
  97. info(depends->up->name);
  98. info(' ');
  99. info(gettext(relatestrings[depends->type]));
  100. info(' ');
  101. deppossi *possi;
  102. for (possi=depends->list;
  103. possi;
  104. possi=possi->next, comma=(possi && possi->next ? ", " : _(" or "))) {
  105. info(comma);
  106. info(possi->ed->name);
  107. if (possi->verrel != dvr_none) {
  108. switch (possi->verrel) {
  109. case dvr_earlierequal: info(" (<= "); break;
  110. case dvr_laterequal: info(" (>= "); break;
  111. case dvr_earlierstrict: info(" (<< "); break;
  112. case dvr_laterstrict: info(" (>> "); break;
  113. case dvr_exact: info(" (= "); break;
  114. default: internerr("unknown verrel");
  115. }
  116. info(versiondescribe(&possi->version, vdew_nonambig));
  117. info(")");
  118. }
  119. }
  120. info('\n');
  121. add(depends->up,info.string(),displayimportance);
  122. for (possi=depends->list; possi; possi=possi->next) {
  123. add(possi->ed,info.string(),displayimportance);
  124. if (possi->verrel == dvr_none && depends->type != dep_provides) {
  125. // providers aren't relevant if a version was specified, or
  126. // if we're looking at a provider relationship already
  127. deppossi *provider;
  128. for (provider= possi->ed->available.valid ? possi->ed->available.depended : 0;
  129. provider;
  130. provider=provider->nextrev) {
  131. if (provider->up->type != dep_provides) continue;
  132. add(provider->up->up,info.string(),displayimportance);
  133. add(provider->up,displayimportance);
  134. }
  135. }
  136. }
  137. return 1;
  138. }
  139. void repeatedlydisplay(packagelist *sub,
  140. showpriority initial,
  141. packagelist *unredisplay) {
  142. pkginfo **newl;
  143. keybindings *kb;
  144. if (debug) fprintf(debug,"repeatedlydisplay(packagelist[%p])\n",sub);
  145. if (sub->resolvesuggest() != 0 && sub->deletelessimp_anyleft(initial)) {
  146. if (debug) fprintf(debug,"repeatedlydisplay(packagelist[%p]) once\n",sub);
  147. if (unredisplay) unredisplay->enddisplay();
  148. for (;;) {
  149. manual_install = 0; /* Remove flag now that resolvesuggest has seen it. */
  150. newl= sub->display();
  151. if (!newl) break;
  152. if (debug) fprintf(debug,"repeatedlydisplay(packagelist[%p]) newl\n",sub);
  153. kb= sub->bindings; delete sub;
  154. sub= new packagelist(kb,newl);
  155. if (sub->resolvesuggest() <= 1) break;
  156. if (!sub->deletelessimp_anyleft(dp_must)) break;
  157. if (debug) fprintf(debug,"repeatedlydisplay(packagelist[%p]) again\n",sub);
  158. }
  159. if (unredisplay) unredisplay->startdisplay();
  160. }
  161. delete sub;
  162. if (debug) fprintf(debug,"repeatedlydisplay(packagelist[%p]) done\n",sub);
  163. }
  164. int packagelist::deletelessimp_anyleft(showpriority than) {
  165. if (debug)
  166. fprintf(debug,"packagelist[%p]::dli_al(%d): nitems=%d\n",this,than,nitems);
  167. int insat, runthr;
  168. for (runthr=0, insat=0;
  169. runthr < nitems;
  170. runthr++) {
  171. if (table[runthr]->dpriority < than) {
  172. table[runthr]->free(recursive);
  173. } else {
  174. if (insat != runthr) table[insat]= table[runthr];
  175. insat++;
  176. }
  177. }
  178. nitems= insat;
  179. if (debug) fprintf(debug,"packagelist[%p]::dli_al(%d) done; nitems=%d\n",
  180. this,than,nitems);
  181. return nitems;
  182. }