7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin# CDDL HEADER START
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin# The contents of this file are subject to the terms of the
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin# Common Development and Distribution License (the "License").
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin# You may not use this file except in compliance with the License.
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin# See the License for the specific language governing permissions
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin# and limitations under the License.
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin# When distributing Covered Code, include this CDDL HEADER in each
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin# If applicable, add the following below this CDDL HEADER, with the
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin# fields enclosed by brackets "[]" replaced with your own identifying
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin# information: Portions Copyright [yyyy] [name of copyright owner]
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin# CDDL HEADER END
3e14f97f673e8a630f076077de35afdd43dc1587Roger A. Faulkner# Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin# Solaris needs /usr/xpg6/bin:/usr/xpg4/bin because the tools in /usr/bin are not POSIX-conformant
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chinexport PATH=/usr/xpg6/bin:/usr/xpg4/bin:/bin:/usr/bin
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin#set -o xtrace
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin while [[ "${s:currattrlen:1}" == ~(E)[[:blank:][:space:]] ]] ; do
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin #x="foo=bar huz=123" ; print "${x##~(E)[[:alnum:]_-:]*=[^[:blank:]\"]*}"
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin #x='foo="ba=r o" huz=123' ; print "${x##~(E)[[:alnum:]_-:]*=\"[^\"]*\"}"
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin #x="foo='ba=r o' huz=123" ; print "${x##~(E)[[:alnum:]_-:]*=\'[^\"]*\'}"
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin #x="foox huz=123" ; print "${x##~(E)[[:alnum:]_-:]*}"
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin #x='foo="bar=o" huz=123' ; print "${x##~(E)([[:alnum:]_-:]*=[^[:blank:]\"]*|[[:alnum:]_-:]*=\"[^\"]*\"|[[:alnum:]_-:]*=\'[^\"]*\')}"
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin nextattr="${s##~(E)([[:alnum:]_-:]*=[^[:blank:]\"]*|[[:alnum:]_-:]*=\"[^\"]*\"|[[:alnum:]_-:]*=\'[^\"]*\'|[[:alnum:]_-:]*)}"
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin if [[ "${tagval}" == ~(Elr)(\'.*\'|\".*\") ]] ; then
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin aa[${aa_count}]=( name="${tagstr%%=*}" value="${tagval}" )
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin # special case for HTML where you have something like <foo baz>
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin (( aa_count > 1000 )) && fatal_error "$0: aa_count too large" # assert
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin#set -o xtrace
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin attrstrtoattrarray "${tag_attributes}" "nodepath[${nodesnum}].tagattributes"
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin stack.items[stack.pos]="${stack.items[stack.pos-1]}[${nodesnum}].nodes"
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin# print "xmltok: '${tag_type}' = '${tag_value}'"
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin typeset issingletag # bool: true/false (used for tags like "<br />")
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin [[ ! -z "${callbacks["document_start"]}" ]] && ${callbacks["document_start"]} "${1}" "document_start"
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin [[ ! -z "${callbacks["tag_text"]}" ]] && ${callbacks["tag_text"]} "${1}" "tag_text" "$buf"
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin [[ ! -z "${callbacks["tag_comment"]}" ]] && ${callbacks["tag_comment"]} "${1}" "tag_comment" "${buf:3:${#buf}-5}"
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin # check if the tag starts and ends at the same time (like "<br />")
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin # check if the tag has attributes (e.g. space after name)
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin if [[ "$buf" == ~(E)[[:space:][:blank:]] ]] ; then
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin [[ ! -z "${callbacks["tag_end"]}" ]] && ${callbacks["tag_end"]} "${1}" "tag_end" "$namebuf"
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin [[ ! -z "${callbacks["tag_begin"]}" ]] && ${callbacks["tag_begin"]} "${1}" "tag_begin" "$namebuf" "$attrbuf"
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin # handle tags like <br/> (which are start- and end-tag in one piece)
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin [[ ! -z "${callbacks["tag_end"]}" ]] && ${callbacks["tag_end"]} "${1}" "tag_end" "$namebuf"
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin [[ ! -z "${callbacks["document_end"]}" ]] && ${callbacks["document_end"]} "${1}" "document_end" "exit_success"
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin print # final newline to make filters like "sed" happy
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin<score-partwise instrument="flute1">
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin <identification>
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin <kaiman>nocrocodile</kaiman>
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin </identification>
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin <!-- a comment -->
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin <foo>myfootext</foo>
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin <bar>mybartext</bar>
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin <!-- another
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin <ttt>myttttext</ttt>
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin</score-partwise>
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin getopts -a "${progname}" "${xmldocumenttree1_usage}" OPT '-?'
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin# program start
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz[-?\n@(#)\$Id: xmldocumenttree1 (Roland Mainz) 2009-05-09 \$\n]
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin[-author?Roland Mainz <roland.mainz@nrubsig.org>]
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin[+NAME?xmldocumenttree1 - XML tree demo]
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin[+DESCRIPTION?\bxmldocumenttree\b is a small ksh93 compound variable demo
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin which reads a XML input file, converts it into an internal
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin variable tree representation and outputs it in the format
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz specified by viewmode (either "list", "namelist", "tree" or "compacttree").]
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chinfile viewmode
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin[+SEE ALSO?\bksh93\b(1)]
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chinwhile getopts -a "${progname}" "${xmldocumenttree1_usage}" OPT ; do
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin# printmsg "## OPT=|${OPT}|, OPTARG=|${OPTARG}|"
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainzif [[ "${viewmode}" != ~(Elr)(list|namelist|tree|compacttree) ]] ; then
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin fatal_error $"Invalid view mode \"${viewmode}\"."
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin# setup callbacks for xml_tok
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin# argument for "handle_document"
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin set | egrep "xdoc.*(tagname|tagtype|tagval|tagattributes)" | fgrep -v ']=$'
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin typeset + | egrep "xdoc.*(tagname|tagtype|tagval|tagattributes)"
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin fatal_error $"Invalid view mode \"${viewmode}\"."