pkglist.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. /*
  2. * dselect - Debian package maintenance user interface
  3. * pkglist.h - external definitions for package list handling
  4. *
  5. * Copyright © 1994,1995 Ian Jackson <ian@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. int status_width, section_width, priority_width;
  83. int package_width, versioninstalled_width, versionavailable_width, description_width;
  84. int section_column, priority_column, versioninstalled_column;
  85. int versionavailable_column, package_column, description_column;
  86. // Only used when ‘verbose’ is set
  87. int status_hold_width, status_status_width, status_want_width;
  88. // Table of packages
  89. struct perpackagestate *datatable;
  90. struct perpackagestate **table;
  91. // Misc.
  92. int nallocated;
  93. bool recursive, verbose;
  94. enum { so_unsorted, so_section, so_priority, so_alpha } sortorder;
  95. enum { sso_unsorted, sso_avail, sso_state } statsortorder;
  96. enum { vdo_none, vdo_available, vdo_both } versiondisplayopt;
  97. bool calcssadone, calcsssdone;
  98. struct perpackagestate *headings;
  99. // Package searching flags
  100. bool searchdescr;
  101. regex_t searchfsm;
  102. // Information displays
  103. struct infotype {
  104. bool (packagelist::*relevant)(); // null means always relevant
  105. void (packagelist::*display)(); // null means end of table
  106. };
  107. const infotype *currentinfo;
  108. static const infotype infoinfos[];
  109. static const infotype *const baseinfo;
  110. bool itr_recursive();
  111. bool itr_nonrecursive();
  112. void severalinfoblurb();
  113. void itd_mainwelcome();
  114. void itd_explaindisplay();
  115. void itd_recurwelcome();
  116. void itd_relations();
  117. void itd_description();
  118. void itd_statuscontrol();
  119. void itd_availablecontrol();
  120. // Dependency and sublist processing
  121. struct doneent { doneent *next; void *dep; } *depsdone, *unavdone;
  122. bool alreadydone(doneent **, void *);
  123. int resolvedepcon(dependency*);
  124. int checkdependers(pkginfo*, int changemade); // returns new changemade
  125. int deselect_one_of(pkginfo *er, pkginfo *ed, dependency *dep);
  126. // Define these virtuals
  127. bool checksearch(char *str);
  128. bool matchsearch(int index);
  129. void redraw1itemsel(int index, int selected);
  130. void redrawcolheads();
  131. void redrawthisstate();
  132. void redrawinfo();
  133. void redrawtitle();
  134. void setwidths();
  135. const char *itemname(int index);
  136. const struct helpmenuentry *helpmenulist();
  137. // Miscellaneous internal routines
  138. void redraw1package(int index, int selected);
  139. int compareentries(const struct perpackagestate *a, const struct perpackagestate *b);
  140. friend int qsort_compareentries(const void *a, const void *b);
  141. pkgwant reallywant(pkgwant, struct perpackagestate *);
  142. int describemany(char buf[], const char *prioritystring, const char *section,
  143. const struct perpackagestate *pps);
  144. bool deppossatisfied(deppossi *possi, perpackagestate **fixbyupgrade);
  145. void sortmakeheads();
  146. void resortredisplay();
  147. void movecursorafter(int ncursor);
  148. void initialsetup();
  149. void finalsetup();
  150. void ensurestatsortinfo();
  151. // To do with building the list, with heading lines in it
  152. void discardheadings();
  153. void addheading(enum ssavailval, enum ssstateval,
  154. pkgpriority, const char *, const char *section);
  155. void sortinplace();
  156. bool affectedmatches(struct pkginfo *pkg, struct pkginfo *comparewith);
  157. void affectedrange(int *startp, int *endp);
  158. void setwant(pkgwant nw);
  159. void sethold(int hold);
  160. public:
  161. // Keybinding functions */
  162. void kd_quit_noop();
  163. void kd_revert_abort();
  164. void kd_revertsuggest();
  165. void kd_revertdirect();
  166. void kd_revertinstalled();
  167. void kd_morespecific();
  168. void kd_lessspecific();
  169. void kd_swaporder();
  170. void kd_swapstatorder();
  171. void kd_select();
  172. void kd_deselect();
  173. void kd_purge();
  174. void kd_hold();
  175. void kd_unhold();
  176. void kd_info();
  177. void kd_toggleinfo();
  178. void kd_verbose();
  179. void kd_versiondisplay();
  180. packagelist(keybindings *kb); // nonrecursive
  181. packagelist(keybindings *kb, pkginfo **pkgltab); // recursive
  182. void add(pkginfo **arry) { while (*arry) add(*arry++); }
  183. void add(pkginfo*);
  184. void add(pkginfo *, pkgwant);
  185. void add(pkginfo*, const char *extrainfo, showpriority displayimportance);
  186. bool add(dependency *, showpriority displayimportance);
  187. void addunavailable(deppossi*);
  188. bool useavailable(pkginfo *);
  189. pkgbin *find_pkgbin(pkginfo *);
  190. int resolvesuggest();
  191. int deletelessimp_anyleft(showpriority than);
  192. pkginfo **display();
  193. ~packagelist();
  194. };
  195. void repeatedlydisplay(packagelist *sub, showpriority,
  196. packagelist *unredisplay = nullptr);
  197. int would_like_to_install(pkgwant, pkginfo *pkg);
  198. extern const char *const wantstrings[];
  199. extern const char *const eflagstrings[];
  200. extern const char *const statusstrings[];
  201. extern const char *const prioritystrings[];
  202. extern const char *const priorityabbrevs[];
  203. extern const char *const relatestrings[];
  204. extern const char *const ssastrings[], *const ssaabbrevs[];
  205. extern const char *const sssstrings[], *const sssabbrevs[];
  206. extern const char statuschars[];
  207. extern const char eflagchars[];
  208. extern const char wantchars[];
  209. #endif /* PKGLIST_H */