#!/bin/ksh
#
# This file and its contents are supplied under the terms of the
# Common Development and Distribution License ("CDDL"), version 1.0.
# You may only use this file in accordance with the terms of version
# 1.0 of the CDDL.
#
# A full copy of the text of the CDDL should have accompanied this
# source.  A copy of the CDDL is also available via the Internet at
# http://www.illumos.org/license/CDDL.
#

#
# Copyright 2011 Nexenta Systems, Inc.  All rights reserved.

# List all iconv(1) codesets

cd /usr/lib/iconv || exit 1

typeset -A all

/usr/bin/ls | while read f
do
    case "$f" in
    geniconvtbl.so)
	;;
    *.so)
	IFS="%"
	set ${f%.so}
	all[$1]=" "
	all[$2]=" "
	;;
    *.t)
	IFS="."
	set ${f%.t}
	all[$1]=" "
	all[$2]=" "
	;;
    *)
    	;;
    esac
done

/usr/bin/ls geniconvtbl/binarytables |
while read f
do
    case "$f" in
    *.bt)
	IFS="%"
	set ${f%.bt}
	all[$1]=" "
	all[$2]=" "
	;;
    *)
    	;;
    esac
done

# Only store aliases for names we've seen

IFS=" 	"
while read a c
do
    case "$a" in
    \#*)
	;;
    *)
	if [ "$c" -a "${all[$c]}" ] ; then
		all[$c]="${all[$c]} $a"
	fi
	;;
    esac
done < "alias"

cat <<EOF
The following are all supported code set names.  Conversions
between some fromcode-tocode pairs might not be available.
Some of these code set names have aliases, which are shown
after the canonical name.

EOF

for i in "${!all[@]}"
do
	echo "$i ${all[$i]}"
done
