128 |
my @index_data; |
my @index_data; |
129 |
my $index_filter; |
my $index_filter; |
130 |
|
|
131 |
|
sub mkformat { |
132 |
|
my $x = shift || die "mkformat needs tag reference"; |
133 |
|
my $data = shift || return; |
134 |
|
my $format_name = x($x->{format_name}) || return $data; |
135 |
|
my $fmt = x($config->{format}->{$format_name}->{content}) || die "<format name=\"$format_name\"> is not defined!"; |
136 |
|
my $format_delimiter = x($x->{format_delimiter}); |
137 |
|
my @data; |
138 |
|
if ($format_delimiter) { |
139 |
|
@data = split(/$format_delimiter/,$data); |
140 |
|
} else { |
141 |
|
push @data,$data; |
142 |
|
} |
143 |
|
|
144 |
|
if ($fmt) { |
145 |
|
my $nr = scalar $fmt =~ s/%s/%s/g; |
146 |
|
if (($#data+1) == $nr) { |
147 |
|
return sprintf($fmt,@data); |
148 |
|
} else { |
149 |
|
print STDERR "mkformat: [$data] can't be split on [$format_delimiter] to $nr fields!\n"; |
150 |
|
return $data; |
151 |
|
} |
152 |
|
} else { |
153 |
|
print STDERR "usage of link '$format_name' without defined format (<link> tag)\n"; |
154 |
|
} |
155 |
|
} |
156 |
|
|
157 |
# while because of repeatable fields |
# while because of repeatable fields |
158 |
while ($swish || $display) { |
while ($swish || $display) { |
159 |
($swish,$display) = parse_format($type, $format,$row,$repeat_off++,$import2cp); |
($swish,$display) = parse_format($type, $format,$row,$repeat_off++,$import2cp); |
186 |
} |
} |
187 |
if ($filter) { |
if ($filter) { |
188 |
no strict 'refs'; |
no strict 'refs'; |
189 |
$display_data .= join($delimiter,&$filter($display)); |
if ($display_data) { |
190 |
|
$display_data .= $delimiter.join($delimiter,mkformat($x,&$filter($display))); |
191 |
|
} else { |
192 |
|
$display_data = join($delimiter,mkformat($x,&$filter($display))); |
193 |
|
} |
194 |
} else { |
} else { |
195 |
if ($display_data) { |
if ($display_data) { |
196 |
$display_data .= $delimiter.$display; |
$display_data .= $delimiter.mkformat($x,$display); |
197 |
} else { |
} else { |
198 |
$display_data .= $display; |
$display_data = mkformat($x,$display); |
199 |
} |
} |
200 |
} |
} |
201 |
} |
} |
211 |
if (@index_data) { |
if (@index_data) { |
212 |
if ($index_filter) { |
if ($index_filter) { |
213 |
no strict 'refs'; |
no strict 'refs'; |
214 |
foreach my $d (&$index_filter(@index_data)) { |
foreach my $d (@index_data) { |
215 |
$index->insert($field, $d, $path); |
$index->insert($field, &$index_filter($d), $path); |
216 |
} |
} |
217 |
} else { |
} else { |
218 |
foreach my $d (@index_data) { |
foreach my $d (@index_data) { |
319 |
my $type_base = $type; |
my $type_base = $type; |
320 |
$type_base =~ s/_.+$//g; |
$type_base =~ s/_.+$//g; |
321 |
|
|
322 |
$config=XMLin("./import_xml/$type.xml", forcearray => [ $type2tag{$type_base}, 'config' ], forcecontent => 1); |
$config=XMLin("./import_xml/$type.xml", forcearray => [ $type2tag{$type_base}, 'config', 'format' ], forcecontent => 1); |
323 |
|
|
324 |
# output current progress indicator |
# output current progress indicator |
325 |
my $last_p = 0; |
my $last_p = 0; |
326 |
sub progress { |
sub progress { |
327 |
# XXX return if ($show_progress ne ""); |
return if (! $show_progress); |
328 |
my $current = shift; |
my $current = shift; |
329 |
my $total = shift || 1; |
my $total = shift || 1; |
330 |
my $p = int($current * 100 / $total); |
my $p = int($current * 100 / $total); |
336 |
|
|
337 |
my $fake_dir = 1; |
my $fake_dir = 1; |
338 |
sub fakeprogress { |
sub fakeprogress { |
339 |
|
return if (! $show_progress); |
340 |
my $current = shift @_; |
my $current = shift @_; |
341 |
|
|
342 |
my @ind = ('-','\\','|','/','-','\\','|','/', '-'); |
my @ind = ('-','\\','|','/','-','\\','|','/', '-'); |
358 |
$import2cp = Text::Iconv->new($config->{isis_codepage},$codepage); |
$import2cp = Text::Iconv->new($config->{isis_codepage},$codepage); |
359 |
my $db = OpenIsis::open( $isis_db ); |
my $db = OpenIsis::open( $isis_db ); |
360 |
|
|
361 |
|
# check if .txt database for OpenIsis is zero length, |
362 |
|
# if so, erase it and re-open database |
363 |
|
sub check_txt_db { |
364 |
|
my $isis_db = shift || die "need isis database name"; |
365 |
|
my $reopen = 0; |
366 |
|
|
367 |
|
if (-e $isis_db.".TXT") { |
368 |
|
print STDERR "WARNING: removing $isis_db.TXT OpenIsis database...\n"; |
369 |
|
unlink $isis_db.".TXT" || warn "FATAL: unlink error on '$isis_db.TXT': $!"; |
370 |
|
$reopen++; |
371 |
|
} |
372 |
|
if (-e $isis_db.".PTR") { |
373 |
|
print STDERR "WARNING: removing $isis_db.PTR OpenIsis database...\n"; |
374 |
|
unlink $isis_db.".PTR" || warn "FATAL: unlink error on '$isis_db.PTR': $!"; |
375 |
|
$reopen++; |
376 |
|
} |
377 |
|
return OpenIsis::open( $isis_db ) if ($reopen); |
378 |
|
} |
379 |
|
|
380 |
|
# EOF error |
381 |
|
if ($db == -1) { |
382 |
|
$db = check_txt_db($isis_db); |
383 |
|
if ($db == -1) { |
384 |
|
print STDERR "FATAL: OpenIsis can't open zero size file $isis_db\n"; |
385 |
|
next; |
386 |
|
} |
387 |
|
} |
388 |
|
|
389 |
|
# OpenIsis::ERR_BADF |
390 |
|
if ($db == -4) { |
391 |
|
print STDERR "FATAL: OpenIsis can't find file $isis_db\n"; |
392 |
|
next; |
393 |
|
# OpenIsis::ERR_IO |
394 |
|
} elsif ($db == -5) { |
395 |
|
print STDERR "FATAL: OpenIsis can't access file $isis_db\n"; |
396 |
|
next; |
397 |
|
} elsif ($db < 0) { |
398 |
|
print STDERR "FATAL: OpenIsis unknown error $db with file $isis_db\n"; |
399 |
|
next; |
400 |
|
} |
401 |
|
|
402 |
my $max_rowid = OpenIsis::maxRowid( $db ); |
my $max_rowid = OpenIsis::maxRowid( $db ); |
403 |
|
|
404 |
|
# if 0 records, try to rease isis .txt database |
405 |
|
if ($max_rowid == 0) { |
406 |
|
# force removal of database |
407 |
|
$db = check_txt_db($isis_db); |
408 |
|
$max_rowid = OpenIsis::maxRowid( $db ); |
409 |
|
} |
410 |
|
|
411 |
print STDERR "Reading database: $isis_db [$max_rowid rows]\n"; |
print STDERR "Reading database: $isis_db [$max_rowid rows]\n"; |
412 |
|
|
413 |
my $path = $database; |
my $path = $database; |
429 |
} |
} |
430 |
} |
} |
431 |
} |
} |
432 |
|
# for this to work with current version of OpenIsis (0.9.0) |
433 |
|
# you might need my patch from |
434 |
|
# http://www.rot13.org/~dpavlin/projects/openisis-0.9.0-perl_close.diff |
435 |
|
OpenIsis::close($db); |
436 |
print STDERR "\n"; |
print STDERR "\n"; |
437 |
|
|
438 |
} elsif ($type_base eq "excel") { |
} elsif ($type_base eq "excel") { |