dpkg-parsechangelog.pl 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. -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>
  51. set output format (defaults to 'dpkg').
  52. --all include all changes.
  53. -s, --since <version> include all changes later than <version>.
  54. -v <version> ditto.
  55. -u, --until <version> include all changes earlier than <version>.
  56. -f, --from <version> include all changes equal or later than <version>.
  57. -t, --to <version> include all changes up to or equal than <version>.
  58. -c, --count <number> include <number> entries from the top (or tail
  59. if <number> is lower than 0).
  60. -n <number> ditto.
  61. -o, --offset <number> change starting point for --count, counted from
  62. the top (or tail if <number> is lower than 0).
  63. "), $Dpkg::PROGNAME;
  64. }
  65. @ARGV = normalize_options(@ARGV);
  66. while (@ARGV) {
  67. last unless $ARGV[0] =~ m/^-/;
  68. my $arg = shift;
  69. if ($arg eq '--') {
  70. last;
  71. } elsif ($arg eq '-L') {
  72. warning(g_('-L is obsolete; it is without effect'));
  73. } elsif ($arg eq '-F') {
  74. $options{changelogformat} = shift;
  75. usageerr(g_('bad changelog format name'))
  76. unless length $options{changelogformat} and
  77. $options{changelogformat} =~ m/^([0-9a-z]+)$/;
  78. } elsif ($arg eq '--format') {
  79. $options{format} = shift;
  80. } elsif ($arg eq '-l' or $arg eq '--file') {
  81. $options{file} = shift;
  82. usageerr(g_('missing changelog filename'))
  83. unless length $options{file};
  84. } elsif ($arg eq '-S' or $arg eq '--show-field') {
  85. $fieldname = shift;
  86. } elsif ($arg eq '-c' or $arg eq '--count' or $arg eq '-n') {
  87. $options{count} = shift;
  88. } elsif ($arg eq '-f' or $arg eq '--from') {
  89. $options{from} = shift;
  90. } elsif ($arg eq '-o' or $arg eq '--offset') {
  91. $options{offset} = shift;
  92. } elsif ($arg eq '-s' or $arg eq '--since' or $arg eq '-v') {
  93. $options{since} = shift;
  94. } elsif ($arg eq '-t' or $arg eq '--to') {
  95. $options{to} = shift;
  96. } elsif ($arg eq '-u' or $arg eq '--until') {
  97. ## no critic (ControlStructures::ProhibitUntilBlocks)
  98. $options{until} = shift;
  99. ## use critic
  100. } elsif ($arg eq '--all') {
  101. $options{all} = undef;
  102. } elsif ($arg eq '-?' or $arg eq '--help') {
  103. usage(); exit(0);
  104. } elsif ($arg eq '--version') {
  105. version(); exit(0);
  106. } else {
  107. usageerr(g_("unknown option '%s'"), $arg);
  108. }
  109. }
  110. usageerr(g_('takes no non-option arguments')) if @ARGV;
  111. my $count = 0;
  112. my @fields = changelog_parse(%options);
  113. foreach my $f (@fields) {
  114. print "\n" if $count++;
  115. if ($fieldname) {
  116. print $f->{$fieldname} . "\n" if exists $f->{$fieldname};
  117. } else {
  118. print $f->output();
  119. }
  120. }