Debian Codegraph @

src/unicode_start

raw ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 #!/bin/sh
2
3 # 0. Check whether we're on a console
4 TTY=$(/usr/bin/tty)
5 case "$TTY" in
6 /dev/console|/dev/vc*|/dev/tty[0-9]*)
7 ;;
8 *)
9 echo "unicode_start skipped on $TTY" >&2
10 exit 0
11 ;;
12 esac
13
14 # Enables Unicode processing in the current console.
15 #
16 # 1. The input side: the keyboard driver.
17
18 # Set the keyboard driver in Unicode mode. (Default is ASCII mode.)
19 # This really does nothing with the way normal keys are handled in
20 # the kernel. All it does is:
21 # - It is necessary for `dumpkeys' in order to not drop U+XXXX
22 # entries from the keymaps.
23 # - It is necessary for `loadkeys' in order to avoid warnings.
24 # - Unicode characters typed as Alt-x1 ... Alt-xn (where x1,...,xn
25 # are digits on the numeric keypad) will be emitted in UTF-8.
26
27 kbd_mode -u
28
29 # Change the keyboard mapping in such a way that the non-ASCII keys
30 # produce UTF-8 encoded multibyte sequences, instead of single bytes
31 # >= 0x80 in a legacy 8-bit encoding.
32
33 # Non-root users are allowed to change the unicode mode of their console, but
34 # not the global keymap. root will have to load the keymap in unicode mode
35 # explicitly.
36
37 uid="$(id -u 2>/dev/null)" ||:
38 if [ "$uid" = 0 ]; then
39 # There is no way of reverting the effect of "dumpkeys | loadkeys --unicode",
40 # the memory of the earlier keymap is lost. Therefore, try
41 # to save a copy of the original keymap to be able to reload it in unicode_stop.
42 # (see also http://mail.nl.linux.org/linux-utf8/2003-08/msg00053.html):
43
44 [ -n "$HOME" ] && [ "$HOME" != '/' ] ||
45 HOME='/root'
46
47 if [ -d "$HOME" ] && [ -w "$HOME" ]; then
48 [ -d "$HOME/.kbd" ] ||
49 mkdir -- "$HOME/.kbd"
50
51 [ ! -w "$HOME/.kbd" ] ||
52 dumpkeys > "$HOME/.kbd/.keymap_sv"
53 fi
54
55 # redirect stderr and stdout of loadkeys to /dev/null to avoid the confusing
56 # "plus before udiaeresis ignored" warnings.
57
58 dumpkeys | loadkeys --unicode > /dev/null 2>&1
59 fi
60
61 # 2. The output side: the console screen.
62
63 # Tell the console output driver that the bytes arriving are UTF-8
64 # encoded multibyte sequences.
65 if [ -t 1 ] && [ -t 2 ]; then
66 printf '\033%%G'
67 fi
68 stty iutf8
69
70 # Tell the graphics card how to display Unicode characters not
71 # contained in the IBM 437 character set (on PCs). The font should
72 # have a Unicode map attached, or explicitly specified, e.g.,
73 # by giving `def.uni' as a second argument.
74
75 case "$#" in
76 2)
77 setfont "$1" -u "$2"
78 ;;
79 1)
80 setfont "$1"
81 ;;
82 0)
83 ;;
84 *)
85 echo "usage: unicode_start [font [unicode map]]"
86 ;;
87 esac