]> Pileus Git - ~andy/gtk/blob - gdk/gen-keyname-table.pl
stylecontext: Do invalidation on first resize container
[~andy/gtk] / gdk / gen-keyname-table.pl
1 #!/usr/bin/perl -w
2
3 if (@ARGV != 2) {
4     die "Usage: gen-keyname-table.pl keynames.txt keynames-translate.txt > keyname-table.h\n";
5 }
6
7 open IN, $ARGV[0] || die "Cannot open $ARGV[0]: $!\n";
8
9 @keys = ();
10 @translate = ();
11 while (defined($_ = <IN>)) {
12     next if /^!/;
13     if (!/^\s*(0x[0-9a-f]+)\s+([\w_]*\S)\s+(1)?\s*$/) {
14         die "Cannot parse line $_";
15     }
16
17     push @keys, [$1, $2];
18
19     if (defined ($3)) {
20         push @translate, $2;
21     }
22 }
23 close IN;
24
25 open IN, $ARGV[1] || die "Cannot open $ARGV[1]: $!\n";
26 while (defined($_ = <IN>)) {
27     next if /^!/;
28     if (!/^\s*([\w_]*\S)\s+$/) {
29         die "Cannot parse line $_";
30     }
31
32     push @translate, $1;
33 }
34 close IN;
35
36 $offset = 0;
37
38 $date = gmtime;
39
40 print <<EOT;
41 /* keyname-table.h: Generated by gen-keyname-table.pl from keynames.txt
42  *
43  *  Date: $date
44  *
45  * Do not edit.   
46  */
47 static const char keynames[] =
48 EOT
49
50 for $key (@keys) {
51     $name = $key->[1];
52
53     if ($offset != 0) {
54         print qq(\n);
55     }
56     print qq(  "$name\\0");
57
58     $key->[3] = $offset;
59     $offset += length($name) + 1;
60 }
61
62 print ";\n\n";
63
64 print <<EOT;
65 typedef struct {
66     guint  keyval;
67     guint  offset;
68 } gdk_key;
69
70 static const gdk_key gdk_keys_by_keyval[] = {
71 EOT
72
73 $i = 0;
74 for $key (@keys) {
75     $keyval = $key->[0];
76     $name = $key->[1];
77     $offset = $key->[3];
78
79     if ($i != 0) {
80         print ",\n";
81     }
82     print "  { $keyval, $offset }";
83     $i++;
84 }
85
86 print "\n};\n\n";
87
88 @keys = sort { $a->[1] cmp $b->[1] } @keys;
89
90
91 print <<EOT;
92 static const gdk_key gdk_keys_by_name[] = {
93 EOT
94
95 $i = 0;
96 for $key (@keys) {
97     $keyval = $key->[0];
98     $name = $key->[1];
99     $offset = $key->[3];
100
101     if ($i != 0) {
102         print ",\n";
103     }
104     print "  { $keyval, $offset }";
105     $i++;
106 }
107
108 print <<EOT;
109 };
110
111
112 #if 0
113
114 /*
115  * Translators, the strings in the 'keyboard label' context are
116  * display names for keyboard keys. Some of them have prefixes like
117  * XF86 or ISO_ - these should be removed in the translation. Similarly,
118  * underscores should be replaced by spaces. The prefix 'KP_' stands
119  * for 'key pad' and you may want to include that in your translation.
120  * Here are some examples of English translations:
121  * XF86AudioMute - Audio mute
122  * Scroll_lock   - Scroll lock
123  * KP_Space      - Space (keypad)
124  */
125 EOT
126
127 for $key (@translate) {
128     if ($key eq 'KP_Space') {
129       print "/* Translators: KP_ means 'key pad' here */\n";
130     }
131     if ($key eq 'XF86MonBrightnessUp') {
132       print "/* Translators: 'Mon' means Monitor here, and the XF86 prefix should be removed */\n";
133     }
134     print <<EOT;
135 NC_("keyboard label", "$key")
136 EOT
137 }
138
139 print <<EOT;
140
141 #endif
142 EOT
143