dpkg-parsechangelog.pl 3.7 KB

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