main.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*
  2. * dpkg-deb - construction and deconstruction of *.deb archives
  3. * main.c - main program
  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 dpkg; 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 <stdlib.h>
  24. #include <signal.h>
  25. #include <sys/stat.h>
  26. #include <sys/types.h>
  27. #include <sys/wait.h>
  28. #include <errno.h>
  29. #include <unistd.h>
  30. #include <dirent.h>
  31. #include <limits.h>
  32. #include <ctype.h>
  33. #include <assert.h>
  34. #include <config.h>
  35. #include <dpkg.h>
  36. #include <version.h>
  37. #include <myopt.h>
  38. #include "dpkg-deb.h"
  39. static void printversion(void) {
  40. if (fputs(_("Debian GNU/Linux `"), stdout) < 0) werr("stdout");
  41. if (fputs(BACKEND, stdout) < 0) werr("stdout");
  42. if (fputs(_("' package archive backend version "), stdout) < 0) werr("stdout");
  43. if (fputs(DPKG_VERSION_ARCH ".\n", stdout) < 0) werr("stdout");
  44. if (fputs(_("Copyright (C) 1994-1996 Ian Jackson. This is free software; see the\n"
  45. "GNU General Public Licence version 2 or later for copying conditions.\n"
  46. "There is NO warranty. See dpkg-deb --licence for details.\n"),
  47. stdout) < 0) werr("stdout");
  48. }
  49. static void usage(void) {
  50. if (fputs(_("\
  51. Usage: dpkg-deb -b|--build <directory> [<deb>] Build an archive.\n\
  52. dpkg-deb -c|--contents <deb> List contents.\n\
  53. dpkg-deb -I|--info <deb> [<cfile>...] Show info to stdout.\n\
  54. dpkg-deb -f|--field <deb> [<cfield>...] Show field(s) to stdout.\n\
  55. dpkg-deb -e|--control <deb> [<directory>] Extract control info.\n\
  56. dpkg-deb -x|--extract <deb> <directory> Extract files.\n\
  57. dpkg-deb -X|--vextract <deb> <directory> Extract & list files.\n\
  58. dpkg-deb --fsys-tarfile <deb> Output filesystem tarfile.\n\
  59. dpkg-deb -h|--help Display this message.\n\
  60. dpkg-deb --version | --licence Show version/licence.\n\
  61. <deb> is the filename of a Debian format archive.\n\
  62. <cfile> is the name of an administrative file component.\n\
  63. <cfield> is the name of a field in the main `control' file.\n\
  64. Options: -D for debugging output; --old or --new controls archive format;\n\
  65. --nocheck to suppress control file check (build bad package).\n\
  66. -z# to set the compression when building\n\
  67. \n\
  68. Use `dpkg' to install and remove packages from your system, or\n\
  69. `dselect' for user-friendly package management. Packages unpacked\n\
  70. using `dpkg-deb --extract' will be incorrectly installed !\n"),
  71. stdout) < 0) werr("stdout");
  72. }
  73. const char thisname[]= BACKEND;
  74. const char printforhelp[]=
  75. N_("Type dpkg-deb --help for help about manipulating *.deb files;\n"
  76. "Type dpkg --help for help about installing and deinstalling packages.");
  77. int debugflag=0, nocheckflag=0, oldformatflag=BUILDOLDPKGFORMAT;
  78. const char* compression=NULL;
  79. const struct cmdinfo *cipaction=0;
  80. dofunction *action=0;
  81. static void helponly(const struct cmdinfo *cip, const char *value) {
  82. usage(); exit(0);
  83. }
  84. static void versiononly(const struct cmdinfo *cip, const char *value) {
  85. printversion(); exit(0);
  86. }
  87. static void setaction(const struct cmdinfo *cip, const char *value);
  88. static dofunction *const dofunctions[]= {
  89. do_build,
  90. do_contents,
  91. do_control,
  92. do_info,
  93. do_field,
  94. do_extract,
  95. do_vextract,
  96. do_fsystarfile
  97. };
  98. /* NB: the entries using setaction must appear first and be in the
  99. * same order as dofunctions:
  100. */
  101. static const struct cmdinfo cmdinfos[]= {
  102. { "build", 'b', 0, 0, 0, setaction },
  103. { "contents", 'c', 0, 0, 0, setaction },
  104. { "control", 'e', 0, 0, 0, setaction },
  105. { "info", 'I', 0, 0, 0, setaction },
  106. { "field", 'f', 0, 0, 0, setaction },
  107. { "extract", 'x', 0, 0, 0, setaction },
  108. { "vextract", 'X', 0, 0, 0, setaction },
  109. { "fsys-tarfile", 0, 0, 0, 0, setaction },
  110. { "new", 0, 0, &oldformatflag, 0, 0, 0 },
  111. { "old", 0, 0, &oldformatflag, 0, 0, 1 },
  112. { "debug", 'D', 0, &debugflag, 0, 0, 1 },
  113. { "nocheck", 0, 0, &nocheckflag, 0, 0, 1 },
  114. { "compression", 'z', 1, 0, &compression, 0, 1 },
  115. { "help", 'h', 0, 0, 0, helponly },
  116. { "version", 0, 0, 0, 0, versiononly },
  117. { "licence", 0, 0, 0, 0, showcopyright }, /* UK spelling */
  118. { "license", 0, 0, 0, 0, showcopyright }, /* US spelling */
  119. { 0, 0 }
  120. };
  121. static void setaction(const struct cmdinfo *cip, const char *value) {
  122. if (cipaction)
  123. badusage(_("conflicting actions --%s and --%s"),cip->olong,cipaction->olong);
  124. cipaction= cip;
  125. assert(cip-cmdinfos < sizeof(dofunctions)*sizeof(dofunction*));
  126. action= dofunctions[cip-cmdinfos];
  127. }
  128. int main(int argc, const char *const *argv) {
  129. jmp_buf ejbuf;
  130. setlocale(LC_ALL, "");
  131. setlocale(LC_NUMERIC, "POSIX");
  132. bindtextdomain(PACKAGE, LOCALEDIR);
  133. textdomain(PACKAGE);
  134. if (setjmp(ejbuf)) { /* expect warning about possible clobbering of argv */
  135. error_unwind(ehflag_bombout); exit(2);
  136. }
  137. push_error_handler(&ejbuf,print_error_fatal,0);
  138. myopt(&argv,cmdinfos);
  139. if (!cipaction) badusage(_("need an action option"));
  140. unsetenv("GZIP");
  141. action(argv);
  142. set_error_display(0,0);
  143. error_unwind(ehflag_normaltidy);
  144. exit(0);
  145. }