--- trunk2/lib/WebPAC.pm 2004/07/07 21:41:50 388 +++ trunk2/lib/WebPAC.pm 2004/07/20 17:15:48 389 @@ -198,9 +198,12 @@ my $rec = $self->{'data'}->{$mfn}; $self->create_lookup($rec, @{$arg->{'lookup'}}); + $self->progress_bar($mfn,$maxmfn); + } $self->{'current_mfn'} = 1; + $self->{'last_pcnt'} = 0; # store max mfn and return it. return $self->{'max_mfn'} = $maxmfn; @@ -228,9 +231,45 @@ return; } + $self->progress_bar($mfn,$self->{'max_mfn'}); + return $self->{'data'}->{$mfn}; } +=head2 progress_bar + +Draw progress bar on STDERR. + + $webpac->progress_bar($current, $max); + +=cut + +sub progress_bar { + my $self = shift; + + my ($curr,$max) = @_; + + my $log = $self->_get_logger(); + + $log->logconfess("no current value!") if (! $curr); + $log->logconfess("no maximum value!") if (! $max); + + if ($curr > $max) { + $max = $curr; + $log->debug("overflow to $curr"); + } + + $self->{'last_pcnt'} ||= 1; + + $self->{'last_pcnt'} = $curr if ($curr < $self->{'last_pcnt'}); + + my $p = int($curr * 100 / $max); + if ($p != $self->{'last_pcnt'}) { + printf STDERR ("%5d / %5d [%-51s] %-2d %% \r",$curr,$max,"=" x ($p/2).">", $p ); + $self->{'last_pcnt'} = $p; + } +} + =head2 open_import_xml Read file from C directory and parse it. @@ -335,6 +374,7 @@ if ($$rec->{$f}) { return '' if (! $$rec->{$f}->[$i]); + no strict 'refs'; if ($sf && $$rec->{$f}->[$i]->{$sf}) { $$found++ if (defined($$found)); return $$rec->{$f}->[$i]->{$sf};