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
|
#!/usr/bin/perl -w
if (@ARGV != 2) {
die "Usage: gen-keyname-table.pl keynames.txt keynames-translate.txt > keyname-table.h\n";
}
open IN, $ARGV[0] || die "Cannot open $ARGV[0]: $!\n";
@keys = ();
@translate = ();
while (defined($_ = <IN>)) {
next if /^!/;
if (!/^\s*(0x[0-9a-f]+)\s+([\w_]*\S)\s+(1)?\s*$/) {
die "Cannot parse line $_";
}
push @keys, [$1, $2];
if (defined ($3)) {
push @translate, $2;
}
}
close IN;
open IN, $ARGV[1] || die "Cannot open $ARGV[1]: $!\n";
while (defined($_ = <IN>)) {
next if /^!/;
if (!/^\s*([\w_]*\S)\s+$/) {
die "Cannot parse line $_";
}
push @translate, $1;
}
close IN;
$offset = 0;
$date = gmtime;
print <<EOT;
/* keyname-table.h: Generated by gen-keyname-table.pl from keynames.txt
*
* Date: $date
*
* Do not edit.
*/
static const char keynames[] =
EOT
for $key (@keys) {
$name = $key->[1];
if ($offset != 0) {
print qq(\n);
}
print qq( "$name\\0");
$key->[3] = $offset;
$offset += length($name) + 1;
}
print ";\n\n";
print <<EOT;
typedef struct {
guint keyval;
guint offset;
} gdk_key;
static const gdk_key gdk_keys_by_keyval[] = {
EOT
$i = 0;
for $key (@keys) {
$keyval = $key->[0];
$name = $key->[1];
$offset = $key->[3];
if ($i != 0) {
print ",\n";
}
print " { $keyval, $offset }";
$i++;
}
print "\n};\n\n";
@keys = sort { $a->[1] cmp $b->[1] } @keys;
print <<EOT;
static const gdk_key gdk_keys_by_name[] = {
EOT
$i = 0;
for $key (@keys) {
$keyval = $key->[0];
$name = $key->[1];
$offset = $key->[3];
if ($i != 0) {
print ",\n";
}
print " { $keyval, $offset }";
$i++;
}
print <<EOT;
};
#if 0
/*
* Translators, the strings in the 'keyboard label' context are
* display names for keyboard keys. Some of them have prefixes like
* XF86 or ISO_ - these should be removed in the translation. Similarly,
* underscores should be replaced by spaces. The prefix 'KP_' stands
* for 'key pad' and you may want to include that in your translation.
* Here are some examples of English translations:
* XF86AudioMute - Audio mute
* Scroll_lock - Scroll lock
* KP_Space - Space (keypad)
*/
EOT
for $key (@translate) {
if ($key eq 'KP_Space') {
print "/* Translators: KP_ means 'key pad' here */\n";
}
if ($key eq 'XF86MonBrightnessUp') {
print "/* Translators: 'Mon' means Monitor here, and the XF86 prefix should be removed */\n";
}
print <<EOT;
NC_("keyboard label", "$key")
EOT
}
print <<EOT;
#endif
EOT
|