dpkg-parsechangelog.pl 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. #!/usr/bin/perl
  2. #
  3. # dpkg-parsechangelog
  4. #
  5. # Copyright © 1996 Ian Jackson
  6. # Copyright © 2001 Wichert Akkerman
  7. # Copyright © 2006-2012 Guillem Jover <guillem@debian.org>
  8. #
  9. # This program is free software; you can redistribute it and/or modify
  10. # it under the terms of the GNU General Public License as published by
  11. # the Free Software Foundation; either version 2 of the License, or
  12. # (at your option) any later version.
  13. #
  14. # This program is distributed in the hope that it will be useful,
  15. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. # GNU General Public License for more details.
  18. #
  19. # You should have received a copy of the GNU General Public License
  20. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. use strict;
  22. use warnings;
  23. use Dpkg;
  24. use Dpkg::Gettext;
  25. use Dpkg::ErrorHandling;
  26. use Dpkg::Changelog::Parse;
  27. textdomain("dpkg-dev");
  28. my %options;
  29. sub version {
  30. printf _g("Debian %s version %s.\n"), $progname, $version;
  31. printf _g("
  32. This is free software; see the GNU General Public License version 2 or
  33. later for copying conditions. There is NO warranty.
  34. ");
  35. }
  36. sub usage {
  37. printf _g(
  38. "Usage: %s [<option>...]")
  39. . "\n\n" . _g(
  40. "Options:
  41. -l<changelog-file> get per-version info from this file.
  42. -F<changelog-format> force changelog format.
  43. -L<libdir> look for changelog parsers in <libdir>.
  44. -?, --help show this help message.
  45. --version show the version.")
  46. . "\n\n" . _g(
  47. "Parser options:
  48. --format <output-format> see man page for list of available
  49. output formats, defaults to 'dpkg'
  50. for compatibility with dpkg-dev
  51. --since <version>, include all changes later than version
  52. -s<version>, -v<version>
  53. --until <version>, include all changes earlier than version
  54. -u<version>
  55. --from <version>, include all changes equal or later
  56. -f<version> than version
  57. --to <version>, -t<version> include all changes up to or equal
  58. than version
  59. --count <number>, include <number> entries from the top
  60. -c<number>, -n<number> (or the tail if <number> is lower than 0)
  61. --offset <number>, change the starting point for --count,
  62. -o<number> counted from the top (or the tail if
  63. <number> is lower than 0)
  64. --all include all changes
  65. "), $progname;
  66. }
  67. while (@ARGV) {
  68. last unless $ARGV[0] =~ m/^-/;
  69. $_ = shift(@ARGV);
  70. if (m/^-L(.+)$/) {
  71. $options{"libdir"} = $1;
  72. } elsif (m/^-F([0-9a-z]+)$/) {
  73. $options{"changelogformat"} = $1;
  74. } elsif (m/^-l(.+)$/) {
  75. $options{"file"} = $1;
  76. } elsif (m/^--$/) {
  77. last;
  78. } elsif (m/^-([cfnostuv])(.*)$/) {
  79. if (($1 eq "c") or ($1 eq "n")) {
  80. $options{"count"} = $2;
  81. } elsif ($1 eq "f") {
  82. $options{"from"} = $2;
  83. } elsif ($1 eq "o") {
  84. $options{"offset"} = $2;
  85. } elsif (($1 eq "s") or ($1 eq "v")) {
  86. $options{"since"} = $2;
  87. } elsif ($1 eq "t") {
  88. $options{"to"} = $2;
  89. } elsif ($1 eq "u") {
  90. $options{"until"} = $2;
  91. }
  92. } elsif (m/^--(count|file|format|from|offset|since|to|until)(.*)$/) {
  93. if ($2) {
  94. $options{$1} = $2;
  95. } else {
  96. $options{$1} = shift(@ARGV);
  97. }
  98. } elsif (m/^--all$/) {
  99. $options{"all"} = undef;
  100. } elsif (m/^-(\?|-help)$/) {
  101. usage(); exit(0);
  102. } elsif (m/^--version$/) {
  103. version(); exit(0);
  104. } else {
  105. usageerr(_g("unknown option \`%s'"), $_);
  106. }
  107. }
  108. @ARGV && usageerr(_g("takes no non-option arguments"));
  109. my $count = 0;
  110. my @fields = changelog_parse(%options);
  111. foreach my $f (@fields) {
  112. print "\n" if $count++;
  113. print $f->output();
  114. }