]> git.draconx.ca Git - gentoo-draconx.git/blob - app-text/mathml2/mathml2-20031021.ebuild
app-text/mathml2: Rewrite of mathml-xml-dtd.
[gentoo-draconx.git] / app-text / mathml2 / mathml2-20031021.ebuild
1 # Copyright © 2021 Nick Bowler
2 # License GPLv3+: GNU General Public License version 3 or any later version.
3 # This is free software: you are free to change and redistribute it.
4 # There is NO WARRANTY, to the extent permitted by law.
5
6 EAPI=7
7
8 inherit sgml-catalog-r1
9
10 DESCRIPTION="DTD and entity files for the Mathematical Markup Language 2.0"
11 HOMEPAGE="http://www.w3.org/TR/MathML2/"
12 SRC_URI="http://www.w3.org/Math/DTD/$PN.tgz -> $P.tar.gz"
13
14 LICENSE="W3C"
15 SLOT="0"
16 KEYWORDS="~amd64 ~x86"
17
18 BDEPEND="dev-libs/libxml2
19         virtual/awk"
20 RDEPEND="!app-text/mathml-xml-dtd"
21 DEPEND="$RDEPEND
22         app-text/sgml-common"
23
24 S=$WORKDIR/$PN
25
26 src_prepare () {
27         rm -f xhtml*.dtd
28         default
29 }
30
31 src_compile () {
32         cat >"$WORKDIR/gen-catalog.awk" <<-'EOF'
33                 BEGIN { print "OVERRIDE YES" }
34                 /^[[:space:]]*PUBLIC.*-\/\/W3C\/\// {
35                   pubid=$0
36                   sub(/^[[:space:]]*/, "", pubid);
37
38                   if (getline > 0) {
39                     file=substr($1, 2, length($1)-2)
40
41                     if (length(file) && getline < file > 0) {
42                       print pubid, "\"" file "\""
43                           print "SYSTEM", "\"http://www.w3.org/TR/MathML2/dtd/" file "\"", "\"" file "\""
44                           print "SYSTEM", "\"http://www.w3.org/Math/DTD/mathml2/" file "\"", "\"" file "\""
45                       close(file)
46                     }
47                   }
48                 }
49         EOF
50
51         ( set -x; awk -f "$WORKDIR/gen-catalog.awk" mathml2.dtd >catalog ) || die
52 }
53
54 src_install () {
55         declare -g pubmap=()
56
57         local insdir=/usr/share/sgml/$PN
58         local a b
59
60         insinto $insdir
61         doins -r catalog math* iso*
62
63         insinto /etc/sgml
64         printf 'CATALOG "%s"\n' "${EPREFIX%/}$insdir/catalog" | newins - $PN.cat
65
66         # Extract public identifiers from SGML catalog
67         exec 3<catalog
68         while read a b <&3; do
69                 case $a in
70                 PUBLIC)
71                         save_IFS=$IFS
72                         IFS=\"; set x $b; shift
73                         IFS=$save_IFS
74
75                         pubmap+=("$2" "${EPREFIX%/}$4")
76                 esac
77         done
78         exec 3<&-
79 }
80
81 update_catalog () {
82         local insdir="file://${EPREFIX%/}/usr/share/sgml/$PN"
83         local xmlcatalog="${BROOT%/}/usr/bin/xmlcatalog"
84         local systemuri=("http://www.w3.org/TR/MathML2/dtd" "http://www.w3.org/Math/DTD/mathml2")
85         local x mode=$1 args=()
86
87         command -v "$xmlcatalog" >/dev/null || die
88
89         set x "${pubmap[@]}"; shift
90         while test $# -gt 0; do
91                 case $mode in
92                 --add) args+=( --add public "$1" "$insdir/$2" ) ;;
93                 --del) args+=( --del "$1" ) ;;
94                 esac
95                 shift 2
96         done
97
98         for x in "${systemuri[@]}"; do
99                 case $mode in
100                 --add) args+=( --add rewriteSystem "$x" "$insdir"
101                                --add rewriteURI "$x" "$insdir" ) ;;
102                 --del) args+=( --del "$x" ) ;;
103                 esac
104         done
105
106         xmlcatalog --noout "${args[@]}" "${EROOT%/}/etc/xml/catalog"
107 }
108
109 pkg_postinst () {
110         sgml-catalog-r1_pkg_postinst
111
112         einfo "Adding $P to global XML catalog"
113         update_catalog --add
114 }
115
116 pkg_postrm () {
117         sgml-catalog-r1_pkg_postrm
118
119         einfo "Removing $P from global XML catalog"
120         update_catalog --del
121 }