/[gentoo-src]/build-docbook-catalog/build-docbook-catalog
Gentoo

Contents of /build-docbook-catalog/build-docbook-catalog

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.6 - (hide annotations) (download)
Tue Mar 29 02:11:48 2011 UTC (3 years, 5 months ago) by flameeyes
Branch: MAIN
Changes since 1.5: +29 -3 lines
Add support for simple-dtds, thanks to Yaakov S in bug #290680.

1 agriffis 1.1 #!/bin/bash
2 flameeyes 1.6 # $Header: /var/cvsroot/gentoo-src/build-docbook-catalog/build-docbook-catalog,v 1.5 2009/08/23 16:06:03 flameeyes Exp $
3 agriffis 1.1 #
4     # build-docbook-catalog: populate /etc/xml/docbook based in
5     # installed docbook-xml-dtd versions.
6     #
7     # Copyright 2004 Gentoo Foundation
8     # Distributed under the terms of the GNU General Public License v2
9     # written by Aron Griffis
10     #
11    
12     ROOTCATALOG=/etc/xml/catalog
13     CATALOG=/etc/xml/docbook
14     DOCBOOKDIR=/usr/share/sgml/docbook
15     DTDS=
16     LATEST_DTD=
17     LATEST_DATE=
18 agriffis 1.2 VERBOSE=false
19     ZERO=${0##*/}
20 agriffis 1.1
21     #
22     # main (called from bottom)
23     #
24     main() {
25 agriffis 1.2 typeset d v opts
26    
27     opts=$(getopt -o v --long verbose -n "$ZERO" -- "$@") || exit 1
28     eval set -- "$opts"
29     while true; do
30     case "$1" in
31     -v|--verbose) VERBOSE=true ; shift ;;
32     --) shift ; break ;;
33     *) echo "Options parsing failed on $1!" >&2 ; exit 1 ;;
34     esac
35     done
36 agriffis 1.1
37     create_catalogs # will exit on error
38 flameeyes 1.3 for type in xsl xsl-ns xsl-saxon xsl-xalan; do
39     populate_xsl $type
40     done
41 agriffis 1.1
42     # Clean out old dtds from catalog
43 agriffis 1.2 verb "Cleaning out old DocBook XML versions from ${CATALOG} and ${ROOTCATALOG}"
44 flameeyes 1.6 clean_catalog "${DOCBOOKDIR}/xml\(-simple\)*-dtd-[^/\"']*/[^/\"']*" ${CATALOG}
45     clean_catalog "${DOCBOOKDIR}/xml\(-simple\)*-dtd-[^/\"']*/[^/\"']*" ${ROOTCATALOG}
46 agriffis 1.1
47     if set_dtds; then
48     for d in ${DTDS}; do
49     populate_dtd ${d}
50     done
51 flameeyes 1.6 for d in ${SIMPLE_DTDS}; do
52     populate_simple_dtd ${d}
53     done
54 agriffis 1.1 populate_entities
55     fi
56    
57     exit 0
58     }
59    
60 agriffis 1.2 #
61     # verbose echo -- only echo if called with --verbose
62     #
63     verb() {
64     $VERBOSE && echo "$*"
65     }
66    
67 agriffis 1.1 #
68     # fill in the DTDS variable based on installed versions
69     #
70     set_dtds() {
71     DTDS=$(find ${DOCBOOKDIR} -path '*/xml-dtd-*/docbookx.dtd')
72 flameeyes 1.6 SIMPLE_DTDS=$(find ${DOCBOOKDIR} -path '*/xml-simple-dtd-*/sdocbook.dtd')
73 agriffis 1.1 if [[ -z ${DTDS} ]]; then
74     echo "No installed DocBook XML DTDs found"
75     return 1
76     else
77     return 0
78     fi
79     }
80    
81     #
82     # create the catalogs root and docbook specific
83     #
84     create_catalogs() {
85     if [[ ! -r ${ROOTCATALOG} ]] ; then
86     echo "Creating XML Catalog root ${ROOTCATALOG}"
87     /usr/bin/xmlcatalog --noout --create ${ROOTCATALOG}
88     if [[ ! -r ${ROOTCATALOG} ]] ; then
89     echo "Failed creating ${ROOTCATALOG}, aborting" >&2
90     exit 1
91     fi
92     else
93 agriffis 1.2 verb "Found XML Catalog root ${ROOTCATALOG}"
94 agriffis 1.1 # clean out existing entries
95 agriffis 1.2 verb " Cleaning existing ${CATALOG} delegates from ${ROOTCATALOG}"
96 agriffis 1.1 clean_catalog "file://${CATALOG}" ${ROOTCATALOG}
97     fi
98    
99     if [[ ! -r ${CATALOG} ]] ; then
100     echo "Creating DocBook XML Catalog ${CATALOG}"
101     /usr/bin/xmlcatalog --noout --create ${CATALOG}
102     if [[ ! -r ${CATALOG} ]] ; then
103     echo "Failed creating ${CATALOG}, aborting" >&2
104     exit 1
105     fi
106     else
107 agriffis 1.2 verb "Found DocBook XML Catalog ${CATALOG}"
108 agriffis 1.1 fi
109    
110     # dtd pointers
111 agriffis 1.2 verb " Populating ${ROOTCATALOG} with DTD delegates to ${CATALOG}"
112 flameeyes 1.5 xmlcatalog --noout --add "delegatePublic" "-//OASIS//ENTITIES DocBook" "file://${CATALOG}" ${ROOTCATALOG}
113     xmlcatalog --noout --add "delegatePublic" "-//OASIS//ELEMENTS DocBook" "file://${CATALOG}" ${ROOTCATALOG}
114     xmlcatalog --noout --add "delegatePublic" "-//OASIS//DTD DocBook" "file://${CATALOG}" ${ROOTCATALOG}
115 agriffis 1.1 xmlcatalog --noout --add "delegateSystem" "http://www.oasis-open.org/docbook/" "file://${CATALOG}" ${ROOTCATALOG}
116     xmlcatalog --noout --add "delegateURI" "http://www.oasis-open.org/docbook/" "file://${CATALOG}" ${ROOTCATALOG}
117    
118     # entities pointer
119 agriffis 1.2 verb " Populating ${ROOTCATALOG} with ISO entities delegate to ${CATALOG}"
120 agriffis 1.1 xmlcatalog --noout --add "delegatePublic" "ISO 8879:1986" "file://${CATALOG}" ${ROOTCATALOG}
121     }
122    
123     #
124     # clean_catalog
125     # $1 == regex to clean
126     # $2 == catalog
127     #
128     clean_catalog() {
129     typeset list f regex=$1 catalog=$2
130    
131     list=$(egrep --only-matching "${regex}" "${catalog}" | sort -u)
132     for f in ${list}; do
133     xmlcatalog --noout --del "${f}" ${catalog}
134     done
135     }
136    
137     #
138     # populate a specific dtd version into the docbook catalog
139     # $1 == /path/to/docbookx.dtd
140     #
141     populate_dtd() {
142     typeset dtd=$1 docbookdir=${1%/*} dtd_date
143     typeset v=${docbookdir##*-}
144    
145     # sanity check
146     if [[ ${dtd} != */xml-dtd-*/* ]]; then
147     echo "Warning: I don't understand \"${dtd}\"" >&2
148     return
149     fi
150     echo "Found DocBook XML ${v} in ${docbookdir}"
151    
152     # Populate the docbook catalog with this version
153 agriffis 1.2 verb " Populating ${CATALOG} based on ${docbookdir}"
154 agriffis 1.1 xmlcatalog --noout --add "public" "-//OASIS//ELEMENTS DocBook XML Information Pool V${v}//EN" "file://${docbookdir}/dbpoolx.mod" ${CATALOG}
155     xmlcatalog --noout --add "public" "-//OASIS//DTD DocBook XML V${v}//EN" "file://${docbookdir}/docbookx.dtd" ${CATALOG}
156     xmlcatalog --noout --add "public" "-//OASIS//ENTITIES DocBook XML Character Entities V${v}//EN" "file://${docbookdir}/dbcentx.mod" ${CATALOG}
157     xmlcatalog --noout --add "public" "-//OASIS//ENTITIES DocBook XML Notations V${v}//EN" "file://${docbookdir}/dbnotnx.mod" ${CATALOG}
158     xmlcatalog --noout --add "public" "-//OASIS//ENTITIES DocBook XML Additional General Entities V${v}//EN" "file://${docbookdir}/dbgenent.mod" ${CATALOG}
159     xmlcatalog --noout --add "public" "-//OASIS//ELEMENTS DocBook XML Document Hierarchy V${v}//EN" "file://${docbookdir}/dbhierx.mod" ${CATALOG}
160     xmlcatalog --noout --add "public" "-//OASIS//DTD XML Exchange Table Model 19990315//EN" "file://${docbookdir}/soextblx.dtd" ${CATALOG}
161     xmlcatalog --noout --add "public" "-//OASIS//DTD DocBook XML CALS Table Model V${v}//EN" "file://${docbookdir}/calstblx.dtd" ${CATALOG}
162     xmlcatalog --noout --add "rewriteSystem" "http://www.oasis-open.org/docbook/xml/${v}" "file://${docbookdir}" ${CATALOG}
163     xmlcatalog --noout --add "rewriteURI" "http://www.oasis-open.org/docbook/xml/${v}" "file://${docbookdir}" ${CATALOG}
164    
165     # grab the RCS date from docbookx.dtd for comparison purposes
166     if [[ ! -f ${docbookdir}/ent/iso-lat1.ent ]]; then
167 agriffis 1.2 verb " No entities available for ${dtd}"
168 agriffis 1.1 return 0
169     fi
170     dtd_date=$(egrep --only-matching --max-count=1 \
171     '[0-9]{4}/[0-9]{2}/[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}' "${dtd}")
172     if [[ -z ${dtd_date} ]]; then
173 agriffis 1.2 verb " Couldn't find RCS date in ${dtd}, ignoring entities"
174 agriffis 1.1 return 0
175     fi
176 agriffis 1.2 verb " RCS datestamp in ${dtd} is ${dtd_date}"
177 agriffis 1.1 dtd_date=$(date -d "$dtd_date" +%s)
178     if [[ -z $LATEST_DTD || $dtd_date -gt $LATEST_DATE ]]; then
179     LATEST_DATE=${dtd_date}
180     LATEST_DTD=${dtd}
181     fi
182     }
183    
184 flameeyes 1.6 #
185     # populate a specific simple dtd version into the docbook catalog
186     # $1 == /path/to/sdocbook.dtd
187     #
188     populate_simple_dtd() {
189     typeset dtd=$1 docbookdir=${1%/*}
190     typeset v=${docbookdir##*-}
191    
192     # sanity check
193     if [[ ${dtd} != */xml-simple-dtd-*/* ]]; then
194     echo "Warning: I don't understand \"${dtd}\"" >&2
195     return
196     fi
197     echo "Found Simplified DocBook XML ${v} in ${docbookdir}"
198    
199     # Populate the docbook catalog with this version
200     verb " Populating ${CATALOG} based on ${docbookdir}"
201     xmlcatalog --noout --add "public" "-//OASIS//DTD Simplified DocBook XML V${v}//EN" "file://${docbookdir}/sdocbook.dtd" ${CATALOG}
202     xmlcatalog --noout --add "rewriteSystem" "http://www.oasis-open.org/docbook/xml/simple/${v}" "file://${docbookdir}" ${CATALOG}
203     xmlcatalog --noout --add "rewriteURI" "http://www.oasis-open.org/docbook/xml/simple/${v}" "file://${docbookdir}" ${CATALOG}
204     }
205    
206 agriffis 1.1 #
207     # populate ISO DocBook entities from the most recent DTD
208     #
209     populate_entities() {
210     typeset isodir=${LATEST_DTD%/*}/ent i j
211     typeset -a entities avail
212    
213     # sanity check
214     if [[ -z ${LATEST_DTD} || ! -d ${isodir} ]]; then
215     echo "No ISO DocBook entities available for catalog"
216     return 0
217     fi
218     echo "Using ISO DocBook entities from ${isodir}"
219    
220     # here are the entities we know about;
221     # note these must remain sorted!
222     entities=(
223     "iso-amsa.ent" "ISO 8879:1986//ENTITIES Added Math Symbols: Arrow Relations//EN"
224     "iso-amsb.ent" "ISO 8879:1986//ENTITIES Added Math Symbols: Binary Operators//EN"
225     "iso-amsc.ent" "ISO 8879:1986//ENTITIES Added Math Symbols: Delimiters//EN"
226     "iso-amsn.ent" "ISO 8879:1986//ENTITIES Added Math Symbols: Negated Relations//EN"
227     "iso-amso.ent" "ISO 8879:1986//ENTITIES Added Math Symbols: Ordinary//EN"
228     "iso-amsr.ent" "ISO 8879:1986//ENTITIES Added Math Symbols: Relations//EN"
229     "iso-box.ent" "ISO 8879:1986//ENTITIES Box and Line Drawing//EN"
230     "iso-cyr1.ent" "ISO 8879:1986//ENTITIES Russian Cyrillic//EN"
231     "iso-cyr2.ent" "ISO 8879:1986//ENTITIES Non-Russian Cyrillic//EN"
232     "iso-dia.ent" "ISO 8879:1986//ENTITIES Diacritical Marks//EN"
233     "iso-grk1.ent" "ISO 8879:1986//ENTITIES Greek Letters//EN"
234     "iso-grk2.ent" "ISO 8879:1986//ENTITIES Monotoniko Greek//EN"
235     "iso-grk3.ent" "ISO 8879:1986//ENTITIES Greek Symbols//EN"
236     "iso-grk4.ent" "ISO 8879:1986//ENTITIES Alternative Greek Symbols//EN"
237     "iso-lat1.ent" "ISO 8879:1986//ENTITIES Added Latin 1//EN"
238     "iso-lat2.ent" "ISO 8879:1986//ENTITIES Added Latin 2//EN"
239     "iso-num.ent" "ISO 8879:1986//ENTITIES Numeric and Special Graphic//EN"
240     "iso-pub.ent" "ISO 8879:1986//ENTITIES Publishing//EN"
241     "iso-tech.ent" "ISO 8879:1986//ENTITIES General Technical//EN"
242     )
243    
244     # here are the entities available; assume no spaces in filenames...
245     avail=($(ls ${isodir} | sort))
246    
247     # double-check the lists
248 agriffis 1.2 verb " Populating ${CATALOG} with ISO DocBook entities"
249 agriffis 1.1 i=0 ; j=0
250     while [[ ${i} -lt ${#entities[@]} || ${j} -lt ${#avail[@]} ]]; do
251     if [[ ${i} -ge ${#entities[@]} ]]; then
252     echo "Warning: Extra ISO entities file: ${avail[j]}"
253     let j=j+1
254     elif [[ ${j} -ge ${#avail[@]} ]]; then
255     echo "Warning: Entities file not found: ${entities[i]}"
256     let i=i+2
257     elif [[ ${avail[j]} < ${entities[i]} ]]; then
258     echo "Warning: Extra ISO entities file: ${avail[j]}"
259     let j=j+1
260     elif [[ ${entities[i]} < ${avail[j]} ]]; then
261     echo "Warning: Entities file not found: ${entities[i]}"
262     let i=i+2
263     elif [[ ${entities[i]} == ${avail[j]} ]]; then
264     xmlcatalog --noout --add "public" "${entities[i+1]}" \
265     "file://${isodir}/${entities[i]}" ${CATALOG}
266     let j=j+1
267     let i=i+2
268     else
269     echo "${0}: Whoah, shouldn't be here, aborting" >&2
270     exit 1
271     fi
272     done
273     }
274    
275     #
276     # populate XSL stylesheets
277     #
278     populate_xsl() {
279     typeset listed avail f
280    
281 flameeyes 1.3 # This is either xsl, xsl-ns, xsl-saxon or xsl-xalan
282     local type=$1
283    
284     # Delete current entries from the catalog (delete legacy versioned entries too)
285     clean_catalog "${DOCBOOKDIR}/${type}-stylesheets(-[0-9\.]+)?" $CATALOG
286     clean_catalog "${DOCBOOKDIR}/${type}-stylesheets(-[0-9\.]+)?" $ROOTCATALOG
287    
288     xsldir=/usr/share/sgml/docbook/${type}-stylesheets
289    
290     if [[ ! -d ${xsldir} ]]; then
291     echo "DocBook XSL stylesheets (${type}) not found" >&2
292 agriffis 1.1 return 1
293     fi
294 flameeyes 1.3
295 agriffis 1.1 if [[ ! -e ${xsldir}/html/docbook.xsl || ! -e ${xsldir}/common/l10n.xml ]]; then
296 flameeyes 1.3 echo "DocBook XSL stylesheets are missing files from ${xsldir}" >&2
297 agriffis 1.1 return 1
298     fi
299    
300     # Populate catalog with XSL entries
301 flameeyes 1.3 echo "Found DocBook XSL stylesheets (${type}) in ${xsldir}"
302 flameeyes 1.4
303     verb " Populating ${ROOTCATALOG} with XSL delegations"
304     xmlcatalog --noout --add "delegateSystem" "http://docbook.sourceforge.net/release/${type}/" "file://${CATALOG}" ${ROOTCATALOG}
305     xmlcatalog --noout --add "delegateURI" "http://docbook.sourceforge.net/release/${type}/" "file://${CATALOG}" ${ROOTCATALOG}
306    
307 agriffis 1.2 verb " Populating ${CATALOG} with XSL stylesheets"
308 flameeyes 1.4 xmlcatalog --noout --add "rewriteSystem" "http://docbook.sourceforge.net/release/${type}/current" "file://${xsldir}" ${CATALOG}
309     xmlcatalog --noout --add "rewriteURI" "http://docbook.sourceforge.net/release/${type}/current" "file://${xsldir}" ${CATALOG}
310 agriffis 1.1 }
311    
312     # Call the main routine
313 agriffis 1.2 main "$@"

  ViewVC Help
Powered by ViewVC 1.1.20