dpkg-parsechangelog.pl 3.7 KB

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