dpkg-parsechangelog.pl 2.5 KB

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