debian.pl 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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;
  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. --label, -l <file> name of the changelog file to
  29. use in error messages
  30. --file <file> changelog file to parse, defaults
  31. to '-' (standard input)
  32. --format <outputformat> see man page for list of available
  33. output formats, defaults to 'dpkg'
  34. for compatibility with dpkg-dev
  35. --since, -s, -v <version> include all changes later than version
  36. --until, -u <version> include all changes earlier than version
  37. --from, -f <version> include all changes equal or later
  38. than version
  39. --to, -t <version> include all changes up to or equal
  40. than version
  41. --count, -c, -n <number> include <number> entries from the top
  42. (or the tail if <number> is lower than 0)
  43. --offset, -o <number> change the starting point for --count,
  44. counted from the top (or the tail if
  45. <number> is lower than 0)
  46. --all include all changes
  47. "), $progname;
  48. }
  49. my ( $since, $until, $from, $to, $all, $count, $offset, $file, $label );
  50. my $default_file = '-';
  51. my $format = 'dpkg';
  52. my %allowed_formats = (
  53. dpkg => 1,
  54. rfc822 => 1,
  55. );
  56. sub set_format {
  57. my ($opt, $val) = @_;
  58. unless ($allowed_formats{$val}) {
  59. usageerr(_g('output format %s not supported'), $val );
  60. }
  61. $format = $val;
  62. }
  63. GetOptions( "file=s" => \$file,
  64. "label|l=s" => \$label,
  65. "since|v=s" => \$since,
  66. "until|u=s" => \$until,
  67. "from|f=s" => \$from,
  68. "to|t=s" => \$to,
  69. "count|c|n=i" => \$count,
  70. "offset|o=i" => \$offset,
  71. "help|h" => sub{usage();exit(0)},
  72. "version|V" => sub{version();exit(0)},
  73. "format=s" => \&set_format,
  74. "all|a" => \$all,
  75. )
  76. or do { usage(); exit(2) };
  77. usageerr('too many arguments') if @ARGV > 1;
  78. if (@ARGV) {
  79. if ($file && ($file ne $ARGV[0])) {
  80. usageerr(_g('more than one file specified (%s and %s)'),
  81. $file, $ARGV[0] );
  82. }
  83. $file = $ARGV[0];
  84. }
  85. my $changes = Dpkg::Changelog::Debian->init();
  86. $file ||= $default_file;
  87. $label ||= $file;
  88. unless ($since or $until or $from or $to or
  89. $offset or $count or $all) {
  90. $count = 1;
  91. }
  92. my @all = $all ? ( all => $all ) : ();
  93. my $opts = { since => $since, until => $until,
  94. from => $from, to => $to,
  95. count => $count, offset => $offset,
  96. @all, reportfile => $label };
  97. if ($file eq '-') {
  98. $changes->parse({ inhandle => \*STDIN, %$opts })
  99. or failure(_g('fatal error occured while parsing input'));
  100. } else {
  101. $changes->parse({ infile => $file, %$opts })
  102. or failure(_g('fatal error occured while parsing %s'),
  103. $file );
  104. }
  105. eval("print \$changes->${format}_str(\$opts)");
  106. if ($@) {
  107. failure("%s",$@);
  108. }