dpkg-parsechangelog.pl 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. use English;
  5. use POSIX;
  6. use POSIX qw(:errno_h);
  7. use Dpkg;
  8. use Dpkg::Gettext;
  9. use Dpkg::ErrorHandling;
  10. use Dpkg::Changelog qw(parse_changelog);
  11. textdomain("dpkg-dev");
  12. my %options;
  13. sub version {
  14. printf _g("Debian %s version %s.\n"), $progname, $version;
  15. printf _g("
  16. Copyright (C) 1996 Ian Jackson.
  17. Copyright (C) 2001 Wichert Akkerman");
  18. printf _g("
  19. This is free software; see the GNU General Public Licence version 2 or
  20. later for copying conditions. There is NO warranty.
  21. ");
  22. }
  23. sub usage {
  24. printf _g(
  25. "Usage: %s [<option> ...]
  26. Options:
  27. -l<changelogfile> get per-version info from this file.
  28. -F<changelogformat> force change log format.
  29. -L<libdir> look for change log parsers in <libdir>.
  30. -h, --help show this help message.
  31. --version show the version.
  32. parser options:
  33. --format <outputformat> see man page for list of available
  34. output formats, defaults to 'dpkg'
  35. for compatibility with dpkg-dev
  36. --since, -s, -v <version> include all changes later than version
  37. --until, -u <version> include all changes earlier than version
  38. --from, -f <version> include all changes equal or later
  39. than version
  40. --to, -t <version> include all changes up to or equal
  41. than version
  42. --count, -c, -n <number> include <number> entries from the top
  43. (or the tail if <number> is lower than 0)
  44. --offset, -o <number> change the starting point for --count,
  45. counted from the top (or the tail if
  46. <number> is lower than 0)
  47. --all include all changes
  48. "), $progname;
  49. }
  50. while (@ARGV) {
  51. last unless $ARGV[0] =~ m/^-/;
  52. $_ = shift(@ARGV);
  53. if (m/^-L(.+)$/) {
  54. $options{"libdir"} = $1;
  55. } elsif (m/^-F([0-9a-z]+)$/) {
  56. $options{"changelogformat"} = $1;
  57. } elsif (m/^-l(.+)$/) {
  58. $options{"file"} = $1;
  59. } elsif (m/^--$/) {
  60. last;
  61. } elsif (m/^-([cfnostuv])(.*)$/) {
  62. if (($1 eq "c") or ($1 eq "n")) {
  63. $options{"count"} = $2;
  64. } elsif ($1 eq "f") {
  65. $options{"from"} = $2;
  66. } elsif ($1 eq "o") {
  67. $options{"offset"} = $2;
  68. } elsif (($1 eq "s") or ($1 eq "v")) {
  69. $options{"since"} = $2;
  70. } elsif ($1 eq "t") {
  71. $options{"to"} = $2;
  72. } elsif ($1 eq "u") {
  73. $options{"until"} = $2;
  74. }
  75. } elsif (m/^--(count|file|format|from|offset|since|to|until)(.*)$/) {
  76. if ($2) {
  77. $options{$1} = $2;
  78. } else {
  79. $options{$1} = shift(@ARGV);
  80. }
  81. } elsif (m/^--all$/) {
  82. $options{"all"} = undef;
  83. } elsif (m/^-(h|-help)$/) {
  84. usage(); exit(0);
  85. } elsif (m/^--version$/) {
  86. version(); exit(0);
  87. } else {
  88. usageerr(_g("unknown option \`%s'"), $_);
  89. }
  90. }
  91. @ARGV && usageerr(_g("%s takes no non-option arguments"), $progname);
  92. my $count = 0;
  93. my @fields = parse_changelog(%options);
  94. foreach my $f (@fields) {
  95. print "\n" if $count++;
  96. print tied(%$f)->dump();
  97. }