dpkg-parsechangelog.pl 3.0 KB

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