+ my $start_t = time();
+ sub progress {
+ return if (! $show_progress);
+ my $current = shift;
+ my $total = shift || 1;
+ my $p = int($current * 100 / $total);
+ if ($p < $last_p || $current == 1) {
+ $start_t = time();
+ $last_p = 0;
+ } elsif ($p != $last_p) {
+ my $rate = ($current / (time() - $start_t || 1));
+ my $eta = ($total-$current) / ($rate || 1);
+ printf STDERR ("%5d [%-38s] %-5d %0.1f/s %s\r",$current,"=" x ($p/3)."$p%>", $total, $rate, fmt_time($eta));
+ $last_p = $p;
+ }
+ }
+
+ my $fake_dir = 1;
+ my $fake_pos = 0;
+ my $last_fake_t = time();
+ sub fakeprogress {
+ return if (! $show_progress);
+ my $current = shift @_;
+
+ my @ind = ('-','\\','|','/','-','\\','|','/');
+
+ if ($current < $fake_pos) {
+ $start_t = time();
+ $last_fake_t = 0;
+ $fake_dir = 1;
+ $fake_pos = 0;
+ }
+
+ if (time()-$last_fake_t >= 1) {
+ $last_fake_t = time();
+ $fake_pos += $fake_dir;
+ $fake_dir = -$fake_dir if ($fake_pos > 38);
+ }
+
+ if ($current % 10 == 0) {
+ my $rate = ($current / (time() - $start_t || 1));
+ printf STDERR ("%5d [%-38s] %0.1f/s\r",$current, " " x $fake_pos .$ind[($current / 10) % 8], $rate);
+ }
+ }
+
+ # now read database
+print STDERR "using: $type...\n";
+
+ # erase cache for tags by order in this database
+ delete $cache->{tags_by_order};
+
+ if ($type_base eq "isis") {
+
+ my $isis_db = $cfg -> val($database, 'isis_db') || die "$database doesn't have 'isis_db' defined!";
+
+ $import2cp = Text::Iconv->new($config->{isis_codepage},$codepage);
+ my $db = new Biblio::Isis( isisdb => $isis_db );
+
+ my $max_rowid = $db->count || die "can't find maxmfn";
+
+ print STDERR "Reading database: $isis_db [$max_rowid rows]\n";
+
+ $path = $database;
+
+ for (my $row_id = 1; $row_id <= $max_rowid; $row_id++ ) {
+ my $row = $db->to_hash( $row_id );
+ if ($row) {
+
+ $row->{mfn} = $row_id;
+ $row->{record} = $db->{record};
+
+ progress($row->{mfn}, $max_rowid);
+
+ my $swishpath = $path."#".int($row->{mfn});
+
+ if (my $xml = data2xml($type_base,$row,$add_xml,$cfg,$database)) {
+ $xml = $cp2utf->convert($xml);
+ use bytes; # as opposed to chars
+ print "Path-Name: $swishpath\n";
+ print "Content-Length: ".(length($xml)+1)."\n";
+ print "Document-Type: XML\n\n$xml\n";
+ }
+ }
+ }
+ print STDERR "\n";
+
+ } elsif ($type_base eq "excel") {
+ require Spreadsheet::ParseExcel;
+ require Spreadsheet::ParseExcel::Utility;
+ import Spreadsheet::ParseExcel::Utility qw(int2col);
+
+ $import2cp = Text::Iconv->new($config->{excel_codepage},$codepage);
+ my $excel_file = $cfg -> val($database, 'excel_file') || die "$database doesn't have 'excel_file' defined!";
+
+ my $sheet = x($config->{sheet}) || die "no sheet in $type.xml";
+ my $start_row = x($config->{start_row}) - 1 || die "no start_row in $type.xml";
+
+ my $oBook = Spreadsheet::ParseExcel::Workbook->Parse($excel_file) || die "can't open Excel file '$excel_file'";
+
+ my $sheet_nr = 0;
+ foreach my $oWks (@{$oBook->{Worksheet}}) {
+ #print STDERR "-- SHEET $sheet_nr:", $oWks->{Name}, "\n";
+ last if ($oWks->{Name} eq $sheet);
+ $sheet_nr++;
+ }