File: ckbcomp-mini

package info (click to toggle)
console-setup 1.244
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 28,124 kB
  • sloc: perl: 10,288; xml: 8,643; sh: 3,901; makefile: 777
file content (231 lines) | stat: -rwxr-xr-x 5,723 bytes parent folder | download | duplicates (4)
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
#!/bin/sh

#     ckbcomp-mini -- convert XKB specification to loadkeys/kbdcontrol format
#     Copyright (c) 2006,2009,2011 Anton Zinoviev <anton@lml.bas.bg>

#     Permission is hereby granted, free of charge, to any person
#     obtaining a copy of this file (the "Program"), to deal in the
#     Program without restriction, including without limitation the
#     rights to use, copy, modify, merge, publish, distribute,
#     sublicense, and/or sell copies of the Program, and to permit
#     persons to whom the Program is furnished to do so, subject to
#     the following conditions: The above copyright notice and this
#     permission notice shall be included in all copies or substantial
#     portions of the Program.

#     THE PROGRAM IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
#     EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
#     OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
#     NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
#     HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
#     WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
#     FROM, OUT OF OR IN CONNECTION WITH THE PROGRAM OR THE USE OR
#     OTHER DEALINGS IN THE PROGRAM.

# Default values:
model=pc105
layout=''
variant=''
options=''
charmap=''
compose_charmap=''
freebsd=''
verbose_option=no

installdir=${0%/*}
case "$installdir" in
    */bin) installdir=${installdir%/bin} ;;
    *) installdir=$installdir/.. ;;
esac
datadir=$installdir/share/console-setup
[ -d "$datadir" ] || datadir=/usr/share/console-setup

# The same as /usr/bin/which - in order to make "which" available in
# environments where "which" does not exist
which () {
    local IFS
    IFS=:
    for i in $PATH; do
	if [ -x "$i/$1" ]; then
	    echo "$i/$1"
	    return 0
	fi
    done
    return 1
}

while [ "$*" ]; do
    case "$1" in
	-I*)
	    datadir=${1#-I}
	    ;;
	-model)
	    shift
	    model="$1"
	    ;;
	-layout)
	    shift
	    layout=">$1"
	    ;;
	-variant)
	    shift
	    variant=">$1"
	    ;;
	-option)
	    shift
	    options=$(echo $options $1 | sed 's/,/ /g')
	    ;;
	-charmap)
	    shift
            charmap=`echo "$1"|sed 's/-//g'`
	    ;;
	-ccharmap)
	    shift
            compose_charmap=`echo "$1"|sed 's/-//g'`
	    ;;
	-backspace)
	    shift
	    ;;
	-freebsd)
            freebsd=yes
	    ;;
	-\?|-help)
	    cat >&2 <<EOF
Usage: ckbcomp-mini [args] [<layout> [<variant> [<option> ... ]]]
Where legal args are:
-?,-help            Print this message
-charmap <name>     Specifies the encoding to use
-ccharmap <name>    Specifies the encoding to use for compose sequences
-I<dir>             Search for ekmaps in <dir>
-model <name>       Specifies model used to choose component names
-layout <name>      Specifies layout used to choose component names
-variant <name>     Specifies layout variant used to choose component names
-option <name>      Adds an option used to choose component names
-freebsd            Generate a keymap for FreeBSD
-backspace <type>   Ignored
EOF
	    exit 0
	    ;;
	-*)
	    echo "ckbcomp-mini: Unrecognised option $1" >&2
	    exit 1
	    ;;
	*)
	    if [ -z "$layout" ]; then
		layout=">$1"
	    elif [ -z "$variant" ]; then
		variant=">$1"
	    else
		options=$(echo $options $1 | sed 's/,/ /g')
	    fi
    esac
    shift
done

layout=${layout#>}
variant=${variant#>}

case "$model" in
    amiga|ataritt|pc105|sun4|sun5)
	;;
    *)
	model=pc105
	;;
esac

if [ -z "$layout" ]; then
    layout=us
fi

if [ "$freebsd" ]; then
    ekmap=$datadir/$model.ekbd.gz
else
    ekmap=$datadir/$model.ekmap.gz
fi

if [ ! -f $ekmap ]; then
    echo "ckbcomp-mini: $ekmap does not exist" >&2
    exit 1
fi

layout=${layout#*,}
variant=${variant#*,}

ckbcomp_rec () {
    local kmap
    kmap="$1"
    zcat $ekmap \
	| grep "^$kmap::" \
	| sed "s/^$kmap:://" \
	| {
	    while read line; do
		case "$line" in
		    ?include*)
			ckbcomp_rec "${line##* }"
                        ;;
		    *)
			echo "$line"
			;;
		    esac
	    done
	  }
}

utf_keymap () {
    if [ -z "$freebsd" ]; then
        echo 'keymaps 0-4,6,8,10,12,14'
    fi
    ckbcomp_rec "$layout:$variant"
    for option in $options; do
        zcat $ekmap \
	    | grep "^$option::" \
	    | sed "s/^$option:://"
    done
    if [ -z "$compose_charmap" -a -n "$charmap" ]; then
	compose_charmap=$charmap
    fi
    if [ -n "$freebsd" -a -n "$compose_charmap" ]; then
        file1="/etc/console-setup/dkey.${compose_charmap}.inc"
        file2="$installdir/etc/console-setup/dkey.${compose_charmap}.inc"
        if [ -f "$file1" ]; then
            cat "$file1"
        elif [ -f "$file2" ]; then
            cat "$file2"
        fi
    fi
    if [ -z "$freebsd" ]; then
        echo 'strings as usual'
        if [ -n "$compose_charmap" ]; then
            file1="/etc/console-setup/compose.${compose_charmap}.inc"
            file2="$installdir/etc/console-setup/compose.${compose_charmap}.inc"
            if [ -f "$file1" ]; then
                cat "$file1"
            elif [ -f "$file2" ]; then
                cat "$file2"
            fi
        fi
    fi
}

if [ "$charmap" ]; then
    if [ -f $datadir/charmap_functions.sh ]; then
        . $datadir/charmap_functions.sh
    else
        echo $charmap is not supported >&2
        exit 1
    fi
    utf_keymap \
        | while read x; do
              line=''
              for i in $x; do
                  case $i in
                      +U+????) line="$line+`to_$charmap ${i#+U+}` " ;;
                      U+????) line="$line`to_$charmap ${i#U+}` " ;;
                      *) line="$line$i " ;;
                  esac
              done
              echo $line
          done
else
    utf_keymap
fi