+ sub progress {
+ return if (! $show_progress);
+ my $current = shift;
+ my $total = shift || 1;
+ my $p = int($current * 100 / $total);
+ if ($p != $last_p) {
+ printf STDERR ("%5d / %5d [%-51s] %-2d %% \r",$current,$total,"=" x ($p/2).">", $p );
+ $last_p = $p;
+ }
+ }
+
+ my $fake_dir = 1;
+ sub fakeprogress {
+ return if (! $show_progress);
+ my $current = shift @_;
+
+ my @ind = ('-','\\','|','/','-','\\','|','/', '-');
+
+ $last_p += $fake_dir;
+ $fake_dir = -$fake_dir if ($last_p > 1000 || $last_p < 0);
+ if ($last_p % 10 == 0) {
+ printf STDERR ("%5d / %5s [%-51s]\r",$current,"?"," " x ($last_p/20).$ind[($last_p/20) % $#ind]);
+ }
+ }
+
+ # 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 = OpenIsis::open( $isis_db );
+
+ # check if .txt database for OpenIsis is zero length,
+ # if so, erase it and re-open database
+ sub check_txt_db {
+ my $isis_db = shift || die "need isis database name";
+ my $reopen = 0;
+
+ if (-e $isis_db.".TXT") {
+ print STDERR "WARNING: removing $isis_db.TXT OpenIsis database...\n";
+ unlink $isis_db.".TXT" || warn "FATAL: unlink error on '$isis_db.TXT': $!";
+ $reopen++;
+ }
+ if (-e $isis_db.".PTR") {
+ print STDERR "WARNING: removing $isis_db.PTR OpenIsis database...\n";
+ unlink $isis_db.".PTR" || warn "FATAL: unlink error on '$isis_db.PTR': $!";
+ $reopen++;
+ }
+ return OpenIsis::open( $isis_db ) if ($reopen);
+ }
+
+ # EOF error
+ if ($db == -1) {
+ $db = check_txt_db($isis_db);
+ if ($db == -1) {
+ print STDERR "FATAL: OpenIsis can't open zero size file $isis_db\n";
+ next;
+ }
+ }
+
+ # OpenIsis::ERR_BADF
+ if ($db == -4) {
+ print STDERR "FATAL: OpenIsis can't find file $isis_db\n";
+ next;
+ # OpenIsis::ERR_IO
+ } elsif ($db == -5) {
+ print STDERR "FATAL: OpenIsis can't access file $isis_db\n";
+ next;
+ } elsif ($db < 0) {
+ print STDERR "FATAL: OpenIsis unknown error $db with file $isis_db\n";
+ next;
+ }
+
+ my $max_rowid = OpenIsis::maxRowid( $db );
+
+ # if 0 records, try to rease isis .txt database
+ if ($max_rowid == 0) {
+ # force removal of database
+ $db = check_txt_db($isis_db);
+ $max_rowid = OpenIsis::maxRowid( $db );
+ }
+
+ print STDERR "Reading database: $isis_db [$max_rowid rows]\n";
+
+ my $path = $database;
+
+ for (my $row_id = 1; $row_id <= $max_rowid; $row_id++ ) {
+ my $row = OpenIsis::read( $db, $row_id );
+ if ($row && $row->{mfn}) {
+
+ 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";
+ }
+ }
+ }
+ # for this to work with current version of OpenIsis (0.9.0)
+ # you might need my patch from
+ # http://www.rot13.org/~dpavlin/projects/openisis-0.9.0-perl_close.diff
+ OpenIsis::close($db);
+ 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++;
+ }