#!/usr/bin/perl
#
# zinc.pl by Davide Libenzi ( generates XMail delivery tables )
# Copyright (C) 2002  Davide Libenzi
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
# Davide Libenzi <davidel@xmailserver.org>
# Beau E. Cox <beau@beaucox.com>
# Thomas Loo <loo@saltstorm.net>
#

use strict;
use warnings;


if ($#ARGV < 2) {
    printf("[%s] generates XMail's delivery tables\n\n", $0);
    printf("use: %s  init_delay(-Qt)  delay_incr(-Qi)  num_retries(-Qr)\n\n", $0);
    exit 1;
}
 
my($c, $t, $i, $n, $tot, $ststr, $ntstr);
$t = int $ARGV[0];
$i = int $ARGV[1];
$n = int $ARGV[2];
$tot = 0;
 
for ($c = 1; $c <= $n; $c++) {
    sectime($tot, \$ststr);
    sectime($t, \$ntstr);

    printf("%02u\tsend-time = %-6u (%s)\tnext-try = %-6u (%s)\n",
           $c, $tot, $ststr, $t, $ntstr);
 
    $tot += $t;
    if ($i != 0) {
        $t += $t / $i;
    }
}

exit 0;


sub sectime {
	my ($secs, $tstr) = @_;
	my ($hh, $mm);

    $hh = int $secs / 3600;
    $secs -= $hh * 3600;
    $mm = int $secs / 60;
    $secs -= $mm * 60;
    $$tstr = sprintf("%02d:%02d:%02d", $hh, $mm, $secs);
}

