pkglist.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. /*
  2. * dselect - Debian package maintenance user interface
  3. * pkglist.h - external definitions for package list handling
  4. *
  5. * Copyright © 1994,1995 Ian Jackson <ijackson@chiark.greenend.org.uk>
  6. * Copyright © 2001 Wichert Akkerman <wakkerma@debian.org>
  7. * Copyright © 2007-2014 Guillem Jover <guillem@debian.org>
  8. *
  9. * This is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  21. */
  22. #ifndef PKGLIST_H
  23. #define PKGLIST_H
  24. #include <regex.h>
  25. enum showpriority {
  26. dp_none, // has not been involved in any unsatisfied things
  27. dp_may, // has been involved in an unsatisfied Suggests
  28. dp_should, // has been involved in an unsatisfied Recommends
  29. dp_must // has been involved in an unsatisfied Depends/Conflicts
  30. };
  31. enum selpriority {
  32. // where did the currently suggested value come from, and how important
  33. // is it to display this package ?
  34. // low
  35. sp_inherit, // inherited from our parent list
  36. sp_selecting, // propagating a selection
  37. sp_deselecting, // propagating a deselection
  38. sp_fixed // it came from the ‘status’ file and we're not a recursive list
  39. // high
  40. };
  41. enum ssavailval { // Availability sorting order, first to last:
  42. ssa_broken, // Brokenly-installed and nothing available
  43. ssa_notinst_unseen, // Entirely new packages (available but not deselected yet)
  44. ssa_installed_newer, // Installed, newer version available
  45. ssa_installed_gone, // Installed but no longer available
  46. ssa_installed_sameold, // Same or older version available as installed
  47. ssa_notinst_seen, // Available but not installed
  48. ssa_notinst_gone, // Not available, and only config files left
  49. ssa_none=-1
  50. };
  51. enum ssstateval { // State sorting order, first to last:
  52. sss_broken, // In some way brokenly installed
  53. sss_installed, // Installed
  54. sss_configfiles, // Config files only
  55. sss_notinstalled, // Not installed
  56. sss_none=-1
  57. };
  58. struct perpackagestate {
  59. struct pkginfo *pkg;
  60. /* The ‘heading’ entries in the list, for “all packages of type foo”,
  61. * point to a made-up pkginfo, which has pkg->name==0.
  62. * pkg->priority and pkg->section are set to the values if appropriate, or to
  63. * PKG_PRIO_UNSET resp. null if the heading refers to all priorities resp.
  64. * sections.
  65. * uprec is used when constructing the list initially and when tearing it
  66. * down and should not otherwise be used; other fields are undefined.
  67. */
  68. pkgwant original; // set by caller
  69. pkgwant direct; // set by caller
  70. pkgwant suggested; // set by caller, modified by resolvesuggest
  71. pkgwant selected; // not set by caller, will be set by packagelist
  72. selpriority spriority; // monotonically increases (used by sublists)
  73. showpriority dpriority; // monotonically increases (used by sublists)
  74. struct perpackagestate *uprec; // 0 if this is not part of a recursive list
  75. ssavailval ssavail;
  76. ssstateval ssstate;
  77. varbuf relations;
  78. void free(bool recursive);
  79. };
  80. class packagelist : public baselist {
  81. protected:
  82. column col_status;
  83. column col_section;
  84. column col_priority;
  85. column col_package;
  86. column col_archinstalled;
  87. column col_archavailable;
  88. column col_versioninstalled;
  89. column col_versionavailable;
  90. column col_description;
  91. // Only used when ‘verbose’ is set
  92. column col_status_hold;
  93. column col_status_status;
  94. column col_status_old_want;
  95. column col_status_new_want;
  96. // Table of packages
  97. struct perpackagestate *datatable;
  98. struct perpackagestate **table;
  99. // Misc.
  100. int nallocated;
  101. bool recursive, verbose;
  102. enum { so_unsorted, so_section, so_priority, so_alpha } sortorder;
  103. enum { sso_unsorted, sso_avail, sso_state } statsortorder;
  104. enum { ado_none, ado_available, ado_both } archdisplayopt;
  105. enum { vdo_none, vdo_available, vdo_both } versiondisplayopt;
  106. bool calcssadone, calcsssdone;
  107. struct perpackagestate *headings;
  108. // Package searching flags
  109. bool searchdescr;
  110. regex_t searchfsm;
  111. // Information displays
  112. struct infotype {
  113. bool (packagelist::*relevant)(); // null means always relevant
  114. void (packagelist::*display)(); // null means end of table
  115. };
  116. const infotype *currentinfo;
  117. static const infotype infoinfos[];
  118. static const infotype *const baseinfo;
  119. bool itr_recursive();
  120. bool itr_nonrecursive();
  121. void severalinfoblurb();
  122. void itd_mainwelcome();
  123. void itd_explaindisplay();
  124. void itd_recurwelcome();
  125. void itd_relations();
  126. void itd_description();
  127. void itd_statuscontrol();
  128. void itd_availablecontrol();
  129. // Dependency and sublist processing
  130. struct doneent { doneent *next; void *dep; } *depsdone, *unavdone;
  131. bool alreadydone(doneent **, void *);
  132. int resolvedepcon(dependency*);
  133. int checkdependers(pkginfo*, int changemade); // returns new changemade
  134. int deselect_one_of(pkginfo *er, pkginfo *ed, dependency *dep);
  135. // Define these virtuals
  136. bool checksearch(char *str);
  137. bool matchsearch(int index);
  138. void redraw1itemsel(int index, int selected);
  139. void redrawcolheads();
  140. void redrawthisstate();
  141. void redrawinfo();
  142. void redrawtitle();
  143. void setwidths();
  144. const char *itemname(int index);
  145. const struct helpmenuentry *helpmenulist();
  146. // Miscellaneous internal routines
  147. void redraw1package(int index, int selected);
  148. int compareentries(const struct perpackagestate *a, const struct perpackagestate *b);
  149. friend int qsort_compareentries(const void *a, const void *b);
  150. pkgwant reallywant(pkgwant, struct perpackagestate *);
  151. int describemany(char buf[], const char *prioritystring, const char *section,
  152. const struct perpackagestate *pps);
  153. bool deppossatisfied(deppossi *possi, perpackagestate **fixbyupgrade);
  154. void sortmakeheads();
  155. void resortredisplay();
  156. void movecursorafter(int ncursor);
  157. void initialsetup();
  158. void finalsetup();
  159. void ensurestatsortinfo();
  160. // To do with building the list, with heading lines in it
  161. void discardheadings();
  162. void addheading(enum ssavailval, enum ssstateval,
  163. pkgpriority, const char *, const char *section);
  164. void sortinplace();
  165. bool affectedmatches(struct pkginfo *pkg, struct pkginfo *comparewith);
  166. void affectedrange(int *startp, int *endp);
  167. void setwant(pkgwant nw);
  168. void sethold(int hold);
  169. public:
  170. // Keybinding functions */
  171. void kd_quit_noop();
  172. void kd_revert_abort();
  173. void kd_revertsuggest();
  174. void kd_revertdirect();
  175. void kd_revertinstalled();
  176. void kd_morespecific();
  177. void kd_lessspecific();
  178. void kd_swaporder();
  179. void kd_swapstatorder();
  180. void kd_select();
  181. void kd_deselect();
  182. void kd_purge();
  183. void kd_hold();
  184. void kd_unhold();
  185. void kd_info();
  186. void kd_toggleinfo();
  187. void kd_verbose();
  188. void kd_archdisplay();
  189. void kd_versiondisplay();
  190. packagelist(keybindings *kb); // nonrecursive
  191. packagelist(keybindings *kb, pkginfo **pkgltab); // recursive
  192. void add(pkginfo **arry) { while (*arry) add(*arry++); }
  193. void add(pkginfo*);
  194. void add(pkginfo *, pkgwant);
  195. void add(pkginfo*, const char *extrainfo, showpriority displayimportance);
  196. bool add(dependency *, showpriority displayimportance);
  197. void addunavailable(deppossi*);
  198. bool useavailable(pkginfo *);
  199. pkgbin *find_pkgbin(pkginfo *);
  200. int resolvesuggest();
  201. int deletelessimp_anyleft(showpriority than);
  202. pkginfo **display();
  203. ~packagelist();
  204. };
  205. void repeatedlydisplay(packagelist *sub, showpriority,
  206. packagelist *unredisplay = nullptr);
  207. int would_like_to_install(pkgwant, pkginfo *pkg);
  208. extern const char *const wantstrings[];
  209. extern const char *const eflagstrings[];
  210. extern const char *const statusstrings[];
  211. extern const char *const prioritystrings[];
  212. extern const char *const priorityabbrevs[];
  213. extern const char *const relatestrings[];
  214. extern const char *const ssastrings[], *const ssaabbrevs[];
  215. extern const char *const sssstrings[], *const sssabbrevs[];
  216. extern const char statuschars[];
  217. extern const char eflagchars[];
  218. extern const char wantchars[];
  219. #endif /* PKGLIST_H */