#! /usr/bin/perl
use warnings;
use strict;
use integer;
use FindBin;

# This development helper script, added February 2005, works around
# Debian bug #284271 against ftp.debian.org.  It corrects the Priority
# listing of the debram's own binary packages from "ext" to "opt" in
# debram.txt.
#
# After #284271 is resolved, this script will no longer be needed and
# can safely be removed from the source.
#
#

our $width_0    = 18; # the width of the text preceding the Priority.
our $pri0       = 'ext';
our $pri1       = 'opt';
our $debram_txt = "${FindBin::RealBin}/../debram.txt";
our %binary     = map {$_=>1} qw(
  debram
  debram-data
);

my $width_pri   = length($pri0);

open DT, '<', $debram_txt;
my @dt = <DT>;
close DT;
for ( @dt ) {
  my( $t0, $pri, $t1, $package, $t2 ) =
    /^(.{$width_0})(.{$width_pri})( \267 )(\S+)(.*)$/o
    or next;
  defined $binary{$package} or next;
  $binary{$package} == 1
    or die "$0: package $package is listed twice\n";
  $binary{$package} = 0;
  $pri eq $pri0
    or die "$0: package $package already has Priority \"$pri\"\n";
  $_ = "$t0$pri1$t1$package$t2\n";
}
open DT, '>', $debram_txt;
print DT @dt;
close DT;

