You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

93 lines
1.7 KiB

  1. /* $Id: tasksel.c,v 1.3 1999/11/23 05:12:43 tausq Exp $ */
  2. #include "tasksel.h"
  3. #include <string.h>
  4. #include <signal.h>
  5. #include <libintl.h>
  6. #include <locale.h>
  7. #include <stdlib.h>
  8. #include <unistd.h>
  9. #include "slangui.h"
  10. #include "data.h"
  11. #include "macros.h"
  12. static void signalhandler(int sig)
  13. {
  14. switch (sig) {
  15. case SIGWINCH:
  16. ui_resize();
  17. break;
  18. default:
  19. DPRINTF("%s\n", _("Unknown signal seen"));
  20. }
  21. }
  22. void help(void)
  23. {
  24. fprintf(stderr, "tasksel [-t]\n\t");
  25. fprintf(stderr, "%s\n\n", _("-t -- test mode; don't actually run apt-get on exit"));
  26. exit(0);
  27. }
  28. int main(int argc, char * const argv[])
  29. {
  30. int i, c, r, testmode = 0;
  31. struct packages_t taskpkgs, packages;
  32. struct package_t **pkglist;
  33. char buf[2048];
  34. signal(SIGWINCH, signalhandler);
  35. setlocale(LC_ALL, "");
  36. bindtextdomain(PACKAGE, LOCALEDIR);
  37. textdomain(PACKAGE);
  38. while (1) {
  39. c = getopt(argc, argv, "t");
  40. if (c == -1) break;
  41. switch (c) {
  42. case 't': testmode = 1; break;
  43. default: help();
  44. }
  45. }
  46. packages_readlist(&taskpkgs, &packages);
  47. ui_init(argc, argv, &taskpkgs, &packages);
  48. ui_drawscreen();
  49. r = ui_eventloop();
  50. ui_shutdown();
  51. pkglist = packages_enumerate(&taskpkgs);
  52. if (r == 0) {
  53. sprintf(buf, "apt-get install ");
  54. c = 0;
  55. for (i = 0; i < taskpkgs.count; i++) {
  56. if (pkglist[i]->selected > 0) {
  57. /* TODO check buffer overflow; not likely, but still... */
  58. strcat(buf, pkglist[i]->name);
  59. strcat(buf, " ");
  60. c++;
  61. }
  62. }
  63. if (c > 0) {
  64. if (testmode == 1)
  65. printf("%s\n", buf);
  66. else
  67. system(buf);
  68. } else {
  69. fprintf(stderr, "No packages selected\n");
  70. r = 1;
  71. }
  72. }
  73. packages_free(&taskpkgs, &packages);
  74. return r;
  75. }