| 1 |
#!/usr/bin/perl |
| 2 |
# |
| 3 |
|
| 4 |
# 2002 Michael Bunk <[email protected]> |
| 5 |
# only sgml tei! |
| 6 |
|
| 7 |
$hdfile = shift @ARGV; |
| 8 |
|
| 9 |
if ($hdfile eq "") { |
| 10 |
print stderr "Usage: hd2dict <hdfile>\n"; |
| 11 |
print stderr " To convert headword definition dict files to TEI format. Output\n"; |
| 12 |
print stderr " is on stdout.\n"; |
| 13 |
die; |
| 14 |
} |
| 15 |
|
| 16 |
die "Can't find file \"$hdfile\"" unless -f $hdfile; |
| 17 |
|
| 18 |
open(HDHANDLE, "<".$hdfile); |
| 19 |
|
| 20 |
while (<HDHANDLE>) { |
| 21 |
push(@zeilen,$_); |
| 22 |
} |
| 23 |
|
| 24 |
print "<!DOCTYPE TEI\.2 PUBLIC \"\-//TEI P3//DTD Main Document Type//EN\"\n"; |
| 25 |
print "\"/usr/share/sgml/tei-3/tei2\.dtd\" \[\n"; |
| 26 |
print " <!ENTITY % TEI\.dictionaries 'INCLUDE' > \]>\n"; |
| 27 |
print "<\?xml version='1\.0' encoding='ISO-8859-1'>\n"; |
| 28 |
print "<tei\.2>\n<teiheader>\n<filedesc>\n<titlestmt><title>".$hdfile."</title>\n"; |
| 29 |
print " <respStmt><resp>converted with</resp><name>hd2tei\.pl</name></respStmt>\n"; |
| 30 |
print " </titleStmt>\n<publicationStmt><p>freedict\.de\n"; |
| 31 |
|
| 32 |
# Statement aus Quelldatei uebernehmen (Zeilen vor dem ersten %h) |
| 33 |
for(@zeilen) { |
| 34 |
if (/^%h/) {last;}# Schleife abbrechen |
| 35 |
print $_; |
| 36 |
} |
| 37 |
|
| 38 |
print " </p></publicationStmt>\n<sourceDesc><p>".$hdfile."</p></sourceDesc></fileDesc></teiHeader>\n"; |
| 39 |
|
| 40 |
print "<text><body>\n"; |
| 41 |
|
| 42 |
$openentry = 0; |
| 43 |
|
| 44 |
for(@zeilen) { |
| 45 |
chop; |
| 46 |
if(/^%h/) { |
| 47 |
if ($openentry == 1) { |
| 48 |
print "</tr></trans></entry>\n"; |
| 49 |
$openentry = 0; |
| 50 |
} |
| 51 |
print "<entry><form><orth>".substr($_,3)."</orth></form>\n <trans><tr>"; |
| 52 |
next; |
| 53 |
}; |
| 54 |
if(/^%d/) { |
| 55 |
$openentry = 1; |
| 56 |
next; |
| 57 |
} |
| 58 |
if ($openentry == 1) { |
| 59 |
print $_;} |
| 60 |
else { print stderr "Unsinn: ".$_."\n";} |
| 61 |
} |
| 62 |
|
| 63 |
print "</body></text></tei.2>\n"; |
| 64 |
|
| 65 |
close(HDHANDLE); |
| 66 |
|