pkgdisplay.cc 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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 <ncurses.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[]= { "new package", "install", "hold", "remove", "purge", 0 },
  36. *const eflagstrings[]= { "", "REINSTALL", 0 },
  37. *const statusstrings[]= { "not installed", "unpacked (not set up)",
  38. "failed config", "installed", "half installed",
  39. "removed (configs remain)", 0 },
  40. *const prioritystrings[]= { "Required", "Important", "Standard", "Recommended",
  41. "Optional", "Extra", "Contrib",
  42. "!Bug!", "Unclassified", 0 },
  43. *const relatestrings[]= { "suggests", "recommends", "depends on", "pre-depends on",
  44. "conflicts with", "provides", "replaces", 0 },
  45. *const priorityabbrevs[]= { "Req", "Imp", "Std", "Rec",
  46. "Opt", "Xtr", "Ctb",
  47. "bUG", "?" };
  48. const char statuschars[]= " UC*I-";
  49. const char eflagchars[]= " R?#";
  50. const char wantchars[]= "n*=-_";
  51. /* These MUST be in the same order as the corresponding enums in pkglist.h */
  52. const char
  53. *const ssaabbrevs[]= { "Broken",
  54. "New",
  55. "Updated",
  56. "Obsolete/local",
  57. "Up-to-date",
  58. "Available",
  59. "Removed" },
  60. *const ssastrings[]= { "Brokenly installed packages",
  61. "Newly available packages",
  62. "Updated packages (newer version is available)",
  63. "Obsolete and local packages present on system",
  64. "Up to date installed packages",
  65. "Available packages (not currently installed)",
  66. "Removed and no longer available packages" };
  67. const char
  68. *const sssstrings[]= { "Brokenly installed packages",
  69. "Installed packages",
  70. "Removed packages (configuration still present)",
  71. "Purged packages and those never installed" },
  72. *const sssabbrevs[]= { "Broken",
  73. "Installed",
  74. "Removed",
  75. "Purged" };
  76. static int maximumstring(const char *const *array) {
  77. int maxlen= 0;
  78. while (*array) {
  79. int l= strlen(*array);
  80. const char *p= strchr(*array, '(');
  81. if (p && p > *array && *--p == ' ') l= p - *array;
  82. if (l > maxlen) maxlen= l;
  83. array++;
  84. }
  85. return maxlen;
  86. }
  87. void packagelist::setwidths() {
  88. if (debug) fprintf(debug,"packagelist[%p]::setwidths()\n",this);
  89. if (verbose) {
  90. status_hold_width= 9;
  91. status_status_width= maximumstring(statusstrings);
  92. status_want_width= maximumstring(wantstrings);
  93. status_width= status_hold_width+status_status_width+status_want_width*2+3;
  94. priority_width= 8;
  95. package_width= 16;
  96. } else {
  97. status_width= 4;
  98. priority_width= 3;
  99. package_width= 12;
  100. }
  101. section_width= 8;
  102. gap_width= 1;
  103. if (sortorder == so_section) {
  104. section_column= status_width + gap_width;
  105. priority_column= section_column + section_width + gap_width;
  106. package_column= priority_column + priority_width + gap_width;
  107. } else {
  108. priority_column= status_width + gap_width;
  109. section_column= priority_column + priority_width + gap_width;
  110. package_column= section_column + section_width + gap_width;
  111. }
  112. int versiondescriptioncolumn= package_column + package_width + gap_width;
  113. switch (versiondisplayopt) {
  114. case vdo_none:
  115. versioninstalled_column= versioninstalled_width= 0;
  116. versionavailable_column= versionavailable_width= 0;
  117. description_column= versiondescriptioncolumn;
  118. break;
  119. case vdo_available:
  120. versioninstalled_column= versioninstalled_width= 0;
  121. versionavailable_column= versiondescriptioncolumn;
  122. versionavailable_width= 11;
  123. description_column= versionavailable_column + versionavailable_width + gap_width;
  124. break;
  125. case vdo_both:
  126. versioninstalled_column= versiondescriptioncolumn;
  127. versioninstalled_width= 11;
  128. versionavailable_column= versioninstalled_column + versioninstalled_width +gap_width;
  129. versionavailable_width= versioninstalled_width;
  130. description_column= versionavailable_column + versionavailable_width + gap_width;
  131. break;
  132. default:
  133. internerr("unknown versiondisplayopt in setwidths");
  134. }
  135. total_width= TOTAL_LIST_WIDTH;
  136. description_width= total_width - description_column;
  137. }
  138. void packagelist::redrawtitle() {
  139. int x,y;
  140. if (title_height) {
  141. mywerase(titlewin);
  142. mvwaddnstr(titlewin,0,0,
  143. recursive ? "dselect - recursive package listing" :
  144. !readwrite ? "dselect - inspection of package states" :
  145. "dselect - main package listing",
  146. xmax);
  147. getyx(titlewin,y,x);
  148. if (x < xmax) {
  149. switch (sortorder) {
  150. case so_section:
  151. switch (statsortorder) {
  152. case sso_unsorted:
  153. waddnstr(titlewin, " (by section)", xmax-x);
  154. break;
  155. case sso_avail:
  156. waddnstr(titlewin, " (avail., section)", xmax-x);
  157. break;
  158. case sso_state:
  159. waddnstr(titlewin, " (status, section)", xmax-x);
  160. break;
  161. default:
  162. internerr("bad statsort in redrawtitle/so_section");
  163. }
  164. break;
  165. case so_priority:
  166. switch (statsortorder) {
  167. case sso_unsorted:
  168. waddnstr(titlewin, " (by priority)", xmax-x);
  169. break;
  170. case sso_avail:
  171. waddnstr(titlewin, " (avail., priority)", xmax-x);
  172. break;
  173. case sso_state:
  174. waddnstr(titlewin, " (status, priority)", xmax-x);
  175. break;
  176. default:
  177. internerr("bad statsort in redrawtitle/so_priority");
  178. }
  179. break;
  180. case so_alpha:
  181. switch (statsortorder) {
  182. case sso_unsorted:
  183. waddnstr(titlewin, " (alphabetically)", xmax-x);
  184. break;
  185. case sso_avail:
  186. waddnstr(titlewin, " (by availability)", xmax-x);
  187. break;
  188. case sso_state:
  189. waddnstr(titlewin, " (by status)", xmax-x);
  190. break;
  191. default:
  192. internerr("bad statsort in redrawtitle/so_priority");
  193. }
  194. break;
  195. waddnstr(titlewin, " (alphabetically)", xmax-x);
  196. break;
  197. case so_unsorted:
  198. break;
  199. default:
  200. internerr("bad sort in redrawtitle");
  201. }
  202. }
  203. const char *helpstring= readwrite ? (verbose ? " mark:+/=/- terse:v help:?"
  204. : " mark:+/=/- verbose:v help:?")
  205. : (verbose ? " terse:v help:?"
  206. : " verbose:v help:?");
  207. int l= strlen(helpstring);
  208. getyx(titlewin,y,x);
  209. if (xmax-l > 0) {
  210. mvwaddstr(titlewin,0,xmax-l, helpstring);
  211. }
  212. wnoutrefresh(titlewin);
  213. }
  214. }