comvar.sh revision da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968
########################################################################
# #
# This software is part of the ast package #
# Copyright (c) 1982-2007 AT&T Knowledge Ventures #
# and is licensed under the #
# Common Public License, Version 1.0 #
# by AT&T Knowledge Ventures #
# #
# A copy of the License is available at #
# (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) #
# #
# Information and Software Systems Research #
# AT&T Research #
# Florham Park NJ #
# #
# David Korn <dgk@research.att.com> #
# #
########################################################################
function err_exit
{
print -u2 -n "\t"
let Errors+=1
}
alias err_exit='err_exit $LINENO'
#test for compound variables
integer Errors=0
Point=(
float x=1. y=0.
)
eval p="$Point"
then err_exit 'compound variable not working'
fi
nameref foo=p
then err_exit 'reference to compound object not working'
fi
unset foo
rec=(
name='Joe Blow'
born=(
integer day=16
year=1980
)
)
if [[ ${newrec.name} != "${rec.name}" ]]
then err_exit 'copying a compound object not working'
fi
then err_exit 'copying integer field of compound object not working'
fi
p_t=(
integer z=0
typeset -A tokens
)
unset x
typeset -A x
if [[ ${x[@]} != bar ]]
then err_exit 'compound assignemnt of associative arrays not working'
fi
unset -n foo x
unset foo x
foo=( x=3)
nameref x=foo
if [[ ${!x.@} != foo.x ]]
then err_exit 'name references not expanded on prefix matching'
fi
unset x
(
x=()
)
foo=(integer x=3)
if [[ ${foo} != *x=3* ]]
then err_exit "compound variable with integer subvariable not working"
fi
err_exit '[[ ... ]] not working after compound assignment'
unset foo
suitable=(
label="Table Viewer"
langs="ksh"
groups="default"
default=(
label="Table Viewer Preferences"
entrylist=" \
vieworigin viewsize viewcolor viewfontname viewfontsize \
showheader header showfooter footer showtitle title showlegends \
class_td_lg1_style class_tr_tr1_style \
class_th_th1_style class_td_td1_style \
fields fieldorder \
"
entries=(
)
viewsize=(
)
label="Window Colors"
)
type=fontname var=viewfontname val="Times-Roman"
label="Window Font Name"
)
type=fontsize var=viewfontsize val=14 label="Window Font Size"
)
)
header=(
)
)
footer=(
)
)
title=(
)
)
type=style var=class_td_lg1_style
val="color: black; font-family: Times-Roman; font-size: 14pt"
label="Legend 1 Style"
)
type=style var=class_tr_tr1_style val="background: black"
label="Table Row 1 Style"
)
type=style var=class_th_th1_style
val="color: black; font-family: Times-Roman; font-size: 14pt; text-align: left"
label="Table Header 1 Style"
)
type=style var=class_td_td1_style
val="color: black; font-family: Times-Roman; font-size: 14pt; text-align: left"
label="Table Cell 1 Style"
)
fields=(
)
type=text var=fieldorder val= label="Order of Fields"
)
)
)
)
function localvar
{
typeset point=(typeset -i x=3 y=4)
}
point=(integer x=6 y=8)
(( (point.x*point.x + point.y*point.y) == 100 )) || err_exit "global compound variable not preserved"
[[ $($SHELL -c 'foo=();foo.[x]=(y z); print ${foo.x[@]}') == 'y z' ]] 2> /dev/null || err_exit 'foo=( [x]=(y z) not working'
unset z