dpkg-parsechangelog.pl 4.0 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 <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"), $progname, $version;
  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. "), $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|-show-field)(?:=(.+))?$/) {
  79. $fieldname = $1 // shift(@ARGV);
  80. } elsif (m/^--$/) {
  81. last;
  82. } elsif (m/^-([cfnostuv])(.*)$/) {
  83. if (($1 eq "c") or ($1 eq "n")) {
  84. $options{"count"} = $2;
  85. } elsif ($1 eq "f") {
  86. $options{"from"} = $2;
  87. } elsif ($1 eq "o") {
  88. $options{"offset"} = $2;
  89. } elsif (($1 eq "s") or ($1 eq "v")) {
  90. $options{"since"} = $2;
  91. } elsif ($1 eq "t") {
  92. $options{"to"} = $2;
  93. } elsif ($1 eq "u") {
  94. $options{"until"} = $2;
  95. }
  96. } elsif (m/^--(count|file|format|from|offset|since|to|until)(.*)$/) {
  97. if ($2) {
  98. $options{$1} = $2;
  99. } else {
  100. $options{$1} = shift(@ARGV);
  101. }
  102. } elsif (m/^--all$/) {
  103. $options{"all"} = undef;
  104. } elsif (m/^-(\?|-help)$/) {
  105. usage(); exit(0);
  106. } elsif (m/^--version$/) {
  107. version(); exit(0);
  108. } else {
  109. usageerr(_g("unknown option \`%s'"), $_);
  110. }
  111. }
  112. @ARGV && usageerr(_g("takes no non-option arguments"));
  113. my $count = 0;
  114. my @fields = changelog_parse(%options);
  115. foreach my $f (@fields) {
  116. print "\n" if $count++;
  117. if ($fieldname) {
  118. print $f->{$fieldname} . "\n";
  119. } else {
  120. print $f->output();
  121. }
  122. }