dpkg-parsechangelog.pl 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 <version>, include all changes later than version
  37. -s<version>, -v<version>
  38. --until <version>, include all changes earlier than version
  39. -u<version>
  40. --from <version>, include all changes equal or later
  41. -f<version> than version
  42. --to <version>, -t<version> include all changes up to or equal
  43. than version
  44. --count <number>, include <number> entries from the top
  45. -c<number>, -n<number> (or the tail if <number> is lower than 0)
  46. --offset <number>, change the starting point for --count,
  47. -o<number> counted from the top (or the tail if
  48. <number> is lower than 0)
  49. --all include all changes
  50. "), $progname;
  51. }
  52. while (@ARGV) {
  53. last unless $ARGV[0] =~ m/^-/;
  54. $_ = shift(@ARGV);
  55. if (m/^-L(.+)$/) {
  56. $options{"libdir"} = $1;
  57. } elsif (m/^-F([0-9a-z]+)$/) {
  58. $options{"changelogformat"} = $1;
  59. } elsif (m/^-l(.+)$/) {
  60. $options{"file"} = $1;
  61. } elsif (m/^--$/) {
  62. last;
  63. } elsif (m/^-([cfnostuv])(.*)$/) {
  64. if (($1 eq "c") or ($1 eq "n")) {
  65. $options{"count"} = $2;
  66. } elsif ($1 eq "f") {
  67. $options{"from"} = $2;
  68. } elsif ($1 eq "o") {
  69. $options{"offset"} = $2;
  70. } elsif (($1 eq "s") or ($1 eq "v")) {
  71. $options{"since"} = $2;
  72. } elsif ($1 eq "t") {
  73. $options{"to"} = $2;
  74. } elsif ($1 eq "u") {
  75. $options{"until"} = $2;
  76. }
  77. } elsif (m/^--(count|file|format|from|offset|since|to|until)(.*)$/) {
  78. if ($2) {
  79. $options{$1} = $2;
  80. } else {
  81. $options{$1} = shift(@ARGV);
  82. }
  83. } elsif (m/^--all$/) {
  84. $options{"all"} = undef;
  85. } elsif (m/^-(h|-help)$/) {
  86. usage(); exit(0);
  87. } elsif (m/^--version$/) {
  88. version(); exit(0);
  89. } else {
  90. usageerr(_g("unknown option \`%s'"), $_);
  91. }
  92. }
  93. @ARGV && usageerr(_g("%s takes no non-option arguments"), $progname);
  94. my $count = 0;
  95. my @fields = parse_changelog(%options);
  96. foreach my $f (@fields) {
  97. print "\n" if $count++;
  98. print $f->output();
  99. }