2005-03-08 04:35:29 +00:00
|
|
|
#!/usr/bin/perl -w
|
|
|
|
|
2011-10-25 13:34:27 +00:00
|
|
|
if (@ARGV != 2) {
|
2022-09-24 13:20:12 +00:00
|
|
|
die "Usage: gen-keyname-table.pl keynames.txt keynames-translate.txt > keynamesprivate.h\n";
|
2005-03-08 04:35:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
open IN, $ARGV[0] || die "Cannot open $ARGV[0]: $!\n";
|
|
|
|
|
|
|
|
@keys = ();
|
2005-06-10 06:41:04 +00:00
|
|
|
@translate = ();
|
2005-03-08 04:35:29 +00:00
|
|
|
while (defined($_ = <IN>)) {
|
|
|
|
next if /^!/;
|
2005-06-10 06:41:04 +00:00
|
|
|
if (!/^\s*(0x[0-9a-f]+)\s+([\w_]*\S)\s+(1)?\s*$/) {
|
2005-03-08 04:35:29 +00:00
|
|
|
die "Cannot parse line $_";
|
|
|
|
}
|
|
|
|
|
|
|
|
push @keys, [$1, $2];
|
2005-06-10 06:41:04 +00:00
|
|
|
|
|
|
|
if (defined ($3)) {
|
|
|
|
push @translate, $2;
|
|
|
|
}
|
2005-03-08 04:35:29 +00:00
|
|
|
}
|
2011-10-25 13:34:27 +00:00
|
|
|
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;
|
2005-03-08 04:35:29 +00:00
|
|
|
|
|
|
|
$offset = 0;
|
|
|
|
|
|
|
|
$date = gmtime;
|
|
|
|
|
|
|
|
print <<EOT;
|
2022-09-24 13:20:12 +00:00
|
|
|
/* keynamesprivate.h: Generated by gen-keyname-table.pl from keynames.txt
|
2005-03-08 04:35:29 +00:00
|
|
|
*
|
|
|
|
* 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 {
|
2024-09-25 00:04:51 +00:00
|
|
|
unsigned int keyval;
|
|
|
|
unsigned int offset;
|
2005-03-08 04:35:29 +00:00
|
|
|
} 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++;
|
|
|
|
}
|
|
|
|
|
2005-06-10 06:41:04 +00:00
|
|
|
print <<EOT;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
|
2011-10-25 13:34:27 +00:00
|
|
|
/*
|
|
|
|
* 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)
|
|
|
|
*/
|
2005-06-10 06:41:04 +00:00
|
|
|
EOT
|
|
|
|
|
|
|
|
for $key (@translate) {
|
2011-10-25 13:34:27 +00:00
|
|
|
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";
|
|
|
|
}
|
2005-06-10 06:41:04 +00:00
|
|
|
print <<EOT;
|
2011-10-25 13:34:27 +00:00
|
|
|
NC_("keyboard label", "$key")
|
2005-06-10 06:41:04 +00:00
|
|
|
EOT
|
2011-10-25 13:34:27 +00:00
|
|
|
}
|
2005-06-10 06:41:04 +00:00
|
|
|
|
|
|
|
print <<EOT;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
EOT
|
2005-03-08 04:35:29 +00:00
|
|
|
|