dpkg-parsechangelog.pl 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #!/usr/bin/perl
  2. $dpkglibdir= ".";
  3. $version= '1.3.0'; # This line modified by Makefile
  4. $format='dpkg';
  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 [-L<libdir>] [-F<format>] [-v<version>]
  18. [-lchangelogfile]
  19. ";
  20. }
  21. @ap=();
  22. while (@ARGV) {
  23. last unless $ARGV[0] =~ m/^-/;
  24. $_= shift(@ARGV);
  25. if (m/^-L/ && length($_)>2) { $libdir=$'; next; }
  26. if (m/^-F([0-9a-z]+)$/) { $force=1; $format=$1; next; }
  27. if (m/^-l/ && length($_)>2) { $changelogfile=$'; next; }
  28. push(@ap,$_);
  29. m/^--$/ && last;
  30. m/^-v/ && next;
  31. &usageerr("unknown option \`$_'");
  32. }
  33. @ARGV && &usageerr("$progname takes no non-option arguments");
  34. $changelogfile= "./$changelogfile" if $changelogfile =~ m/^\s/;
  35. if (!$force) {
  36. open(STDIN,"< $changelogfile") ||
  37. &error("cannot open $changelogfile to find format: $!");
  38. open(P,"tail -40 |") || die "cannot fork: $!\n";
  39. while(<P>) {
  40. next unless m/\schangelog-format:\s+([0-9a-z]+)\W/;
  41. $format=$1;
  42. }
  43. close(P); $? && &subprocerr("tail of $changelogfile");
  44. }
  45. for $pd (@parserpath) {
  46. $pa= "$pd/$format";
  47. if (!stat("$pa")) {
  48. $! == ENOENT || &syserr("failed to check for format parser $pa");
  49. } elsif (!-x _) {
  50. &warn("format parser $pa not executable");
  51. } else {
  52. $pf= $pa;
  53. }
  54. }
  55. defined($pf) || &error("format $pa unknown");
  56. open(STDIN,"< $changelogfile") || die "cannot open $changelogfile: $!\n";
  57. exec($pf,@ap); die "cannot exec format parser: $!\n";