diff options
author | Guillem Jover <guillem@debian.org> | 2014-06-02 00:32:45 +0200 |
---|---|---|
committer | Guillem Jover <guillem@debian.org> | 2014-06-02 00:32:45 +0200 |
commit | c7ad73d0a95ed527e1efe013b97cf849f3af55e9 (patch) | |
tree | 5488444f937653c8ce00cccf0dcff6903e0169dc /dselect | |
parent | dc2edadf0bcb624eafbcd16c92aae7691180f7a4 (diff) | |
download | dpkg-c7ad73d0a95ed527e1efe013b97cf849f3af55e9.tar.gz |
Move enum definitions out of structs
This untangles the types, and makes it possible to use functions that
use such enums as arguments from C++ code, as otherwise the enum would
need to be declared within the struct namespace.
Diffstat (limited to 'dselect')
-rw-r--r-- | dselect/pkgcmds.cc | 63 | ||||
-rw-r--r-- | dselect/pkgdepcon.cc | 35 | ||||
-rw-r--r-- | dselect/pkglist.cc | 65 | ||||
-rw-r--r-- | dselect/pkglist.h | 19 | ||||
-rw-r--r-- | dselect/pkgsublist.cc | 5 | ||||
-rw-r--r-- | dselect/pkgtop.cc | 11 |
6 files changed, 109 insertions, 89 deletions
diff --git a/dselect/pkgcmds.cc b/dselect/pkgcmds.cc index 681893e32..82e388f64 100644 --- a/dselect/pkgcmds.cc +++ b/dselect/pkgcmds.cc @@ -3,6 +3,7 @@ * pkgcmds.cc - package list keyboard commands * * Copyright © 1994,1995 Ian Jackson <ian@chiark.greenend.org.uk> + * Copyright © 2008-2014 Guillem Jover <guillem@debian.org> * * This is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -46,9 +47,9 @@ packagelist::affectedmatches(struct pkginfo *pkg, struct pkginfo *comparewith) { default: internerr("unknown statsortorder %d", statsortorder); } - if (comparewith->priority != pkginfo::pri_unset && + if (comparewith->priority != pri_unset && (comparewith->priority != pkg->priority || - (comparewith->priority == pkginfo::pri_other && + (comparewith->priority == pri_other && strcasecmp(comparewith->otherpriority, pkg->otherpriority)))) return false; if (comparewith->section && @@ -87,18 +88,24 @@ void packagelist::movecursorafter(int ncursor) { refreshlist(); redrawthisstate(); } -pkginfo::pkgwant packagelist::reallywant(pkginfo::pkgwant nwarg, - struct perpackagestate *pkgstate) { - if (nwarg != pkginfo::want_sentinel) return nwarg; - pkginfo::pkgstatus status= pkgstate->pkg->status; - if (status == pkginfo::stat_notinstalled) return pkginfo::want_purge; - if (status == pkginfo::stat_configfiles) return pkginfo::want_deinstall; - return pkginfo::want_install; +pkgwant +packagelist::reallywant(pkgwant nwarg, struct perpackagestate *pkgstate) +{ + if (nwarg != want_sentinel) + return nwarg; + pkgstatus status = pkgstate->pkg->status; + if (status == stat_notinstalled) + return want_purge; + if (status == stat_configfiles) + return want_deinstall; + return want_install; } -void packagelist::setwant(pkginfo::pkgwant nwarg) { +void +packagelist::setwant(pkgwant nwarg) +{ int index, top, bot; - pkginfo::pkgwant nw; + pkgwant nw; if (modstatdb_get_status() == msdbrw_readonly) { beep(); @@ -120,8 +127,8 @@ void packagelist::setwant(pkginfo::pkgwant nwarg) { continue; nw= reallywant(nwarg,table[index]); if (table[index]->selected == nw || - (table[index]->selected == pkginfo::want_purge && - nw == pkginfo::want_deinstall)) + (table[index]->selected == want_purge && + nw == want_deinstall)) continue; sub->add(table[index]->pkg,nw); } @@ -137,24 +144,30 @@ bool manual_install = false; void packagelist::kd_select() { manual_install = true; - setwant(pkginfo::want_install); + setwant(want_install); manual_install = false; } -void packagelist::kd_hold() { setwant(pkginfo::want_hold); } -void packagelist::kd_deselect() { setwant(pkginfo::want_deinstall); } -void packagelist::kd_unhold() { setwant(pkginfo::want_sentinel); } -void packagelist::kd_purge() { setwant(pkginfo::want_purge); } +void packagelist::kd_hold() { setwant(want_hold); } +void packagelist::kd_deselect() { setwant(want_deinstall); } +void packagelist::kd_unhold() { setwant(want_sentinel); } +void packagelist::kd_purge() { setwant(want_purge); } -int would_like_to_install(pkginfo::pkgwant wantvalue, pkginfo *pkg) { +int +would_like_to_install(pkgwant wantvalue, pkginfo *pkg) +{ /* Returns: 1 for yes, 0 for no, -1 for if they want to preserve an error condition. */ debug(dbg_general, "would_like_to_install(%d, %s) status %d", wantvalue, pkg_name(pkg, pnaw_always), pkg->status); - if (wantvalue == pkginfo::want_install) return 1; - if (wantvalue != pkginfo::want_hold) return 0; - if (pkg->status == pkginfo::stat_installed) return 1; - if (pkg->status == pkginfo::stat_notinstalled || - pkg->status == pkginfo::stat_configfiles) return 0; + if (wantvalue == want_install) + return 1; + if (wantvalue != want_hold) + return 0; + if (pkg->status == stat_installed) + return 1; + if (pkg->status == stat_notinstalled || + pkg->status == stat_configfiles) + return 0; return -1; } @@ -280,7 +293,7 @@ packagelist::kd_revertinstalled() for (i = 0; i < nitems; i++) { if (table[i]->pkg->set->name) - table[i]->selected = reallywant(pkginfo::want_sentinel, table[i]); + table[i]->selected = reallywant(want_sentinel, table[i]); ldrawnstart = ldrawnend = -1; } diff --git a/dselect/pkgdepcon.cc b/dselect/pkgdepcon.cc index d49cab828..f082d5ec4 100644 --- a/dselect/pkgdepcon.cc +++ b/dselect/pkgdepcon.cc @@ -3,6 +3,7 @@ * pkgdepcon.cc - dependency and conflict resolution * * Copyright © 1995 Ian Jackson <ian@chiark.greenend.org.uk> + * Copyright © 2008-2014 Guillem Jover <guillem@debian.org> * * This is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -35,11 +36,11 @@ bool packagelist::useavailable(pkginfo *pkg) { if (pkg->clientdata && - pkg->clientdata->selected == pkginfo::want_install && + pkg->clientdata->selected == want_install && pkg_is_informative(pkg, &pkg->available) && - (!(pkg->status == pkginfo::stat_installed || - pkg->status == pkginfo::stat_triggersawaited || - pkg->status == pkginfo::stat_triggerspending) || + (!(pkg->status == stat_installed || + pkg->status == stat_triggersawaited || + pkg->status == stat_triggerspending) || dpkg_version_compare(&pkg->available.version, &pkg->installed.version) > 0)) return true; @@ -185,9 +186,9 @@ packagelist::deselect_one_of(pkginfo *per, pkginfo *ped, dependency *dep) perpackagestate *best; // Try not keep packages needing reinstallation. - if (per->eflag & pkginfo::eflag_reinstreq) + if (per->eflag & eflag_reinstreq) best = ed; - else if (ped->eflag & pkginfo::eflag_reinstreq) + else if (ped->eflag & eflag_reinstreq) best = er; else if (er->spriority < ed->spriority) best= er; // We'd rather change the else if (er->spriority > ed->spriority) best= ed; // one with the lowest priority. @@ -203,8 +204,8 @@ packagelist::deselect_one_of(pkginfo *per, pkginfo *ped, dependency *dep) if (best->spriority >= sp_deselecting) return 0; best->suggested= - best->pkg->status == pkginfo::stat_notinstalled - ? pkginfo::want_purge : pkginfo::want_deinstall; // FIXME: configurable. + best->pkg->status == stat_notinstalled + ? want_purge : want_deinstall; // FIXME: configurable. best->selected= best->suggested; best->spriority= sp_deselecting; @@ -311,7 +312,7 @@ int packagelist::resolvedepcon(dependency *depends) { /* Always select depends. Only select recommends if we got here because * of a manually-initiated install request. */ if (depends->type != dep_recommends || manual_install) { - best->selected= best->suggested= pkginfo::want_install; + best->selected = best->suggested = want_install; best->spriority= sp_selecting; } return rc ? 2 : 0; @@ -327,8 +328,8 @@ int packagelist::resolvedepcon(dependency *depends) { /* Always remove depends, but never remove recommends. */ if (depends->type != dep_recommends) { best->selected= best->suggested= - best->pkg->status == pkginfo::stat_notinstalled - ? pkginfo::want_purge : pkginfo::want_deinstall; // FIXME: configurable + best->pkg->status == stat_notinstalled + ? want_purge : want_deinstall; // FIXME: configurable best->spriority= sp_deselecting; } return rc ? 2 : 0; @@ -383,7 +384,7 @@ packagelist::deppossatisfied(deppossi *possi, perpackagestate **fixbyupgrade) // ‘satisfied’ here for Conflicts and Breaks means that the // restriction is violated ie that the target package is wanted int would; - pkginfo::pkgwant want= pkginfo::want_purge; + pkgwant want = want_purge; if (possi->ed->pkg.clientdata) { want = possi->ed->pkg.clientdata->selected; @@ -400,12 +401,12 @@ packagelist::deppossatisfied(deppossi *possi, perpackagestate **fixbyupgrade) // been specified, in which case we don't need to look at the rest // anyway. if (useavailable(&possi->ed->pkg)) { - assert(want == pkginfo::want_install); + assert(want == want_install); return versionsatisfied(&possi->ed->pkg.available, possi); } else { if (versionsatisfied(&possi->ed->pkg.installed, possi)) return true; - if (want == pkginfo::want_hold && fixbyupgrade && !*fixbyupgrade && + if (want == want_hold && fixbyupgrade && !*fixbyupgrade && versionsatisfied(&possi->ed->pkg.available, possi) && dpkg_version_compare(&possi->ed->pkg.available.version, &possi->ed->pkg.installed.version) > 1) @@ -442,9 +443,9 @@ packagelist::deppossatisfied(deppossi *possi, perpackagestate **fixbyupgrade) if (useavailable(provider->up->up)) return true; if (fixbyupgrade && !*fixbyupgrade && - (!(provider->up->up->status == pkginfo::stat_installed || - provider->up->up->status == pkginfo::stat_triggerspending || - provider->up->up->status == pkginfo::stat_triggersawaited) || + (!(provider->up->up->status == stat_installed || + provider->up->up->status == stat_triggerspending || + provider->up->up->status == stat_triggersawaited) || dpkg_version_compare(&provider->up->up->available.version, &provider->up->up->installed.version) > 1)) *fixbyupgrade = provider->up->up->clientdata; diff --git a/dselect/pkglist.cc b/dselect/pkglist.cc index ccf835f4d..d9c5ad48a 100644 --- a/dselect/pkglist.cc +++ b/dselect/pkglist.cc @@ -4,6 +4,7 @@ * * Copyright © 1995 Ian Jackson <ian@chiark.greenend.org.uk> * Copyright © 2001 Wichert Akkerman <wakkerma@debian.org> + * Copyright © 2008-2014 Guillem Jover <guillem@debian.org> * * This is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -65,7 +66,7 @@ int packagelist::compareentries(const struct perpackagestate *a, strcasecmp(asection,bsection); int c_priority= a->pkg->priority - b->pkg->priority; - if (!c_priority && a->pkg->priority == pkginfo::pri_other) + if (!c_priority && a->pkg->priority == pri_other) c_priority= strcasecmp(a->pkg->otherpriority, b->pkg->otherpriority); int c_name= a->pkg->set->name && b->pkg->set->name ? @@ -109,7 +110,7 @@ void packagelist::discardheadings() { void packagelist::addheading(enum ssavailval ssavail, enum ssstateval ssstate, - pkginfo::pkgpriority priority, + pkgpriority priority, const char *otherpriority, const char *section) { assert(nitems <= nallocated); @@ -182,28 +183,28 @@ void packagelist::ensurestatsortinfo() { this, index, pkg_name(table[index]->pkg, pnaw_always)); pkg= table[index]->pkg; switch (pkg->status) { - case pkginfo::stat_unpacked: - case pkginfo::stat_halfconfigured: - case pkginfo::stat_halfinstalled: - case pkginfo::stat_triggersawaited: - case pkginfo::stat_triggerspending: + case stat_unpacked: + case stat_halfconfigured: + case stat_halfinstalled: + case stat_triggersawaited: + case stat_triggerspending: table[index]->ssavail= ssa_broken; break; - case pkginfo::stat_notinstalled: - case pkginfo::stat_configfiles: + case stat_notinstalled: + case stat_configfiles: if (!dpkg_version_is_informative(&pkg->available.version)) { table[index]->ssavail= ssa_notinst_gone; // FIXME: Disable for now as a workaround, until dselect knows how to properly // store seen packages. #if 0 - } else if (table[index]->original == pkginfo::want_unknown) { + } else if (table[index]->original == want_unknown) { table[index]->ssavail= ssa_notinst_unseen; #endif } else { table[index]->ssavail= ssa_notinst_seen; } break; - case pkginfo::stat_installed: + case stat_installed: veri= &table[index]->pkg->installed.version; vera= &table[index]->pkg->available.version; if (!dpkg_version_is_informative(vera)) { @@ -231,20 +232,20 @@ void packagelist::ensurestatsortinfo() { debug(dbg_general, "packagelist[%p]::ensurestatsortinfos() i=%d pkg=%s", this, index, pkg_name(table[index]->pkg, pnaw_always)); switch (table[index]->pkg->status) { - case pkginfo::stat_unpacked: - case pkginfo::stat_halfconfigured: - case pkginfo::stat_halfinstalled: - case pkginfo::stat_triggersawaited: - case pkginfo::stat_triggerspending: + case stat_unpacked: + case stat_halfconfigured: + case stat_halfinstalled: + case stat_triggersawaited: + case stat_triggerspending: table[index]->ssstate= sss_broken; break; - case pkginfo::stat_notinstalled: + case stat_notinstalled: table[index]->ssstate= sss_notinstalled; break; - case pkginfo::stat_configfiles: + case stat_configfiles: table[index]->ssstate= sss_configfiles; break; - case pkginfo::stat_installed: + case stat_installed: table[index]->ssstate= sss_installed; break; default: @@ -272,7 +273,7 @@ void packagelist::sortmakeheads() { this, sortorder, statsortorder); int nrealitems= nitems; - addheading(ssa_none, sss_none, pkginfo::pri_unset, nullptr, nullptr); + addheading(ssa_none, sss_none, pri_unset, nullptr, nullptr); assert(sortorder != so_unsorted); if (sortorder == so_alpha && statsortorder == sso_unsorted) { sortinplace(); return; } @@ -307,7 +308,7 @@ void packagelist::sortmakeheads() { int prioritydiff= (!lastpkg || thispkg->priority != lastpkg->priority || - (thispkg->priority == pkginfo::pri_other && + (thispkg->priority == pri_other && strcasecmp(thispkg->otherpriority,lastpkg->otherpriority))); int sectiondiff= (!lastpkg || strcasecmp(thispkg->section ? thispkg->section : "", @@ -320,7 +321,7 @@ void packagelist::sortmakeheads() { thispkg->clientdata->ssavail, thispkg->clientdata->ssstate, ssdiff ? "*diff" : "same", thispkg->priority, - thispkg->priority != pkginfo::pri_other ? "<none>" : + thispkg->priority != pri_other ? "<none>" : thispkg->otherpriority ? thispkg->otherpriority : "<null>", prioritydiff ? "*diff*" : "same", thispkg->section ? thispkg->section : "<null>", @@ -328,11 +329,11 @@ void packagelist::sortmakeheads() { if (ssdiff) addheading(ssavail,ssstate, - pkginfo::pri_unset, nullptr, nullptr); + pri_unset, nullptr, nullptr); if (sortorder == so_section && sectiondiff) addheading(ssavail,ssstate, - pkginfo::pri_unset, nullptr, + pri_unset, nullptr, thispkg->section ? thispkg->section : ""); if (sortorder == so_priority && prioritydiff) @@ -391,20 +392,20 @@ packagelist::packagelist(keybindings *kb) : baselist(kb) { while ((pkg = pkg_db_iter_next_pkg(iter))) { struct perpackagestate *state= &datatable[nitems]; state->pkg= pkg; - if (pkg->status == pkginfo::stat_notinstalled && + if (pkg->status == stat_notinstalled && !pkg->files && - pkg->want != pkginfo::want_install) { + pkg->want != want_install) { pkg->clientdata = nullptr; continue; } // treat all unknown packages as already seen - state->direct= state->original= (pkg->want == pkginfo::want_unknown ? pkginfo::want_purge : pkg->want); + state->direct = state->original = (pkg->want == want_unknown ? want_purge : pkg->want); if (modstatdb_get_status() == msdbrw_write && - state->original == pkginfo::want_unknown) { + state->original == want_unknown) { state->suggested= - pkg->status == pkginfo::stat_installed || - pkg->priority <= pkginfo::pri_standard /* FIXME: configurable */ - ? pkginfo::want_install : pkginfo::want_purge; + pkg->status == stat_installed || + pkg->priority <= pri_standard /* FIXME: configurable */ + ? want_install : want_purge; state->spriority= sp_inherit; } else { state->suggested= state->original; @@ -459,7 +460,7 @@ perpackagestate::free(bool recursive) } else { assert(!recursive); if (pkg->want != selected && - !(pkg->want == pkginfo::want_unknown && selected == pkginfo::want_purge)) { + !(pkg->want == want_unknown && selected == want_purge)) { pkg->want= selected; } pkg->clientdata = nullptr; diff --git a/dselect/pkglist.h b/dselect/pkglist.h index 2de7500af..8f19dd774 100644 --- a/dselect/pkglist.h +++ b/dselect/pkglist.h @@ -4,6 +4,7 @@ * * Copyright © 1994,1995 Ian Jackson <ian@chiark.greenend.org.uk> * Copyright © 2001 Wichert Akkerman <wakkerma@debian.org> + * Copyright © 2007-2014 Guillem Jover <guillem@debian.org> * * This is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -70,10 +71,10 @@ struct perpackagestate { * uprec is used when constructing the list initially and when tearing it * down and should not otherwise be used; other fields are undefined. */ - pkginfo::pkgwant original; // set by caller - pkginfo::pkgwant direct; // set by caller - pkginfo::pkgwant suggested; // set by caller, modified by resolvesuggest - pkginfo::pkgwant selected; // not set by caller, will be set by packagelist + pkgwant original; // set by caller + pkgwant direct; // set by caller + pkgwant suggested; // set by caller, modified by resolvesuggest + pkgwant selected; // not set by caller, will be set by packagelist selpriority spriority; // monotonically increases (used by sublists) showpriority dpriority; // monotonically increases (used by sublists) struct perpackagestate *uprec; // 0 if this is not part of a recursive list @@ -154,7 +155,7 @@ protected: void redraw1package(int index, int selected); int compareentries(const struct perpackagestate *a, const struct perpackagestate *b); friend int qsort_compareentries(const void *a, const void *b); - pkginfo::pkgwant reallywant(pkginfo::pkgwant, struct perpackagestate*); + pkgwant reallywant(pkgwant, struct perpackagestate *); int describemany(char buf[], const char *prioritystring, const char *section, const struct perpackagestate *pps); bool deppossatisfied(deppossi *possi, perpackagestate **fixbyupgrade); @@ -169,11 +170,11 @@ protected: // To do with building the list, with heading lines in it void discardheadings(); void addheading(enum ssavailval, enum ssstateval, - pkginfo::pkgpriority, const char*, const char *section); + pkgpriority, const char *, const char *section); void sortinplace(); bool affectedmatches(struct pkginfo *pkg, struct pkginfo *comparewith); void affectedrange(int *startp, int *endp); - void setwant(pkginfo::pkgwant nw); + void setwant(pkgwant nw); void sethold(int hold); public: @@ -202,7 +203,7 @@ protected: packagelist(keybindings *kb, pkginfo **pkgltab); // recursive void add(pkginfo **arry) { while (*arry) add(*arry++); } void add(pkginfo*); - void add(pkginfo*, pkginfo::pkgwant); + void add(pkginfo *, pkgwant); void add(pkginfo*, const char *extrainfo, showpriority displayimportance); bool add(dependency *, showpriority displayimportance); void addunavailable(deppossi*); @@ -217,7 +218,7 @@ protected: void repeatedlydisplay(packagelist *sub, showpriority, packagelist *unredisplay = nullptr); -int would_like_to_install(pkginfo::pkgwant, pkginfo *pkg); +int would_like_to_install(pkgwant, pkginfo *pkg); extern const char *const wantstrings[]; extern const char *const eflagstrings[]; diff --git a/dselect/pkgsublist.cc b/dselect/pkgsublist.cc index fea3f4039..1e5e1d7a7 100644 --- a/dselect/pkgsublist.cc +++ b/dselect/pkgsublist.cc @@ -3,6 +3,7 @@ * pkgsublist.cc - status modification and recursive package list handling * * Copyright © 1995 Ian Jackson <ian@chiark.greenend.org.uk> + * Copyright © 2007-2014 Guillem Jover <guillem@debian.org> * * This is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -53,7 +54,9 @@ void packagelist::add(pkginfo *pkg) { nitems++; } -void packagelist::add(pkginfo *pkg, pkginfo::pkgwant nw) { +void +packagelist::add(pkginfo *pkg, pkgwant nw) +{ debug(dbg_general, "packagelist[%p]::add(pkginfo %s, %s)", this, pkg_name(pkg, pnaw_always), wantstrings[nw]); add(pkg); if (!pkg->clientdata) return; diff --git a/dselect/pkgtop.cc b/dselect/pkgtop.cc index 8973e560c..49755e760 100644 --- a/dselect/pkgtop.cc +++ b/dselect/pkgtop.cc @@ -3,6 +3,7 @@ * pkgtop.cc - handles (re)draw of package list windows colheads, list, thisstate * * Copyright © 1994,1995 Ian Jackson <ian@chiark.greenend.org.uk> + * Copyright © 2007-2014 Guillem Jover <guillem@debian.org> * * This is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -36,12 +37,12 @@ static const char * pkgprioritystring(const struct pkginfo *pkg) { - if (pkg->priority == pkginfo::pri_unset) { + if (pkg->priority == pri_unset) { return nullptr; - } else if (pkg->priority == pkginfo::pri_other) { + } else if (pkg->priority == pri_other) { return pkg->otherpriority; } else { - assert(pkg->priority <= pkginfo::pri_unknown); + assert(pkg->priority <= pri_unknown); return gettext(prioritystrings[pkg->priority]); } } @@ -166,7 +167,7 @@ void packagelist::redraw1itemsel(int index, int selected) { mvwprintw(listpad, screenline, priority_column - 1, " %-*.*s", priority_width, priority_width, - pkg->priority == pkginfo::pri_other ? pkg->otherpriority : + pkg->priority == pri_other ? pkg->otherpriority : gettext(prioritystrings[pkg->priority])); } else { mvwaddch(listpad, screenline, 0, eflagchars[pkg->eflag]); @@ -182,7 +183,7 @@ void packagelist::redraw1itemsel(int index, int selected) { wmove(listpad, screenline, priority_column - 1); waddch(listpad, ' '); - if (pkg->priority == pkginfo::pri_other) { + if (pkg->priority == pri_other) { for (i=priority_width, p=pkg->otherpriority; i > 0 && *p; i--, p++) |