dpkg-parsechangelog.pl 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. use POSIX;
  5. use POSIX qw(:errno_h);
  6. use Dpkg;
  7. use Dpkg::Gettext;
  8. push(@INC,$dpkglibdir);
  9. require 'controllib.pl';
  10. textdomain("dpkg-dev");
  11. my $format ='debian';
  12. my $changelogfile = 'debian/changelog';
  13. my @parserpath = ("/usr/local/lib/dpkg/parsechangelog",
  14. "$dpkglibdir/parsechangelog");
  15. my $libdir; # XXX: Not used!?
  16. my $force;
  17. sub version {
  18. printf _g("Debian %s version %s.\n"), $progname, $version;
  19. printf _g("
  20. Copyright (C) 1996 Ian Jackson.
  21. Copyright (C) 2001 Wichert Akkerman");
  22. printf _g("
  23. This is free software; see the GNU General Public Licence version 2 or
  24. later for copying conditions. There is NO warranty.
  25. ");
  26. }
  27. sub usage {
  28. printf _g(
  29. "Usage: %s [<option> ...]
  30. Options:
  31. -l<changelogfile> get per-version info from this file.
  32. -v<sinceversion> include all changes later than version.
  33. -F<changelogformat> force change log format.
  34. -L<libdir> look for change log parsers in <libdir>.
  35. -h, --help show this help message.
  36. --version show the version.
  37. "), $progname;
  38. }
  39. my @ap = ();
  40. while (@ARGV) {
  41. last unless $ARGV[0] =~ m/^-/;
  42. $_= shift(@ARGV);
  43. if (m/^-L/ && length($_)>2) { $libdir=$'; next; }
  44. if (m/^-F([0-9a-z]+)$/) { $force=1; $format=$1; next; }
  45. push(@ap,$_);
  46. if (m/^-l/ && length($_)>2) { $changelogfile=$'; next; }
  47. m/^--$/ && last;
  48. m/^-v/ && next;
  49. if (m/^-(h|-help)$/) { &usage; exit(0); }
  50. if (m/^--version$/) { &version; exit(0); }
  51. &usageerr("unknown option \`$_'");
  52. }
  53. @ARGV && &usageerr(sprintf(_g("%s takes no non-option arguments"), $progname));
  54. $changelogfile= "./$changelogfile" if $changelogfile =~ m/^\s/;
  55. if (not $force and $changelogfile ne "-") {
  56. open(STDIN,"< $changelogfile") ||
  57. &error(sprintf(_g("cannot open %s to find format: %s"), $changelogfile, $!));
  58. open(P,"tail -n 40 |") || die sprintf(_g("cannot fork: %s"), $!)."\n";
  59. while(<P>) {
  60. next unless m/\schangelog-format:\s+([0-9a-z]+)\W/;
  61. $format=$1;
  62. }
  63. close(P); $? && &subprocerr(sprintf(_g("tail of %s"), $changelogfile));
  64. }
  65. my ($pa, $pf);
  66. for my $pd (@parserpath) {
  67. $pa= "$pd/$format";
  68. if (!stat("$pa")) {
  69. $! == ENOENT || &syserr(sprintf(_g("failed to check for format parser %s"), $pa));
  70. } elsif (!-x _) {
  71. warning(sprintf(_g("format parser %s not executable"), $pa));
  72. } else {
  73. $pf= $pa;
  74. last;
  75. }
  76. }
  77. defined($pf) || &error(sprintf(_g("format %s unknown"), $pa));
  78. if ($changelogfile ne "-") {
  79. open(STDIN,"< $changelogfile") || die sprintf(_g("cannot open %s: %s"), $changelogfile, $!)."\n";
  80. }
  81. exec($pf,@ap); die sprintf(_g("cannot exec format parser: %s"), $!)."\n";