-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.xml
85 lines (72 loc) · 4.56 KB
/
build.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?xml version="1.0" encoding="UTF-8"?>
<project basedir="." name="CTE2TEI" default="TEI">
<target name="clean">
<delete dir="temp" />
</target>
<!-- RegEx replacements to create XML from CTE text file -->
<target name="basicXML" depends="clean">
<tempfile property="cte0" suffix=".xml" destdir="temp"/>
<copy file="${cte}" tofile="${cte0}">
<filterchain>
<fixcrlf />
</filterchain>
</copy>
<!-- < character must be replaced in all instances -->
<replaceregexp file="${cte0}" match="<" replace="&lt;" flags="g" />
<!-- general outline to create a wellformed XML -->
<replaceregexp file="${cte0}" match="^[^\{]*(.*)" replace="<cte>\1" flags="s" />
<replaceregexp file="${cte0}" match="[^\}]*$" replace="</cte>" flags="s" />
<!-- replace reserved and problematic characters -->
<replaceregexp file="${cte0}" match="\u0002" replace="_" flags="g" />
<replaceregexp file="${cte0}" match="\u001d" replace="_" flags="g" />
<replaceregexp file="${cte0}" match="\u001f" replace="_" flags="g" />
<replaceregexp file="${cte0}" match="&" replace="&amp;" flags="g" />
<!-- Replace special character combinations -->
<replaceregexp file="${cte0}" match="\^\-" replace="" flags="g" />
<replaceregexp file="${cte0}" match="\^\+" replace="­" flags="g" />
<replaceregexp file="${cte0}" match="\^\." replace=" " flags="g" />
<replaceregexp file="${cte0}" match="\^\_" replace=" " flags="g" />
<!-- Clean up prologue -->
<replaceregexp file="${cte0}" match="\\TemplateSpacing" replace="${line.separator}\\\\TemplateSpacing" flags="g" />
<replaceregexp file="${cte0}" match="\\User(\d+)" replace="${line.separator}\\\\User\1" flags="g" />
<replaceregexp file="${cte0}" match="\\FontUser(\d+)" replace="${line.separator}\\\\FontUser\1" flags="g" />
<replaceregexp file="${cte0}" match="\\User(\d+):([^,]+),(\d+)=(.+)"
replace="<pdef lfd="User\1" name="\2" n="\3" def="\4" />" flags="g" />
<replaceregexp file="${cte0}" match="\\FontUser(\d+):([^,]+),(\d+)=(.+)"
replace="<fdef lfd="FontUser\1" name="\2" n="\3" def="\4" />" flags="g" />
<replaceregexp file="${cte0}" match="name="\s+" replace="name="" flags="g" />
<replaceregexp file="${cte0}" match="SecondaryDocs=([^\\<]+)"
replace="<SecondaryDocs name="\1"/>" flags="g" />
<!-- newline serves as delimiter between blocks -->
<replaceregexp file="${cte0}" match="${line.separator}" replace="<end/>${line.separator}" flags="g" />
<!-- main outline -->
<replaceregexp file="${cte0}" match="\{(Description|Text|Notes\d|Apparatus\d|Fonts|Format|HeaderFooter)\\" replace="<\1>" flags="g" />
<replaceregexp file="${cte0}" match="\\(Description|Text|Notes\d|Apparatus\d|Fonts|Format|HeaderFooter)\}" replace="</\1>" flags="g" />
<!-- we must not create elements without a name -->
<replaceregexp file="${cte0}" match="\{ " replace="<Z>" flags="g" />
<replaceregexp file="${cte0}" match="\\ \}" replace="</Z>" flags="g" />
<replaceregexp file="${cte0}" match="\{Q\\" replace="<Qs/>" flags="g" />
<replaceregexp file="${cte0}" match="\\Q\}" replace="<Qe/>" flags="g" />
<!-- paragraph marker -->
<replaceregexp file="${cte0}" match="\{P\\([^\\]*)\\P\}" replace="<P vals="\1" />" flags="g"/>
<!-- other elements -->
<replaceregexp file="${cte0}" match="\{(.)([^\\]*)\\" replace="<\1 vals="\2">" flags="g" />
<replaceregexp file="${cte0}" match="\\(.)\}" replace="</\1>" flags="g" />
</target>
<!-- transform this to a (more or less) valid TEI that retains the info from CTE -->
<target name="TEI" depends="basicXML">
<tempfile property="cte1" suffix="-1.xml" destdir="temp"/>
<tempfile property="cte2" suffix="-2.xml" destdir="temp"/>
<tempfile property="cte3" suffix="-3.xml" destdir="temp"/>
<tempfile property="cte4" suffix="-4.xml" destdir="temp"/>
<tempfile property="cte5" suffix="-5.xml" destdir="temp"/>
<xslt in="${cte0}" style="cte0.xsl" out="${cte1}">
<param name="origFile" expression="${cte}"/>
</xslt>
<xslt in="${cte1}" style="cte1.xsl" out="${cte2}" />
<xslt in="${cte2}" style="cte2.xsl" out="${cte3}" />
<xslt in="${cte3}" style="cte3.xsl" out="${cte4}" />
<xslt in="${cte4}" style="cte4.xsl" out="${cte5}" />
<xslt in="${cte5}" style="cte5.xsl" out="${out}" />
</target>
</project>