#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
#
# Make sure all math stuff runs in the "C" locale to avoid problems
# with alternative # radix point representations (e.g. ',' instead of
# '.' in de_DE.*-locales). This needs to be set _before_ any
# floating-point constants are defined in this script).
if [[ "${LC_ALL}" != "" ]] ; then
export \
LC_MONETARY="${LC_ALL}" \
LC_MESSAGES="${LC_ALL}" \
LC_COLLATE="${LC_ALL}" \
LC_CTYPE="${LC_ALL}"
unset LC_ALL
fi
export LC_NUMERIC=C
function fatal_error
{
print -u2 "${progname}: $*"
exit 1
}
function do_directory
{
nameref tree=$1
typeset basedir="$2"
typeset basename
typeset dirname
typeset i
typeset dummy
typeset -C -A tree.files
typeset -C -A tree.dirs
# define "node"
if [[ -d "$i" ]] ; then
typeset -C node.flags
node.flags.dir="true"
node.flags.file="false"
else
typeset -C node.flags
node.flags.dir="false"
node.flags.file="true"
fi
# basic attributes
typeset -C node.paths=(
dirname="${dirname}"
basename="${basename}"
path="${i}"
)
nameref nflags=node.flags
integer node.size
integer node.links
typeset -C node.owner
typeset -C node.extended_attributes
typeset -a attrlist=(
)
else
fi
if ${nflags.readable} ; then
# have to use ':' instead.
fi
if ${nflags.dir} ; then
do_directory "${!node}" "$i"
fi
done
# remove empty lists
return 0
}
function pathtovartree
{
nameref tree=$1
typeset basedir="$2"
do_directory tree "${basedir}"
return 0
}
function usage
{
OPTIND=0
exit 2
}
# program start
builtin basename
builtin cat
builtin dirname
builtin date
builtin uname
typeset -r filetree1_usage=$'+
[-?\n@(#)\$Id: filetree1 (Roland Mainz) 2009-05-06 \$\n]
[-author?Roland Mainz <roland.mainz@sun.com>]
[-author?Roland Mainz <roland.mainz@nrubsig.org>]
[+NAME?filetree1 - file tree demo]
[+DESCRIPTION?\bfiletree1\b is a small ksh93 compound variable demo
which accepts a directory name as input, and then builds tree
nodes for all files+directories and stores all file attributes
in these notes and then outputs the tree in the format
specified by viewmode (either "list", "namelist", "tree" or "compacttree")..]
viewmode dirs
[+SEE ALSO?\bksh93\b(1), \bfile\b(1)]
'
# printmsg "## OPT=|${OPT}|, OPTARG=|${OPTARG}|"
*) usage ;;
esac
done
typeset viewmode="$1"
shift
fatal_error $"Invalid view mode \"${viewmode}\"."
fi
typeset -C myfiletree
while (( $# > 0 )) ; do
print -u2 -f "# Scanning %s ...\n" "${1}"
pathtovartree myfiletree "${1}"
shift
done
print -u2 $"#parsing completed."
list)
;;
typeset + | egrep "^myfiletree\["
;;
tree)
print -v myfiletree
;;
print -C myfiletree
;;
*)
fatal_error $"Invalid view mode \"${viewmode}\"."
;;
esac
print -u2 $"#done."
exit 0
# EOF.