dpkg-parsechangelog.pl 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. my $fieldname;
  30. sub version {
  31. printf _g("Debian %s version %s.\n"), $Dpkg::PROGNAME, $Dpkg::PROGVERSION;
  32. printf _g('
  33. This is free software; see the GNU General Public License version 2 or
  34. later for copying conditions. There is NO warranty.
  35. ');
  36. }
  37. sub usage {
  38. printf _g(
  39. 'Usage: %s [<option>...]')
  40. . "\n\n" . _g(
  41. 'Options:
  42. -l<changelog-file> get per-version info from this file.
  43. -F<changelog-format> force changelog format.
  44. -L<libdir> look for changelog parsers in <libdir>.
  45. -S, --show-field <field> show the values for <field>.
  46. -?, --help show this help message.
  47. --version show the version.')
  48. . "\n\n" . _g(
  49. "Parser options:
  50. --format <output-format> see man page for list of available
  51. output formats, defaults to 'dpkg'
  52. for compatibility with dpkg-dev
  53. --since <version>, include all changes later than version
  54. -s<version>, -v<version>
  55. --until <version>, include all changes earlier than version
  56. -u<version>
  57. --from <version>, include all changes equal or later
  58. -f<version> than version
  59. --to <version>, -t<version> include all changes up to or equal
  60. than version
  61. --count <number>, include <number> entries from the top
  62. -c<number>, -n<number> (or the tail if <number> is lower than 0)
  63. --offset <number>, change the starting point for --count,
  64. -o<number> counted from the top (or the tail if
  65. <number> is lower than 0)
  66. --all include all changes
  67. "), $Dpkg::PROGNAME;
  68. }
  69. while (@ARGV) {
  70. last unless $ARGV[0] =~ m/^-/;
  71. $_ = shift(@ARGV);
  72. if (m/^-L(.+)$/) {
  73. $options{libdir} = $1;
  74. } elsif (m/^-F([0-9a-z]+)$/) {
  75. $options{changelogformat} = $1;
  76. } elsif (m/^-l(.+)$/) {
  77. $options{file} = $1;
  78. } elsif (m/^-S(.+)$/) {
  79. $fieldname = $1;
  80. } elsif (m/^--show-field(?:=(.+))?$/) {
  81. $fieldname = $1 // shift(@ARGV);
  82. } elsif (m/^--$/) {
  83. last;
  84. } elsif (m/^-([cfnostuv])(.*)$/) {
  85. if (($1 eq 'c') or ($1 eq 'n')) {
  86. $options{count} = $2;
  87. } elsif ($1 eq 'f') {
  88. $options{from} = $2;
  89. } elsif ($1 eq 'o') {
  90. $options{offset} = $2;
  91. } elsif (($1 eq 's') or ($1 eq 'v')) {
  92. $options{since} = $2;
  93. } elsif ($1 eq 't') {
  94. $options{to} = $2;
  95. } elsif ($1 eq 'u') {
  96. ## no critic (ControlStructures::ProhibitUntilBlocks)
  97. $options{until} = $2;
  98. ## use critic
  99. }
  100. } elsif (m/^--(count|file|format|from|offset|since|to|until)(.*)$/) {
  101. if ($2) {
  102. $options{$1} = $2;
  103. } else {
  104. $options{$1} = shift(@ARGV);
  105. }
  106. } elsif (m/^--all$/) {
  107. $options{all} = undef;
  108. } elsif (m/^-(\?|-help)$/) {
  109. usage(); exit(0);
  110. } elsif (m/^--version$/) {
  111. version(); exit(0);
  112. } else {
  113. usageerr(_g("unknown option \`%s'"), $_);
  114. }
  115. }
  116. usageerr(_g('takes no non-option arguments')) if @ARGV;
  117. my $count = 0;
  118. my @fields = changelog_parse(%options);
  119. foreach my $f (@fields) {
  120. print "\n" if $count++;
  121. if ($fieldname) {
  122. print $f->{$fieldname} . "\n";
  123. } else {
  124. print $f->output();
  125. }
  126. }