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.
8 inherit sgml-catalog-r1
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"
16 KEYWORDS="~amd64 ~x86"
18 BDEPEND="dev-libs/libxml2
20 RDEPEND="!app-text/mathml-xml-dtd"
32 cat >"$WORKDIR/gen-catalog.awk" <<-'EOF'
33 BEGIN { print "OVERRIDE YES" }
34 /^[[:space:]]*PUBLIC.*-\/\/W3C\/\// {
36 sub(/^[[:space:]]*/, "", pubid);
39 file=substr($1, 2, length($1)-2)
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 "\""
51 ( set -x; awk -f "$WORKDIR/gen-catalog.awk" mathml2.dtd >catalog ) || die
57 local insdir=/usr/share/sgml/$PN
61 doins -r catalog math* iso*
64 printf 'CATALOG "%s"\n' "${EPREFIX%/}$insdir/catalog" | newins - $PN.cat
66 # Extract public identifiers from SGML catalog
68 while read a b <&3; do
72 IFS=\"; set x $b; shift
75 pubmap+=("$2" "${EPREFIX%/}$4")
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=()
87 command -v "$xmlcatalog" >/dev/null || die
89 set x "${pubmap[@]}"; shift
90 while test $# -gt 0; do
92 --add) args+=( --add public "$1" "$insdir/$2" ) ;;
93 --del) args+=( --del "$1" ) ;;
98 for x in "${systemuri[@]}"; do
100 --add) args+=( --add rewriteSystem "$x" "$insdir"
101 --add rewriteURI "$x" "$insdir" ) ;;
102 --del) args+=( --del "$x" ) ;;
106 xmlcatalog --noout "${args[@]}" "${EROOT%/}/etc/xml/catalog"
110 sgml-catalog-r1_pkg_postinst
112 einfo "Adding $P to global XML catalog"
117 sgml-catalog-r1_pkg_postrm
119 einfo "Removing $P from global XML catalog"