Release 1.15.8
[dpkg.git] / dselect / pkglist.h
blobf2b7b6c703d051a2f38d3323d295b9f6647debba
1 /* -*- c++ -*-
2 * dselect - selection of Debian packages
3 * pkglist.h - external definitions for package list handling
5 * Copyright © 1994,1995 Ian Jackson <ian@chiark.greenend.org.uk>
6 * Copyright © 2001 Wichert Akkerman <wakkerma@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 <http://www.gnu.org/licenses/>.
22 #ifndef PKGLIST_H
23 #define PKGLIST_H
25 #include <regex.h>
27 enum showpriority {
28 dp_none, // has not been involved in any unsatisfied things
29 dp_may, // has been involved in an unsatisfied Suggests
30 dp_should, // has been involved in an unsatisfied Recommends
31 dp_must // has been involved in an unsatisfied Depends/Conflicts
34 enum selpriority {
35 // where did the currently suggested value come from, and how important
36 // is it to display this package ?
37 // low
38 sp_inherit, // inherited from our parent list
39 sp_selecting, // propagating a selection
40 sp_deselecting, // propagating a deselection
41 sp_fixed // it came from the `status' file and we're not a recursive list
42 // high
45 enum ssavailval { // Availability sorting order, first to last:
46 ssa_broken, // Brokenly-installed and nothing available
47 ssa_notinst_unseen, // Entirely new packages (available but not deselected yet)
48 ssa_installed_newer, // Installed, newer version available
49 ssa_installed_gone, // Installed but no longer available
50 ssa_installed_sameold, // Same or older version available as installed
51 ssa_notinst_seen, // Available but not installed
52 ssa_notinst_gone, // Not available, and only config files left
53 ssa_none=-1
56 enum ssstateval { // State sorting order, first to last:
57 sss_broken, // In some way brokenly installed
58 sss_installed, // Installed
59 sss_configfiles, // Config files only
60 sss_notinstalled, // Not installed
61 sss_none=-1
64 struct perpackagestate {
65 struct pkginfo *pkg;
66 /* The `heading' entries in the list, for `all packages of type foo',
67 * point to a made-up pkginfo, which has pkg->name==0.
68 * pkg->priority and pkg->section are set to the values if appropriate, or to
69 * pri_unset resp. null if the heading refers to all priorities resp. sections.
70 * uprec is used when constructing the list initially and when tearing it
71 * down and should not otherwise be used; other fields are undefined.
73 pkginfo::pkgwant original; // set by caller
74 pkginfo::pkgwant direct; // set by caller
75 pkginfo::pkgwant suggested; // set by caller, modified by resolvesuggest
76 pkginfo::pkgwant selected; // not set by caller, will be set by packagelist
77 selpriority spriority; // monotonically increases (used by sublists)
78 showpriority dpriority; // monotonically increases (used by sublists)
79 struct perpackagestate *uprec; // 0 if this is not part of a recursive list
80 ssavailval ssavail;
81 ssstateval ssstate;
82 varbuf relations;
84 void free(int recursive);
87 class packagelist : public baselist {
88 protected:
89 int status_width, gap_width, section_width, priority_width;
90 int package_width, versioninstalled_width, versionavailable_width, description_width;
91 int section_column, priority_column, versioninstalled_column;
92 int versionavailable_column, package_column, description_column;
94 // Only used when `verbose' is set
95 int status_hold_width, status_status_width, status_want_width;
97 // Table of packages
98 struct perpackagestate *datatable;
99 struct perpackagestate **table;
101 // Misc.
102 int recursive, nallocated, verbose;
103 enum { so_unsorted, so_section, so_priority, so_alpha } sortorder;
104 enum { sso_unsorted, sso_avail, sso_state } statsortorder;
105 enum { vdo_none, vdo_available, vdo_both } versiondisplayopt;
106 int calcssadone, calcsssdone;
107 struct perpackagestate *headings;
109 // Package searching flags
110 int searchdescr;
111 regex_t searchfsm;
113 // Information displays
114 struct infotype {
115 int (packagelist::*relevant)(); // null means always relevant
116 void (packagelist::*display)(); // null means end of table
118 const infotype *currentinfo;
119 static const infotype infoinfos[];
120 static const infotype *const baseinfo;
121 int itr_recursive();
122 int itr_nonrecursive();
123 void severalinfoblurb();
124 void itd_mainwelcome();
125 void itd_explaindisplay();
126 void itd_recurwelcome();
127 void itd_relations();
128 void itd_description();
129 void itd_statuscontrol();
130 void itd_availablecontrol();
132 // Dependency and sublist processing
133 struct doneent { doneent *next; void *dep; } *depsdone, *unavdone;
134 bool alreadydone(doneent **, void *);
135 int resolvedepcon(dependency*);
136 int checkdependers(pkginfo*, int changemade); // returns new changemade
137 int deselect_one_of(pkginfo *er, pkginfo *ed, dependency *dep);
139 // Define these virtuals
140 bool checksearch(char *str);
141 bool matchsearch(int index);
142 void redraw1itemsel(int index, int selected);
143 void redrawcolheads();
144 void redrawthisstate();
145 void redrawinfo();
146 void redrawtitle();
147 void setwidths();
148 const char *itemname(int index);
149 const struct helpmenuentry *helpmenulist();
151 // Miscellaneous internal routines
153 void redraw1package(int index, int selected);
154 int compareentries(const struct perpackagestate *a, const struct perpackagestate *b);
155 friend int qsort_compareentries(const void *a, const void *b);
156 pkginfo::pkgwant reallywant(pkginfo::pkgwant, struct perpackagestate*);
157 int describemany(char buf[], const char *prioritystring, const char *section,
158 const struct perpackagestate *pps);
159 bool deppossatisfied(deppossi *possi, perpackagestate **fixbyupgrade);
161 void sortmakeheads();
162 void resortredisplay();
163 void movecursorafter(int ncursor);
164 void initialsetup();
165 void finalsetup();
166 void ensurestatsortinfo();
168 // To do with building the list, with heading lines in it
169 void discardheadings();
170 void addheading(enum ssavailval, enum ssstateval,
171 pkginfo::pkgpriority, const char*, const char *section);
172 void sortinplace();
173 bool affectedmatches(struct pkginfo *pkg, struct pkginfo *comparewith);
174 void affectedrange(int *startp, int *endp);
175 void setwant(pkginfo::pkgwant nw);
176 void sethold(int hold);
178 public:
180 // Keybinding functions */
181 void kd_quit_noop();
182 void kd_revert_abort();
183 void kd_revertsuggest();
184 void kd_revertdirect();
185 void kd_revertinstalled();
186 void kd_morespecific();
187 void kd_lessspecific();
188 void kd_swaporder();
189 void kd_swapstatorder();
190 void kd_select();
191 void kd_deselect();
192 void kd_purge();
193 void kd_hold();
194 void kd_unhold();
195 void kd_info();
196 void kd_toggleinfo();
197 void kd_verbose();
198 void kd_versiondisplay();
200 packagelist(keybindings *kb); // nonrecursive
201 packagelist(keybindings *kb, pkginfo **pkgltab); // recursive
202 void add(pkginfo **arry) { while (*arry) add(*arry++); }
203 void add(pkginfo*);
204 void add(pkginfo*, pkginfo::pkgwant);
205 void add(pkginfo*, const char *extrainfo, showpriority displayimportance);
206 bool add(dependency *, showpriority displayimportance);
207 void addunavailable(deppossi*);
208 bool useavailable(pkginfo *);
209 pkginfoperfile *findinfo(pkginfo*);
211 int resolvesuggest();
212 int deletelessimp_anyleft(showpriority than);
213 pkginfo **display();
214 ~packagelist();
217 void repeatedlydisplay(packagelist *sub, showpriority, packagelist *unredisplay =0);
218 int would_like_to_install(pkginfo::pkgwant, pkginfo *pkg);
220 extern const char *const wantstrings[];
221 extern const char *const eflagstrings[];
222 extern const char *const statusstrings[];
223 extern const char *const prioritystrings[];
224 extern const char *const priorityabbrevs[];
225 extern const char *const relatestrings[];
226 extern const char *const ssastrings[], *const ssaabbrevs[];
227 extern const char *const sssstrings[], *const sssabbrevs[];
228 extern const char statuschars[];
229 extern const char eflagchars[];
230 extern const char wantchars[];
232 const struct pkginfoperfile *i2info(struct pkginfo *pkg);
234 extern modstatdb_rw readwrite;
236 #endif /* PKGLIST_H */