debian.pl 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. use Getopt::Long qw(:config gnu_getopt auto_help);
  5. use POSIX;
  6. use Dpkg;
  7. use Dpkg::Gettext;
  8. use Dpkg::ErrorHandling qw(usageerr failure);
  9. use Dpkg::Changelog::Debian;
  10. textdomain("dpkg-dev");
  11. $progname = "parsechangelog/$progname";
  12. sub version {
  13. printf _g("Debian %s version %s.\n"), $progname, $version;
  14. printf _g("
  15. Copyright (C) 1996 Ian Jackson.
  16. Copyright (C) 2005,2007 Frank Lichtenheld.");
  17. printf _g("
  18. This is free software; see the GNU General Public Licence version 2 or
  19. later for copying conditions. There is NO warranty.
  20. ");
  21. }
  22. sub usage {
  23. printf _g(
  24. "Usage: %s [<option>...] [<changelogfile>]
  25. Options:
  26. --help, -h print usage information
  27. --version, -V print version information
  28. --file, -l <file> changelog file to parse, defaults
  29. to 'debian/changelog'
  30. --format <outputformat> see man page for list of available
  31. output formats, defaults to 'dpkg'
  32. for compatibility with dpkg-dev
  33. --since, -s, -v <version> include all changes later than version
  34. --until, -u <version> include all changes earlier than version
  35. --from, -f <version> include all changes equal or later
  36. than version
  37. --to, -t <version> include all changes up to or equal
  38. than version
  39. --count, -c, -n <number> include <number> entries from the top
  40. (or the tail if <number> is lower than 0)
  41. --offset, -o <number> change the starting point for --count,
  42. counted from the top (or the tail if
  43. <number> is lower than 0)
  44. --all include all changes
  45. "), $progname;
  46. }
  47. my ( $since, $until, $from, $to, $all, $count, $offset, $file );
  48. my $default_file = 'debian/changelog';
  49. my $format = 'dpkg';
  50. my %allowed_formats = (
  51. dpkg => 1,
  52. rfc822 => 1,
  53. );
  54. sub set_format {
  55. my ($opt, $val) = @_;
  56. unless ($allowed_formats{$val}) {
  57. usageerr(_g('output format %s not supported'), $val );
  58. }
  59. $format = $val;
  60. }
  61. GetOptions( "file|l=s" => \$file,
  62. "since|v=s" => \$since,
  63. "until|u=s" => \$until,
  64. "from|f=s" => \$from,
  65. "to|t=s" => \$to,
  66. "count|c|n=i" => \$count,
  67. "offset|o=i" => \$offset,
  68. "help|h" => sub{usage();exit(0)},
  69. "version|V" => sub{version();exit(0)},
  70. "format=s" => \&set_format,
  71. "all|a" => \$all,
  72. )
  73. or do { usage(); exit(2) };
  74. usageerr('too many arguments') if @ARGV > 1;
  75. if (@ARGV) {
  76. if ($file && ($file ne $ARGV[0])) {
  77. usageerr(_g('more than one file specified (%s and %s)'),
  78. $file, $ARGV[0] );
  79. }
  80. $file = $ARGV[0];
  81. }
  82. my $changes = Dpkg::Changelog::Debian->init();
  83. $file ||= $default_file;
  84. unless ($since or $until or $from or $to or
  85. $offset or $count or $all) {
  86. $count = 1;
  87. }
  88. my @all = $all ? ( all => $all ) : ();
  89. my $opts = { since => $since, until => $until,
  90. from => $from, to => $to,
  91. count => $count, offset => $offset,
  92. @all };
  93. if ($file eq '-') {
  94. my @input = <STDIN>;
  95. $changes->parse({ instring => join('', @input), %$opts })
  96. or failure(_g('fatal error occured while parsing input'));
  97. } else {
  98. $changes->parse({ infile => $file, %$opts })
  99. or failure(_g('fatal error occured while parsing %s'),
  100. $file );
  101. }
  102. eval("print \$changes->${format}_str(\$opts)");