pkgdisplay.cc 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. /*
  2. * dselect - Debian GNU/Linux package maintenance user interface
  3. * pkgdisplay.cc - package list display
  4. *
  5. * Copyright (C) 1994,1995 Ian Jackson <iwj10@cus.cam.ac.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
  9. * published by the Free Software Foundation; either version 2,
  10. * or (at your option) any later version.
  11. *
  12. * This is distributed in the hope that it will be useful, but
  13. * 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
  18. * License along with this; if not, write to the Free Software
  19. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. */
  21. #include <stdio.h>
  22. #include <string.h>
  23. #include <curses.h>
  24. #include <assert.h>
  25. #include <signal.h>
  26. extern "C" {
  27. #include <config.h>
  28. #include <dpkg.h>
  29. #include <dpkg-db.h>
  30. }
  31. #include "dselect.h"
  32. #include "pkglist.h"
  33. /* These MUST be in the same order as the corresponding enums in dpkg-db.h */
  34. const char
  35. *const wantstrings[]= { N_("new package"),
  36. N_("install"),
  37. N_("hold"),
  38. N_("remove"),
  39. N_("purge"),
  40. 0 },
  41. *const eflagstrings[]= { N_(""),
  42. N_("REINSTALL"),
  43. 0 },
  44. *const statusstrings[]= { N_("not installed"),
  45. N_("unpacked (not set up)"),
  46. N_("failed config"),
  47. N_("installed"),
  48. N_("half installed"),
  49. N_("removed (configs remain)"),
  50. 0 },
  51. *const prioritystrings[]= { N_("Required"),
  52. N_("Important"),
  53. N_("Standard"),
  54. N_("Recommended"),
  55. N_("Optional"),
  56. N_("Extra"),
  57. N_("Contrib"),
  58. N_("!Bug!"),
  59. N_("Unclassified"),
  60. 0 },
  61. *const relatestrings[]= { N_("suggests"),
  62. N_("recommends"),
  63. N_("depends on"),
  64. N_("pre-depends on"),
  65. N_("conflicts with"),
  66. N_("provides"),
  67. N_("replaces"),
  68. 0 },
  69. *const priorityabbrevs[]= { N_("Req"),
  70. N_("Imp"),
  71. N_("Std"),
  72. N_("Rec"),
  73. N_("Opt"),
  74. N_("Xtr"),
  75. N_("Ctb"),
  76. N_("bUG"),
  77. N_("?") };
  78. const char statuschars[]= " UC*I-";
  79. const char eflagchars[]= " R?#";
  80. const char wantchars[]= "n*=-_";
  81. /* These MUST be in the same order as the corresponding enums in pkglist.h */
  82. const char
  83. *const ssaabbrevs[]= { N_("Broken"),
  84. N_("New"),
  85. N_("Updated"),
  86. N_("Obsolete/local"),
  87. N_("Up-to-date"),
  88. N_("Available"),
  89. N_("Removed") },
  90. *const ssastrings[]= { N_("Brokenly installed packages"),
  91. N_("Newly available packages"),
  92. N_("Updated packages (newer version is available)"),
  93. N_("Obsolete and local packages present on system"),
  94. N_("Up to date installed packages"),
  95. N_("Available packages (not currently installed)"),
  96. N_("Removed and no longer available packages") };
  97. const char
  98. *const sssstrings[]= { N_("Brokenly installed packages"),
  99. N_("Installed packages"),
  100. N_("Removed packages (configuration still present)"),
  101. N_("Purged packages and those never installed") },
  102. *const sssabbrevs[]= { N_("Broken"),
  103. N_("Installed"),
  104. N_("Removed"),
  105. N_("Purged") };
  106. static int maximumstring(const char *const *array) {
  107. int maxlen= 0;
  108. while (*array) {
  109. int l= strlen(gettext(*array));
  110. const char *p= strchr(*array, '(');
  111. if (p && p > *array && *--p == ' ') l= p - *array;
  112. if (l > maxlen) maxlen= l;
  113. array++;
  114. }
  115. return maxlen;
  116. }
  117. void packagelist::setwidths() {
  118. if (debug) fprintf(debug,"packagelist[%p]::setwidths()\n",this);
  119. if (verbose) {
  120. status_hold_width= 9;
  121. status_status_width= maximumstring(statusstrings);
  122. status_want_width= maximumstring(wantstrings);
  123. status_width= status_hold_width+status_status_width+status_want_width*2+3;
  124. priority_width= 8;
  125. package_width= 16;
  126. } else {
  127. status_width= 4;
  128. priority_width= 3;
  129. package_width= 12;
  130. }
  131. section_width= 8;
  132. gap_width= 1;
  133. if (sortorder == so_section) {
  134. section_column= status_width + gap_width;
  135. priority_column= section_column + section_width + gap_width;
  136. package_column= priority_column + priority_width + gap_width;
  137. } else {
  138. priority_column= status_width + gap_width;
  139. section_column= priority_column + priority_width + gap_width;
  140. package_column= section_column + section_width + gap_width;
  141. }
  142. int versiondescriptioncolumn= package_column + package_width + gap_width;
  143. switch (versiondisplayopt) {
  144. case vdo_none:
  145. versioninstalled_column= versioninstalled_width= 0;
  146. versionavailable_column= versionavailable_width= 0;
  147. description_column= versiondescriptioncolumn;
  148. break;
  149. case vdo_available:
  150. versioninstalled_column= versioninstalled_width= 0;
  151. versionavailable_column= versiondescriptioncolumn;
  152. versionavailable_width= 11;
  153. description_column= versionavailable_column + versionavailable_width + gap_width;
  154. break;
  155. case vdo_both:
  156. versioninstalled_column= versiondescriptioncolumn;
  157. versioninstalled_width= 11;
  158. versionavailable_column= versioninstalled_column + versioninstalled_width +gap_width;
  159. versionavailable_width= versioninstalled_width;
  160. description_column= versionavailable_column + versionavailable_width + gap_width;
  161. break;
  162. default:
  163. internerr(_("unknown versiondisplayopt in setwidths"));
  164. }
  165. total_width= TOTAL_LIST_WIDTH;
  166. description_width= total_width - description_column;
  167. }
  168. void packagelist::redrawtitle() {
  169. int x,y;
  170. if (title_height) {
  171. mywerase(titlewin);
  172. mvwaddnstr(titlewin,0,0,
  173. recursive ? _("dselect - recursive package listing") :
  174. !readwrite ? _("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 in redrawtitle/so_section"));
  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 in redrawtitle/so_priority"));
  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 in redrawtitle/so_priority"));
  223. }
  224. break;
  225. waddnstr(titlewin, _(" (alphabetically)"), xmax-x);
  226. break;
  227. case so_unsorted:
  228. break;
  229. default:
  230. internerr(_("bad sort in redrawtitle"));
  231. }
  232. }
  233. const char *helpstring= readwrite ? (verbose ? _(" mark:+/=/- terse:v help:?")
  234. : _(" mark:+/=/- verbose:v help:?"))
  235. : (verbose ? _(" terse:v help:?")
  236. : _(" verbose:v help:?"));
  237. int l= strlen(helpstring);
  238. getyx(titlewin,y,x);
  239. if (xmax-l > 0) {
  240. mvwaddstr(titlewin,0,xmax-l, helpstring);
  241. }
  242. wnoutrefresh(titlewin);
  243. }
  244. }