pkgdisplay.cc 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. /*
  2. * dselect - Debian package maintenance user interface
  3. * pkgdisplay.cc - package list display
  4. *
  5. * Copyright © 1994,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 published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This is distributed in the hope that it will be useful,
  13. * but 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 License
  18. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  19. */
  20. #include <config.h>
  21. #include <compat.h>
  22. #include <string.h>
  23. #include <stdio.h>
  24. #include <dpkg/i18n.h>
  25. #include <dpkg/dpkg.h>
  26. #include <dpkg/dpkg-db.h>
  27. #include "dselect.h"
  28. #include "pkglist.h"
  29. /* These MUST be in the same order as the corresponding enums in dpkg-db.h */
  30. const char
  31. *const wantstrings[]= { N_("new package"),
  32. N_("install"),
  33. N_("hold"),
  34. N_("remove"),
  35. N_("purge"),
  36. nullptr },
  37. /* TRANSLATORS: The space is a trick to work around gettext which uses
  38. * the empty string to store information about the translation. DO NOT
  39. * CHANGE THAT IN A TRANSLATION! The code really relies on that being
  40. * a single space. */
  41. *const eflagstrings[]= { N_(" "),
  42. N_("REINSTALL"),
  43. nullptr },
  44. *const statusstrings[]= { N_("not installed"),
  45. N_("removed (configs remain)"),
  46. N_("half installed"),
  47. N_("unpacked (not set up)"),
  48. N_("half configured (config failed)"),
  49. N_("awaiting trigger processing"),
  50. N_("triggered"),
  51. N_("installed"),
  52. nullptr },
  53. *const prioritystrings[]= { N_("Required"),
  54. N_("Important"),
  55. N_("Standard"),
  56. N_("Optional"),
  57. N_("Extra"),
  58. N_("Unclassified"),
  59. nullptr },
  60. *const relatestrings[]= { N_("suggests"),
  61. N_("recommends"),
  62. N_("depends on"),
  63. N_("pre-depends on"),
  64. N_("breaks"),
  65. N_("conflicts with"),
  66. N_("provides"),
  67. N_("replaces"),
  68. N_("enhances"),
  69. nullptr },
  70. *const priorityabbrevs[]= { N_("Req"),
  71. N_("Imp"),
  72. N_("Std"),
  73. N_("Opt"),
  74. N_("Xtr"),
  75. N_("bUG"),
  76. N_("?") };
  77. const char statuschars[] = " -IUCWt*";
  78. const char eflagchars[] = " R";
  79. const char wantchars[]= "n*=-_";
  80. /* These MUST be in the same order as the corresponding enums in pkglist.h */
  81. const char
  82. *const ssaabbrevs[]= { N_("Broken"),
  83. N_("New"),
  84. N_("Upgradable"),
  85. N_("Obsolete/local"),
  86. N_("Installed"),
  87. N_("Available"),
  88. N_("Removed") },
  89. *const ssastrings[]= { N_("Brokenly installed packages"),
  90. N_("Newly available packages"),
  91. N_("Upgradable packages"),
  92. N_("Obsolete and locally created packages"),
  93. N_("Installed packages"),
  94. N_("Available not installed packages"),
  95. N_("Removed and no longer available packages") };
  96. const char
  97. *const sssstrings[]= { N_("Brokenly installed packages"),
  98. N_("Installed packages"),
  99. N_("Removed packages (configuration still present)"),
  100. N_("Purged packages and those never installed") },
  101. *const sssabbrevs[]= { N_("Broken"),
  102. N_("Installed"),
  103. N_("Removed"),
  104. N_("Purged") };
  105. static int maximumstring(const char *const *array) {
  106. int maxlen= 0;
  107. while (*array) {
  108. int l= strlen(gettext(*array));
  109. const char *p= strchr(*array, '(');
  110. if (p && p > *array && *--p == ' ') l= p - *array;
  111. if (l > maxlen) maxlen= l;
  112. array++;
  113. }
  114. return maxlen;
  115. }
  116. void packagelist::setwidths() {
  117. debug(dbg_general, "packagelist[%p]::setwidths()", this);
  118. col_cur_x = 0;
  119. if (verbose) {
  120. add_column(col_status_hold, _("Error"), 9);
  121. add_column(col_status_status, _("Installed?"), maximumstring(statusstrings));
  122. add_column(col_status_old_want, _("Old mark"), maximumstring(wantstrings));
  123. add_column(col_status_new_want, _("Marked for"), maximumstring(wantstrings));
  124. } else {
  125. add_column(col_status, _("EIOM"), 4);
  126. }
  127. if (sortorder == so_section)
  128. add_column(col_section, _("Section"), 8);
  129. add_column(col_priority, _("Priority"), verbose ? 8 : 3);
  130. if (sortorder != so_section)
  131. add_column(col_section, _("Section"), 8);
  132. add_column(col_package, _("Package"), verbose ? 16 : 12);
  133. switch (archdisplayopt) {
  134. case ado_none:
  135. col_archinstalled.blank();
  136. col_archavailable.blank();
  137. break;
  138. case ado_available:
  139. col_archinstalled.blank();
  140. add_column(col_archavailable, _("Avail.arch"), verbose ? 14 : 10);
  141. break;
  142. case ado_both:
  143. add_column(col_archinstalled, _("Inst.arch"), verbose ? 14 : 10);
  144. add_column(col_archavailable, _("Avail.arch"), verbose ? 14 : 10);
  145. break;
  146. default:
  147. internerr("unknown archdisplayopt %d", archdisplayopt);
  148. }
  149. switch (versiondisplayopt) {
  150. case vdo_none:
  151. col_versioninstalled.blank();
  152. col_versionavailable.blank();
  153. break;
  154. case vdo_available:
  155. col_versioninstalled.blank();
  156. add_column(col_versionavailable, _("Avail.ver"), 11);
  157. break;
  158. case vdo_both:
  159. add_column(col_versioninstalled, _("Inst.ver"), 11);
  160. add_column(col_versionavailable, _("Avail.ver"), 11);
  161. break;
  162. default:
  163. internerr("unknown versiondisplayopt %d", versiondisplayopt);
  164. }
  165. end_column(col_description, _("Description"));
  166. }
  167. void packagelist::redrawtitle() {
  168. int x, y DPKG_ATTR_UNUSED;
  169. if (title_height) {
  170. mywerase(titlewin);
  171. mvwaddnstr(titlewin,0,0,
  172. recursive ? _("dselect - recursive package listing") :
  173. modstatdb_get_status() == msdbrw_readonly ?
  174. _("dselect - inspection of package states") :
  175. _("dselect - main package listing"),
  176. xmax);
  177. getyx(titlewin,y,x);
  178. if (x < xmax) {
  179. switch (sortorder) {
  180. case so_section:
  181. switch (statsortorder) {
  182. case sso_unsorted:
  183. waddnstr(titlewin, _(" (by section)"), xmax-x);
  184. break;
  185. case sso_avail:
  186. waddnstr(titlewin, _(" (avail., section)"), xmax-x);
  187. break;
  188. case sso_state:
  189. waddnstr(titlewin, _(" (status, section)"), xmax-x);
  190. break;
  191. default:
  192. internerr("bad statsort %d on so_section", statsortorder);
  193. }
  194. break;
  195. case so_priority:
  196. switch (statsortorder) {
  197. case sso_unsorted:
  198. waddnstr(titlewin, _(" (by priority)"), xmax-x);
  199. break;
  200. case sso_avail:
  201. waddnstr(titlewin, _(" (avail., priority)"), xmax-x);
  202. break;
  203. case sso_state:
  204. waddnstr(titlewin, _(" (status, priority)"), xmax-x);
  205. break;
  206. default:
  207. internerr("bad statsort %d on so_priority", statsortorder);
  208. }
  209. break;
  210. case so_alpha:
  211. switch (statsortorder) {
  212. case sso_unsorted:
  213. waddnstr(titlewin, _(" (alphabetically)"), xmax-x);
  214. break;
  215. case sso_avail:
  216. waddnstr(titlewin, _(" (by availability)"), xmax-x);
  217. break;
  218. case sso_state:
  219. waddnstr(titlewin, _(" (by status)"), xmax-x);
  220. break;
  221. default:
  222. internerr("bad statsort %d on so_priority", statsortorder);
  223. }
  224. break;
  225. case so_unsorted:
  226. break;
  227. default:
  228. internerr("bad sort %d", sortorder);
  229. }
  230. }
  231. const char *helpstring;
  232. if (modstatdb_get_status() == msdbrw_write)
  233. helpstring = (verbose ? _(" mark:+/=/- terse:v help:?")
  234. : _(" mark:+/=/- verbose:v help:?"));
  235. else
  236. helpstring = (verbose ? _(" terse:v help:?")
  237. : _(" verbose:v help:?"));
  238. int l= strlen(helpstring);
  239. getyx(titlewin,y,x);
  240. if (xmax-l > 0) {
  241. mvwaddstr(titlewin,0,xmax-l, helpstring);
  242. }
  243. wnoutrefresh(titlewin);
  244. }
  245. }