main.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /*
  2. * dpkg-deb - construction and deconstruction of *.deb archives
  3. * main.c - main program
  4. *
  5. * Copyright © 1994,1995 Ian Jackson <ian@chiark.greenend.org.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 published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This is distributed in the hope that it will be useful,
  13. * but 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 License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #include <config.h>
  21. #include <compat.h>
  22. #include <sys/types.h>
  23. #include <sys/stat.h>
  24. #include <sys/wait.h>
  25. #include <assert.h>
  26. #include <errno.h>
  27. #include <limits.h>
  28. #if HAVE_LOCALE_H
  29. #include <locale.h>
  30. #endif
  31. #include <ctype.h>
  32. #include <string.h>
  33. #include <dirent.h>
  34. #include <unistd.h>
  35. #include <stdlib.h>
  36. #include <stdio.h>
  37. #include <dpkg/macros.h>
  38. #include <dpkg/i18n.h>
  39. #include <dpkg/dpkg.h>
  40. #include <dpkg/dpkg-db.h>
  41. #include <dpkg/compress.h>
  42. #include <dpkg/myopt.h>
  43. #include "dpkg-deb.h"
  44. const char* showformat = "${Package}\t${Version}\n";
  45. static void DPKG_ATTR_NORET
  46. printversion(const struct cmdinfo *cip, const char *value)
  47. {
  48. printf(_("Debian `%s' package archive backend version %s.\n"),
  49. BACKEND, DPKG_VERSION_ARCH);
  50. printf(_(
  51. "This is free software; see the GNU General Public License version 2 or\n"
  52. "later for copying conditions. There is NO warranty.\n"));
  53. m_output(stdout, _("<standard output>"));
  54. exit(0);
  55. }
  56. static void DPKG_ATTR_NORET
  57. usage(const struct cmdinfo *cip, const char *value)
  58. {
  59. printf(_(
  60. "Usage: %s [<option> ...] <command>\n"
  61. "\n"), BACKEND);
  62. printf(_(
  63. "Commands:\n"
  64. " -b|--build <directory> [<deb>] Build an archive.\n"
  65. " -c|--contents <deb> List contents.\n"
  66. " -I|--info <deb> [<cfile> ...] Show info to stdout.\n"
  67. " -W|--show <deb> Show information on package(s)\n"
  68. " -f|--field <deb> [<cfield> ...] Show field(s) to stdout.\n"
  69. " -e|--control <deb> [<directory>] Extract control info.\n"
  70. " -x|--extract <deb> <directory> Extract files.\n"
  71. " -X|--vextract <deb> <directory> Extract & list files.\n"
  72. " --fsys-tarfile <deb> Output filesystem tarfile.\n"
  73. "\n"));
  74. printf(_(
  75. " -h|--help Show this help message.\n"
  76. " --version Show the version.\n"
  77. "\n"));
  78. printf(_(
  79. "<deb> is the filename of a Debian format archive.\n"
  80. "<cfile> is the name of an administrative file component.\n"
  81. "<cfield> is the name of a field in the main `control' file.\n"
  82. "\n"));
  83. printf(_(
  84. "Options:\n"
  85. " --showformat=<format> Use alternative format for --show.\n"
  86. " -D Enable debugging output.\n"
  87. " --old, --new Select archive format.\n"
  88. " --nocheck Suppress control file check (build bad\n"
  89. " packages).\n"
  90. " -z# Set the compression level when building.\n"
  91. " -Z<type> Set the compression type used when building.\n"
  92. " Allowed types: gzip, xz, bzip2, lzma, none.\n"
  93. "\n"));
  94. printf(_(
  95. "Format syntax:\n"
  96. " A format is a string that will be output for each package. The format\n"
  97. " can include the standard escape sequences \\n (newline), \\r (carriage\n"
  98. " return) or \\\\ (plain backslash). Package information can be included\n"
  99. " by inserting variable references to package fields using the ${var[;width]}\n"
  100. " syntax. Fields will be right-aligned unless the width is negative in which\n"
  101. " case left alignment will be used.\n"));
  102. printf(_(
  103. "\n"
  104. "Use `dpkg' to install and remove packages from your system, or\n"
  105. "`dselect' or `aptitude' for user-friendly package management. Packages\n"
  106. "unpacked using `dpkg-deb --extract' will be incorrectly installed !\n"));
  107. m_output(stdout, _("<standard output>"));
  108. exit(0);
  109. }
  110. const char thisname[]= BACKEND;
  111. const char printforhelp[]=
  112. N_("Type dpkg-deb --help for help about manipulating *.deb files;\n"
  113. "Type dpkg --help for help about installing and deinstalling packages.");
  114. int debugflag=0, nocheckflag=0, oldformatflag=BUILDOLDPKGFORMAT;
  115. struct compressor *compressor = &compressor_gzip;
  116. int compress_level = -1;
  117. static void setcompresstype(const struct cmdinfo *cip, const char *value);
  118. static void
  119. set_compress_level(const struct cmdinfo *cip, const char *value)
  120. {
  121. long level;
  122. char *end;
  123. level = strtol(value, &end, 0);
  124. if (value == end || *end || level > INT_MAX)
  125. badusage(_("invalid integer for -%c: '%.250s'"), cip->oshort, value);
  126. if (level < 0 || level > 9)
  127. badusage(_("invalid compression level for -%c: %ld'"), cip->oshort, level);
  128. compress_level = level;
  129. }
  130. static const struct cmdinfo cmdinfos[]= {
  131. ACTION("build", 'b', 0, do_build),
  132. ACTION("contents", 'c', 0, do_contents),
  133. ACTION("control", 'e', 0, do_control),
  134. ACTION("info", 'I', 0, do_info),
  135. ACTION("field", 'f', 0, do_field),
  136. ACTION("extract", 'x', 0, do_extract),
  137. ACTION("vextract", 'X', 0, do_vextract),
  138. ACTION("fsys-tarfile", 0, 0, do_fsystarfile),
  139. ACTION("show", 'W', 0, do_showinfo),
  140. { "new", 0, 0, &oldformatflag, NULL, NULL, 0 },
  141. { "old", 0, 0, &oldformatflag, NULL, NULL, 1 },
  142. { "debug", 'D', 0, &debugflag, NULL, NULL, 1 },
  143. { "nocheck", 0, 0, &nocheckflag, NULL, NULL, 1 },
  144. { "compression", 'z', 1, NULL, NULL, set_compress_level },
  145. { "compress_type", 'Z', 1, NULL, NULL, setcompresstype },
  146. { "showformat", 0, 1, NULL, &showformat, NULL },
  147. { "help", 'h', 0, NULL, NULL, usage },
  148. { "version", 0, 0, NULL, NULL, printversion },
  149. { NULL, 0, 0, NULL, NULL, NULL }
  150. };
  151. static void setcompresstype(const struct cmdinfo *cip, const char *value) {
  152. compressor = compressor_find_by_name(value);
  153. if (compressor == NULL)
  154. ohshit(_("unknown compression type `%s'!"), value);
  155. }
  156. int main(int argc, const char *const *argv) {
  157. dofunction *action;
  158. setlocale(LC_NUMERIC, "POSIX");
  159. setlocale(LC_ALL, "");
  160. bindtextdomain(PACKAGE, LOCALEDIR);
  161. textdomain(PACKAGE);
  162. standard_startup();
  163. myopt(&argv, cmdinfos);
  164. if (!cipaction) badusage(_("need an action option"));
  165. unsetenv("GZIP");
  166. action = (dofunction *)cipaction->farg;
  167. action(argv);
  168. standard_shutdown();
  169. exit(0);
  170. }
  171. /* vi: sw=2
  172. */