#!/usr/bin/perl -s use XML::DT ; use utf8::all; use Text::Wrap; our( $o ); my $filename = shift or die "usage: $0 [-o=file.dici] file.tbx\n"; $o ||= "$filename.dici"; $o =~ s/\.tbx\.dici/.dici/i; my %lang; my $len=80; $Text::Wrap::columns=80; %handler=( -begin => sub{ open(F,">",$o) or die("cant create $0\n"); print F "#", ("-" x $len), "\n"; ## to be rewritten with languages (in -end) }, -type => {termGrp => "SEQ", langSet => "SEQ", descriptGrp => "SEQ", sourceDesc => "SEQ", tig => "SEQ", ntig => "SEQ", termEntry => "SEQ", }, # '-default' => sub{"<$q>$c"}, 'body' => sub{ }, # 1 occurrences; 'admin' => sub{"admin-$v{type} = ".wrap(""," ",$c)."\n" }, # att: type 'note' => sub{"note = ".wrap(""," ",$c)."\n" }, # att: type 'descrip' => sub{"$v{type} =".wrap(""," ",$c)."\n" }, # att: type 'descripGrp' => sub{ join("",@$c) }, # 10977 occurrences; 'fileDesc' => sub{$c }, # 1 occurrences; # 'langSet' => sub{ "#$v{'xml:lang'}\n$c" }, # 21954 occurrences; attributes: xml:lang 'langSet' => sub{ $lang{$v{'xml:lang'}}++; join("",@$c) }, # att: xml:lang # 'martif' => sub{ }, # 1 occurrences; attributes: type, xml:lang 'martifHeader' => sub{ print F "\%desc ", wrap(""," ",$c), "\n\n" }, # 1 occurrences; 'ntig' => sub{ join("",@$c) }, # 22052 occurrences; 'p' => sub{ $c }, # 1 occurrences; 'sourceDesc' => sub{join("",@$c) }, # 1 occurrences; 'term' => sub{ lang() ." = $c\n". id($v{id}) }, # attributes: id 'termEntry' => sub{print F "\nID = $v{id}\n". join("",@$c) }, # att: id 'termNote' => sub{"+$v{type} = $c\n" }, # 341 occurrences; att: type 'termGrp' => sub{ join("",@$c) }, # 22052 occurrences; 'text' => sub{ }, # 1 occurrences; 'tig' => sub{ join("",@$c) }, # 22052 occurrences; 'title' => sub{ }, # 1 occurrences; 'hi' => sub{ if($v{rend} eq "termRef"){"[$c]"} else {"[$v{rend}=$c]"} }, # att= 'titleStmt' => sub{ }, # 1 occurrences; -end => sub{ close(F); open(F,"+<",$o) or die("cant reopen $0\n"); print F "\%lang "; for(sort keys %lang){ print F "$_ "} print F "\n#"; close F; } ); dt($filename,%handler); sub id{ if($_[0]){ "+id = $_[0]\n" } else {""} } sub lang{ ggfather()->{"xml:lang"} || ggfather()->{"lang"} || gfather()->{"xml:lang"} || gfather()->{"lang"} || "??" } __END__