main.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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) NONRETURNING;
  82. static void helponly(const struct cmdinfo *cip, const char *value) {
  83. usage(); exit(0);
  84. }
  85. static void versiononly(const struct cmdinfo *cip, const char *value) NONRETURNING;
  86. static void versiononly(const struct cmdinfo *cip, const char *value) {
  87. printversion(); exit(0);
  88. }
  89. static void setaction(const struct cmdinfo *cip, const char *value);
  90. static dofunction *const dofunctions[]= {
  91. do_build,
  92. do_contents,
  93. do_control,
  94. do_info,
  95. do_field,
  96. do_extract,
  97. do_vextract,
  98. do_fsystarfile
  99. };
  100. /* NB: the entries using setaction must appear first and be in the
  101. * same order as dofunctions:
  102. */
  103. static const struct cmdinfo cmdinfos[]= {
  104. { "build", 'b', 0, 0, 0, setaction },
  105. { "contents", 'c', 0, 0, 0, setaction },
  106. { "control", 'e', 0, 0, 0, setaction },
  107. { "info", 'I', 0, 0, 0, setaction },
  108. { "field", 'f', 0, 0, 0, setaction },
  109. { "extract", 'x', 0, 0, 0, setaction },
  110. { "vextract", 'X', 0, 0, 0, setaction },
  111. { "fsys-tarfile", 0, 0, 0, 0, setaction },
  112. { "new", 0, 0, &oldformatflag, 0, 0, 0 },
  113. { "old", 0, 0, &oldformatflag, 0, 0, 1 },
  114. { "debug", 'D', 0, &debugflag, 0, 0, 1 },
  115. { "nocheck", 0, 0, &nocheckflag, 0, 0, 1 },
  116. { "compression", 'z', 1, 0, &compression, 0, 1 },
  117. { "help", 'h', 0, 0, 0, helponly },
  118. { "version", 0, 0, 0, 0, versiononly },
  119. { "licence", 0, 0, 0, 0, showcopyright }, /* UK spelling */
  120. { "license", 0, 0, 0, 0, showcopyright }, /* US spelling */
  121. { 0, 0 }
  122. };
  123. static void setaction(const struct cmdinfo *cip, const char *value) {
  124. if (cipaction)
  125. badusage(_("conflicting actions --%s and --%s"),cip->olong,cipaction->olong);
  126. cipaction= cip;
  127. assert((int)(cip-cmdinfos) < (int)(sizeof(dofunctions)*sizeof(dofunction*)));
  128. action= dofunctions[cip-cmdinfos];
  129. }
  130. int main(int argc, const char *const *argv) NONRETURNING;
  131. int main(int argc, const char *const *argv) {
  132. jmp_buf ejbuf;
  133. setlocale(LC_ALL, "");
  134. setlocale(LC_NUMERIC, "POSIX");
  135. bindtextdomain(PACKAGE, LOCALEDIR);
  136. textdomain(PACKAGE);
  137. if (setjmp(ejbuf)) { /* expect warning about possible clobbering of argv */
  138. error_unwind(ehflag_bombout); exit(2);
  139. }
  140. push_error_handler(&ejbuf,print_error_fatal,0);
  141. myopt(&argv,cmdinfos);
  142. if (!cipaction) badusage(_("need an action option"));
  143. unsetenv("GZIP");
  144. action(argv);
  145. set_error_display(0,0);
  146. error_unwind(ehflag_normaltidy);
  147. exit(0);
  148. }