1#
2# CDDL HEADER START
3#
4# The contents of this file are subject to the terms of the
5# Common Development and Distribution License (the "License").
6# You may not use this file except in compliance with the License.
7#
8# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9# or http://www.opensolaris.org/os/licensing.
10# See the License for the specific language governing permissions
11# and limitations under the License.
12#
13# When distributing Covered Code, include this CDDL HEADER in each
14# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15# If applicable, add the following below this CDDL HEADER, with the
16# fields enclosed by brackets "[]" replaced with your own identifying
17# information: Portions Copyright [yyyy] [name of copyright owner]
18#
19# CDDL HEADER END
20#
21
22#
23# Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
24#
25
26#
27# variable tree test #003
28# Propose of this test is whether ksh93 handles global variable trees
29# and function-local variable trees the same way, including "nameref"
30# and "unset" handling.
31#
32
33# test setup
34function err_exit
35{
36	print -u2 -n "\t"
37	print -u2 -r ${Command}[$1]: "${@:2}"
38	(( Errors < 127 && Errors++ ))
39}
40alias err_exit='err_exit $LINENO'
41
42# the test cannot use "nounset"
43Command=${0##*/}
44integer Errors=0
45
46function example_tree
47{
48cat <<EOF
49(
50	typeset -A l1=(
51		[adobe]=(
52			typeset -A l2=(
53				[avantgarde]=(
54					typeset -A l3=(
55						[demi]=(
56							typeset -A entries=(
57								[182c069a485316b1bc7ae001c04c7835]=(
58									typeset -a comments=(
59										FONT
60										-adobe-avantgarde-demi-r-normal--199-120-1200-1200-p-1130-iso8859-1
61										COPYRIGHT
62										'Copyright Notice not available'
63										RAW_PIXELSIZE
64										RAW_POINTSIZE
65										--
66										section
67										diaeresis
68										copyright
69										ordfeminine
70										guillemotleft
71									)
72									typeset -a filenames=(
73										X11Rx/R6.4/xc/programs/Xserver/XpConfig/C/print/models/SPSPARC2/fonts/AvantGarde-Demi.pmf
74									)
75									md5sum=182c069a485316b1bc7ae001c04c7835
76									typeset -a xlfd=(
77										-adobe-avantgarde-demi-r-normal--199-120-1200-1200-p-1130-iso8859-1
78									)
79								)
80								[7db15b51965d8fe1f1c55fcb101d7616]=(
81									typeset -a comments=(
82										FONT
83										-adobe-avantgarde-demi-i-normal--199-120-1200-1200-p-1130-iso8859-1
84										COPYRIGHT
85										'Copyright Notice not available'
86										RAW_PIXELSIZE
87										RAW_POINTSIZE
88										--
89										section
90										diaeresis
91										copyright
92										ordfeminine
93										guillemotleft
94									)
95									typeset -a filenames=(
96										X11Rx/R6.4/xc/programs/Xserver/XpConfig/C/print/models/SPSPARC2/fonts/AvantGarde-DemiOblique.pmf
97									)
98									md5sum=7db15b51965d8fe1f1c55fcb101d7616
99									typeset -a xlfd=(
100										-adobe-avantgarde-demi-i-normal--199-120-1200-1200-p-1130-iso8859-1
101									)
102								)
103								[a37e4a4a5035abf6f294d830fbd9e775]=(
104									typeset -a comments=(
105										FONT
106										-adobe-avantgarde-demi-r-normal--422-120-2540-2540-p-2395-iso8859-1
107										COPYRIGHT
108										'Copyright (c) 1985, 1987, 1989, 1990, 1991 Adobe Systems Incorporated.  All Rights Reserved.ITC Avant Garde Gothic is a registered trademark of International Typeface Corporation.'
109										RAW_PIXELSIZE
110										RAW_POINTSIZE
111										--
112										section
113										diaeresis
114										copyright
115										ordfeminine
116										guillemotleft
117									)
118									typeset -a filenames=(
119										fox-gate/XW_NV/open-src/tarballs/xorg-server-1.3.0.0/hw/xprint/config/C/print/models/PSdefault/fonts/AvantGarde-Demi.pmf
120									)
121									md5sum=a37e4a4a5035abf6f294d830fbd9e775
122									typeset -a xlfd=(
123										-adobe-avantgarde-demi-r-normal--422-120-2540-2540-p-2395-iso8859-1
124									)
125								)
126								[da3d6d94fcf759b95c7f829ce5619374]=(
127									typeset -a comments=(
128										FONT
129										-adobe-avantgarde-demi-i-normal--422-120-2540-2540-p-2395-iso8859-1
130										COPYRIGHT
131										'Copyright (c) 1985, 1987, 1989, 1990, 1991 Adobe Systems Incorporated.  All Rights Reserved.ITC Avant Garde Gothic is a registered trademark of International Typeface Corporation.'
132										RAW_PIXELSIZE
133										RAW_POINTSIZE
134										--
135										section
136										diaeresis
137										copyright
138										ordfeminine
139										guillemotleft
140									)
141									typeset -a filenames=(
142										fox-gate/XW_NV/open-src/tarballs/xorg-server-1.3.0.0/hw/xprint/config/C/print/models/PSdefault/fonts/AvantGarde-DemiOblique.pmf
143									)
144									md5sum=da3d6d94fcf759b95c7f829ce5619374
145									typeset -a xlfd=(
146										-adobe-avantgarde-demi-i-normal--422-120-2540-2540-p-2395-iso8859-1
147									)
148								)
149							)
150						)
151					)
152				)
153			)
154		)
155	)
156)
157EOF
158}
159
160function main
161{
162	set -o errexit
163
164	typeset xlfd_tree=()
165	typeset -A xlfd_tree.l1
166
167	eval "xlfd_tree=$( example_tree )"
168
169	typeset i j k l fn
170
171        # filter chain begin
172        for i in "${!xlfd_tree.l1[@]}" ; do
173              for j in "${!xlfd_tree.l1["$i"].l2[@]}" ; do
174        	     for k in "${!xlfd_tree.l1["$i"].l2["$j"].l3[@]}" ; do
175        		     nameref vndnode=xlfd_tree.l1["$i"].l2["$j"].l3["$k"]
176
177        		     for l in "${!vndnode.entries[@]}" ; do
178        			     nameref node=vndnode.entries["$l"]
179
180        			     for fn in "${node.filenames[@]}" ; do
181        				     if [[ "${fn}" != ~(E)x-re_gate_XW_NV_MWS ]] ; then
182        					     unset "${!node}"
183        					     break
184        				     fi
185        			     done
186        		     done
187        	     done
188              done
189	done
190
191	# filter chain end
192
193	return 0
194}
195
196main || ((Errors++))
197
198# tests done
199exit $((Errors))
200