/usr/bin/charset is in console-tools 1:0.2.3dbs-65.1ubuntu2.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 | #!/bin/sh
usage()
{
echo >&2 "Usage: $(basename $0) [-v] [--tty=<device>] G0|G1 [cp437|iso01|vt100|user|<acm_name>]"
}
usage_exit()
{
usage
exit 1
}
tty_out()
{
/bin/echo -en >&3 $*
}
verbose()
{
test $VERBOSE = 1 && echo >&2 $*
}
error()
{
echo >&2 $*
}
activate_charset()
{
verbose "Switching to $1 charset"
case $1 in
G0)
tty_out "\017"
;;
G1)
tty_out "\016"
;;
esac
}
# parse command-line
CHARSET=
ACM=
INTERNAL_ACM=
ACM_NAME=
TTY=/dev/tty
VERBOSE=0
GOT_CHARSET=0
GOT_ACM=0
while [ $# -gt 0 ]
do
case $1 in
-v)
VERBOSE=1
shift
;;
--tty)
TTY=$2
shift
shift
;;
--tty=*)
TTY=${1#--tty=}
shift
;;
G0|G1)
test ${GOT_CHARSET} = 1 && usage_exit
CHARSET=$1
GOT_CHARSET=1
shift
;;
iso01)
test ${GOT_ACM} = 1 && usage_exit
INTERNAL_ACM=B
ACM_NAME=$1
GOT_ACM=1
shift
;;
vt100)
test ${GOT_ACM} = 1 && usage_exit
INTERNAL_ACM=0
ACM_NAME=$1
GOT_ACM=1
shift
;;
cp437)
test ${GOT_ACM} = 1 && usage_exit
INTERNAL_ACM=U
ACM_NAME=$1
GOT_ACM=1
shift
;;
user)
test ${GOT_ACM} = 1 && usage_exit
INTERNAL_ACM=K
ACM_NAME="user-defined"
GOT_ACM=1
shift
;;
*)
test ${GOT_ACM} = 1 && usage_exit
INTERNAL_ACM=K
ACM_NAME="user-defined"
ACM=$1
GOT_ACM=1
shift
;;
esac
done
# open requested tty
test -c "$TTY" && exec 3<>$TTY
# if specified ACM is not available internally, get it from file
if [ "$ACM" != "" ]
then
case $CHARSET in
G0)
OPT=
;;
G1)
OPT=--g1
;;
esac
verbose -n "Loading $ACM ACM into user-defined slot..."
consolechars $OPT --tty=${TTY} -m $ACM && verbose "done."
fi
if [ "$INTERNAL_ACM" -a "$CHARSET" ]
then # make $CHARSET point to $INTERNAL_ACM
if [ "$TTY" ]
then
ONTTY=" on $TTY"
else
ONTTY=""
fi
if [ "$ACM" ]
then
verbose "Making ${CHARSET}${ONTTY} point to $ACM_NAME ACM (file $ACM)"
else
verbose "Making ${CHARSET}${ONTTY} point to internal ACM $ACM_NAME"
fi
case $CHARSET in
G0)
tty_out "\033($INTERNAL_ACM"
;;
G1)
tty_out "\033)$INTERNAL_ACM"
;;
esac
activate_charset $CHARSET
elif [ "$CHARSET" -a -z "$INTERNAL_ACM" ]
then # make $CHARSET current
activate_charset $CHARSET
elif [ "$INTERNAL_ACM" -a -z "$CHARSET" ]
then # set current charset to $ACM
error "Don't know (yet ?) how to determine current charset."
error "Please specify G0 or G1"
exit 1
else
usage
fi
|