3 # Automated Testing Framework (atf)
5 # Copyright (c) 2009 The NetBSD Foundation, Inc.
8 # Redistribution and use in source and binary forms, with or without
9 # modification, are permitted provided that the following conditions
11 # 1. Redistributions of source code must retain the above copyright
12 # notice, this list of conditions and the following disclaimer.
13 # 2. Redistributions in binary form must reproduce the above copyright
14 # notice, this list of conditions and the following disclaimer in the
15 # documentation and/or other materials provided with the distribution.
17 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND
18 # CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
19 # INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
20 # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 # IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY
22 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
24 # GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
26 # IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
28 # IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 # -------------------------------------------------------------------------
34 # Variables expected in the environment.
35 # -------------------------------------------------------------------------
40 : ${XML_CATALOG_FILE:=UNSET}
44 # -------------------------------------------------------------------------
46 # -------------------------------------------------------------------------
50 # -------------------------------------------------------------------------
51 # Auxiliary functions.
52 # -------------------------------------------------------------------------
58 for line
in "${@}"; do
59 echo "${Prog_Name}: ${line}" 1>&2
65 # validate_xml xml_file
68 echo "XML_CATALOG_FILES=${XML_CATALOG_FILE} ${XMLLINT}" \
69 "--nonet --valid --path doc ${1}"
70 XML_CATALOG_FILES
=${XML_CATALOG_FILE} \
71 ${XMLLINT} --nonet --valid --path doc
${1} >/dev
/null
72 [ ${?} -eq 0 ] || err
"XML validation of ${1} failed"
76 # run_xsltproc input stylesheet output [args]
80 stylesheet
=${1}; shift
82 echo "${XSLTPROC} --path doc ${*} ${stylesheet} ${input} >${output}"
83 if ${XSLTPROC} --path doc "${@}" ${stylesheet} ${input} >${output}; then
86 err
"XSLT processing of ${input} with ${stylesheet} failed"
91 # tidy_xml input output
94 echo "${TIDY} -quiet -xml ${1} >${2}"
95 if ${TIDY} -quiet -xml ${1} >${2}; then
98 err
"Tidying of ${1} failed"
103 # xml_to_html xml_input xslt_file html_output
110 tmp1
=$
(mktemp
-t build-xml.XXXXXX
)
111 tmp2
=$
(mktemp
-t build-xml.XXXXXX
)
113 mkdir
-p ${html_output%/*}
114 validate_xml
${xml_input}
115 run_xsltproc
${xml_input} ${xslt_file} ${tmp1}
116 tidy_xml
${tmp1} ${tmp2}
120 echo "mv -f ${tmp2} ${html_output}"
121 mv -f ${tmp2} ${html_output}
125 # format_txt input output
128 echo "${LINKS} -dump ${1} >${2}"
129 if ${LINKS} -dump ${1} >${2}; then
132 err
"Formatting of ${1} failed"
137 # xml_to_txt xml_input xslt_file txt_output
144 tmp1
=$
(mktemp
-t build-xml.XXXXXX
)
145 tmp2
=$
(mktemp
-t build-xml.XXXXXX
)
147 mkdir
-p ${txt_output%/*}
148 validate_xml
${xml_input}
149 run_xsltproc
${xml_input} ${xslt_file} ${tmp1}
150 format_txt
${tmp1} ${tmp2}
154 echo "mv -f ${tmp2} ${txt_output}"
155 mv -f ${tmp2} ${txt_output}
159 # xml_to_anything xml_input xslt_file output
164 format
=$
(echo ${3} | cut
-d : -f 1)
165 output
=$
(echo ${3} | cut
-d : -f 2)
169 xml_to_
${format} ${xml_input} ${xslt_file} ${output}
172 err
"Unknown format ${format}"
177 # -------------------------------------------------------------------------
179 # -------------------------------------------------------------------------
182 [ ${#} -eq 3 ] || usage
188 if [ ${DOC_BUILD} = yes ]; then
189 xml_to_anything
${1} ${2} ${3}
192 err
"Cannot regenerate ${output}" \
193 "Reconfigure the package using --enable-doc-build"
199 Usage: ${Prog_Name} <xml-input> <xslt-file> <format>:<output>
206 # vim: syntax=sh:expandtab:shiftwidth=4:softtabstop=4