main.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /*
  2. * dpkg-split - splitting and joining of multipart *.deb archives
  3. * main.c - main program
  4. *
  5. * Copyright © 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 <assert.h>
  25. #include <limits.h>
  26. #if HAVE_LOCALE_H
  27. #include <locale.h>
  28. #endif
  29. #include <string.h>
  30. #include <stdlib.h>
  31. #include <stdio.h>
  32. #include <dpkg/macros.h>
  33. #include <dpkg/i18n.h>
  34. #include <dpkg/dpkg.h>
  35. #include <dpkg/dpkg-db.h>
  36. #include <dpkg/myopt.h>
  37. #include "dpkg-split.h"
  38. static void DPKG_ATTR_NORET
  39. printversion(const struct cmdinfo *cip, const char *value)
  40. {
  41. printf(_("Debian `%s' package split/join tool; version %s.\n"),
  42. SPLITTER, DPKG_VERSION_ARCH);
  43. printf(_("Copyright (C) 1994-1996 Ian Jackson.\n"));
  44. printf(_(
  45. "This is free software; see the GNU General Public License version 2 or\n"
  46. "later for copying conditions. There is NO warranty.\n"));
  47. m_output(stdout, _("<standard output>"));
  48. exit(0);
  49. }
  50. static void DPKG_ATTR_NORET
  51. usage(const struct cmdinfo *cip, const char *value)
  52. {
  53. printf(_(
  54. "Usage: %s [<option> ...] <command>\n"
  55. "\n"), SPLITTER);
  56. printf(_(
  57. "Commands:\n"
  58. " -s|--split <file> [<prefix>] Split an archive.\n"
  59. " -j|--join <part> <part> ... Join parts together.\n"
  60. " -I|--info <part> ... Display info about a part.\n"
  61. " -a|--auto -o <complete> <part> Auto-accumulate parts.\n"
  62. " -l|--listq List unmatched pieces.\n"
  63. " -d|--discard [<filename> ...] Discard unmatched pieces.\n"
  64. "\n"));
  65. printf(_(
  66. " -h|--help Show this help message.\n"
  67. " --version Show the version.\n"
  68. "\n"));
  69. printf(_(
  70. "Options:\n"
  71. " --depotdir <directory> Use <directory> instead of %s/%s.\n"
  72. " -S|--partsize <size> In KiB, for -s (default is 450).\n"
  73. " -o|--output <file> For -j (default is <package>-<version>.deb).\n"
  74. " -Q|--npquiet Be quiet when -a is not a part.\n"
  75. " --msdos Generate 8.3 filenames.\n"
  76. "\n"
  77. "Exit status: 0 = OK; 1 = -a is not a part; 2 = trouble!\n"),
  78. ADMINDIR, PARTSDIR);
  79. m_output(stdout, _("<standard output>"));
  80. exit(0);
  81. }
  82. const char thisname[]= SPLITTER;
  83. const char printforhelp[]= N_("Type dpkg-split --help for help.");
  84. struct partqueue *queue= NULL;
  85. long opt_maxpartsize = SPLITPARTDEFMAX;
  86. const char *opt_depotdir = ADMINDIR "/" PARTSDIR;
  87. const char *opt_outputfile = NULL;
  88. int opt_npquiet = 0;
  89. int opt_msdos = 0;
  90. void rerr(const char *fn) {
  91. ohshite(_("error reading %.250s"), fn);
  92. }
  93. void rerreof(FILE *f, const char *fn) {
  94. if (ferror(f)) ohshite(_("error reading %.250s"),fn);
  95. ohshit(_("unexpected end of file in %.250s"),fn);
  96. }
  97. static void setpartsize(const struct cmdinfo *cip, const char *value) {
  98. long newpartsize;
  99. char *endp;
  100. newpartsize= strtol(value,&endp,10);
  101. if (value == endp || *endp)
  102. badusage(_("invalid integer for --%s: `%.250s'"), cip->olong, value);
  103. if (newpartsize <= 0 || newpartsize > (INT_MAX >> 10))
  104. badusage(_("part size is far too large or is not positive"));
  105. opt_maxpartsize = newpartsize << 10;
  106. if (opt_maxpartsize <= HEADERALLOWANCE)
  107. badusage(_("part size must be at least %d KiB (to allow for header)"),
  108. (HEADERALLOWANCE >> 10) + 1);
  109. }
  110. static const struct cmdinfo cmdinfos[]= {
  111. ACTION("split", 's', 0, do_split),
  112. ACTION("join", 'j', 0, do_join),
  113. ACTION("info", 'I', 0, do_info),
  114. ACTION("auto", 'a', 0, do_auto),
  115. ACTION("listq", 'l', 0, do_queue),
  116. ACTION("discard", 'd', 0, do_discard),
  117. { "help", 'h', 0, NULL, NULL, usage },
  118. { "version", 0, 0, NULL, NULL, printversion },
  119. { "depotdir", 0, 1, NULL, &opt_depotdir, NULL },
  120. { "partsize", 'S', 1, NULL, NULL, setpartsize },
  121. { "output", 'o', 1, NULL, &opt_outputfile, NULL },
  122. { "npquiet", 'Q', 0, &opt_npquiet, NULL, NULL, 1 },
  123. { "msdos", 0, 0, &opt_msdos, NULL, NULL, 1 },
  124. { NULL, 0 }
  125. };
  126. int main(int argc, const char *const *argv) {
  127. int l;
  128. char *p;
  129. dofunction *action;
  130. setlocale(LC_ALL, "");
  131. bindtextdomain(PACKAGE, LOCALEDIR);
  132. textdomain(PACKAGE);
  133. standard_startup();
  134. myopt(&argv, cmdinfos);
  135. if (!cipaction) badusage(_("need an action option"));
  136. l = strlen(opt_depotdir);
  137. if (l && opt_depotdir[l - 1] != '/') {
  138. p= nfmalloc(l+2);
  139. strcpy(p, opt_depotdir);
  140. strcpy(p+l,"/");
  141. opt_depotdir = p;
  142. }
  143. setvbuf(stdout,NULL,_IONBF,0);
  144. action = (dofunction *)cipaction->farg;
  145. action(argv);
  146. m_output(stderr, _("<standard error>"));
  147. standard_shutdown();
  148. exit(0);
  149. }