dpkg-parsechangelog.pl 2.2 KB

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