dpkg-parsechangelog.pl 2.3 KB

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