main.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /*
  2. * dpkg-split - splitting and joining of multipart *.deb archives
  3. * main.c - main program
  4. *
  5. * Copyright © 1994-1996 Ian Jackson <ian@chiark.greenend.org.uk>
  6. * Copyright © 2006-2012 Guillem Jover <guillem@debian.org>
  7. *
  8. * This is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. #include <config.h>
  22. #include <compat.h>
  23. #include <sys/types.h>
  24. #include <sys/stat.h>
  25. #include <assert.h>
  26. #include <errno.h>
  27. #include <limits.h>
  28. #include <inttypes.h>
  29. #if HAVE_LOCALE_H
  30. #include <locale.h>
  31. #endif
  32. #include <string.h>
  33. #include <stdlib.h>
  34. #include <stdio.h>
  35. #include <dpkg/macros.h>
  36. #include <dpkg/i18n.h>
  37. #include <dpkg/dpkg.h>
  38. #include <dpkg/dpkg-db.h>
  39. #include <dpkg/options.h>
  40. #include "dpkg-split.h"
  41. static void DPKG_ATTR_NORET
  42. printversion(const struct cmdinfo *cip, const char *value)
  43. {
  44. printf(_("Debian `%s' package split/join tool; version %s.\n"),
  45. SPLITTER, DPKG_VERSION_ARCH);
  46. printf(_(
  47. "This is free software; see the GNU General Public License version 2 or\n"
  48. "later for copying conditions. There is NO warranty.\n"));
  49. m_output(stdout, _("<standard output>"));
  50. exit(0);
  51. }
  52. static void DPKG_ATTR_NORET
  53. usage(const struct cmdinfo *cip, const char *value)
  54. {
  55. printf(_(
  56. "Usage: %s [<option> ...] <command>\n"
  57. "\n"), SPLITTER);
  58. printf(_(
  59. "Commands:\n"
  60. " -s|--split <file> [<prefix>] Split an archive.\n"
  61. " -j|--join <part> <part> ... Join parts together.\n"
  62. " -I|--info <part> ... Display info about a part.\n"
  63. " -a|--auto -o <complete> <part> Auto-accumulate parts.\n"
  64. " -l|--listq List unmatched pieces.\n"
  65. " -d|--discard [<filename> ...] Discard unmatched pieces.\n"
  66. "\n"));
  67. printf(_(
  68. " -?, --help Show this help message.\n"
  69. " --version Show the version.\n"
  70. "\n"));
  71. printf(_(
  72. "Options:\n"
  73. " --depotdir <directory> Use <directory> instead of %s/%s.\n"
  74. " -S|--partsize <size> In KiB, for -s (default is 450).\n"
  75. " -o|--output <file> Filename, for -j (default is\n"
  76. " <package>_<version>_<arch>.deb).\n"
  77. " -Q|--npquiet Be quiet when -a is not a part.\n"
  78. " --msdos Generate 8.3 filenames.\n"
  79. "\n"), ADMINDIR, PARTSDIR);
  80. printf(_(
  81. "Exit status:\n"
  82. " 0 = ok\n"
  83. " 1 = with --auto, file is not a part\n"
  84. " 2 = trouble\n"));
  85. m_output(stdout, _("<standard output>"));
  86. exit(0);
  87. }
  88. static const char printforhelp[] = N_("Type dpkg-split --help for help.");
  89. struct partqueue *queue= NULL;
  90. off_t opt_maxpartsize = SPLITPARTDEFMAX;
  91. static const char *admindir;
  92. const char *opt_depotdir;
  93. const char *opt_outputfile = NULL;
  94. int opt_npquiet = 0;
  95. int opt_msdos = 0;
  96. void rerreof(FILE *f, const char *fn) {
  97. if (ferror(f)) ohshite(_("error reading %.250s"),fn);
  98. ohshit(_("unexpected end of file in %.250s"),fn);
  99. }
  100. static void setpartsize(const struct cmdinfo *cip, const char *value) {
  101. off_t newpartsize;
  102. char *endp;
  103. errno = 0;
  104. newpartsize = strtoimax(value, &endp, 10);
  105. if (value == endp || *endp)
  106. badusage(_("invalid integer for --%s: `%.250s'"), cip->olong, value);
  107. if (newpartsize <= 0 || newpartsize > (INT_MAX >> 10) || errno == ERANGE)
  108. badusage(_("part size is far too large or is not positive"));
  109. opt_maxpartsize = newpartsize << 10;
  110. if (opt_maxpartsize <= HEADERALLOWANCE)
  111. badusage(_("part size must be at least %d KiB (to allow for header)"),
  112. (HEADERALLOWANCE >> 10) + 1);
  113. }
  114. static const struct cmdinfo cmdinfos[]= {
  115. ACTION("split", 's', 0, do_split),
  116. ACTION("join", 'j', 0, do_join),
  117. ACTION("info", 'I', 0, do_info),
  118. ACTION("auto", 'a', 0, do_auto),
  119. ACTION("listq", 'l', 0, do_queue),
  120. ACTION("discard", 'd', 0, do_discard),
  121. { "help", '?', 0, NULL, NULL, usage },
  122. { "version", 0, 0, NULL, NULL, printversion },
  123. { "depotdir", 0, 1, NULL, &opt_depotdir, NULL },
  124. { "partsize", 'S', 1, NULL, NULL, setpartsize },
  125. { "output", 'o', 1, NULL, &opt_outputfile, NULL },
  126. { "npquiet", 'Q', 0, &opt_npquiet, NULL, NULL, 1 },
  127. { "msdos", 0, 0, &opt_msdos, NULL, NULL, 1 },
  128. { NULL, 0 }
  129. };
  130. int main(int argc, const char *const *argv) {
  131. int ret;
  132. setlocale(LC_ALL, "");
  133. bindtextdomain(PACKAGE, LOCALEDIR);
  134. textdomain(PACKAGE);
  135. dpkg_set_progname(SPLITTER);
  136. standard_startup();
  137. myopt(&argv, cmdinfos, printforhelp);
  138. admindir = dpkg_db_set_dir(admindir);
  139. if (opt_depotdir == NULL)
  140. opt_depotdir = dpkg_db_get_path(PARTSDIR);
  141. if (!cipaction) badusage(_("need an action option"));
  142. setvbuf(stdout,NULL,_IONBF,0);
  143. ret = cipaction->action(argv);
  144. m_output(stderr, _("<standard error>"));
  145. standard_shutdown();
  146. return ret;
  147. }