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