]> Pileus Git - ~andy/gtk/blob - gdk/gdkkeysyms-update.pl
f13671de60fef0f820aa8ff7d9c8f7caec65939d
[~andy/gtk] / gdk / gdkkeysyms-update.pl
1 #!/usr/bin/env perl
2
3 # Updates http://git.gnome.org/cgit/gtk+/tree/gdk/gdkkeysyms.h from upstream (X.org 7.x),
4 # from http://gitweb.freedesktop.org/?p=xorg/proto/x11proto.git;a=blob_plain;f=keysymdef.h
5
6 # Author  : Simos Xenitellis <simos at gnome dot org>.
7 # Authos  : Bastien Nocera <hadess@hadess.net>
8 # Version : 1.2
9 #
10 # Input   : http://gitweb.freedesktop.org/?p=xorg/proto/x11proto.git;a=blob_plain;f=keysymdef.h
11 # Input   : http://gitweb.freedesktop.org/?p=xorg/proto/x11proto.git;a=blob_plain;f=XF86keysym.h
12 # Output  : http://git.gnome.org/cgit/gtk+/tree/gdk/gdkkeysyms.h
13
14 # Notes   : It downloads keysymdef.h from the Internet, if not found locally,
15 # Notes   : and creates an updated gdkkeysyms.h
16 # Notes   : This version updates the source of gdkkeysyms.h from CVS to the GIT server.
17
18 use strict;
19
20 # Used for reading the keysymdef symbols.
21 my @keysymelements;
22
23 if ( ! -f "keysymdef.h" )
24 {
25         print "Trying to download keysymdef.h from\n";
26         print "http://gitweb.freedesktop.org/?p=xorg/proto/x11proto.git;a=blob_plain;f=keysymdef.h\n";
27         die "Unable to download keysymdef.h from http://gitweb.freedesktop.org/?p=xorg/proto/x11proto.git;a=blob_plain;f=keysymdef.h\n" 
28                 unless system("wget -c -O keysymdef.h \"http://gitweb.freedesktop.org/?p=xorg/proto/x11proto.git;a=blob_plain;f=keysymdef.h\"") == 0;
29         print " done.\n\n";
30 }
31 else
32 {
33         print "We are using existing keysymdef.h found in this directory.\n";
34         print "It is assumed that you took care and it is a recent version\n";
35         print "as found at http://gitweb.freedesktop.org/?p=xorg/proto/x11proto.git;a=blob;f=keysymdef.h\n\n";
36 }
37
38 if ( ! -f "XF86keysym.h" )
39 {
40         print "Trying to download XF86keysym.h from\n";
41         print "http://gitweb.freedesktop.org/?p=xorg/proto/x11proto.git;a=blob_plain;f=XF86keysym.h\n";
42         die "Unable to download keysymdef.h from http://gitweb.freedesktop.org/?p=xorg/proto/x11proto.git;a=blob_plain;f=XF86keysym.h\n" 
43                 unless system("wget -c -O XF86keysym.h \"http://gitweb.freedesktop.org/?p=xorg/proto/x11proto.git;a=blob_plain;f=XF86keysym.h\"") == 0;
44         print " done.\n\n";
45 }
46 else
47 {
48         print "We are using existing XF86keysym.h found in this directory.\n";
49         print "It is assumed that you took care and it is a recent version\n";
50         print "as found at http://gitweb.freedesktop.org/?p=xorg/proto/x11proto.git;a=blob;f=XF86keysym.h\n\n";
51 }
52
53 if ( -f "gdkkeysyms.h" )
54 {
55         print "There is already a gdkkeysyms.h file in this directory. We are not overwriting it.\n";
56         print "Please move it somewhere else in order to run this script.\n";
57         die "Exiting...\n\n";
58 }
59
60 # Source: http://gitweb.freedesktop.org/?p=xorg/proto/x11proto.git;a=blob;f=keysymdef.h
61 die "Could not open file keysymdef.h: $!\n" unless open(IN_KEYSYMDEF, "<:utf8", "keysymdef.h");
62
63 # Output: gtk+/gdk/gdkkeysyms.h
64 die "Could not open file gdkkeysyms.h: $!\n" unless open(OUT_GDKKEYSYMS, ">:utf8", "gdkkeysyms.h");
65
66 # Output: gtk+/gdk/gdkkeysyms-compat.h
67 die "Could not open file gdkkeysyms-compat.h: $!\n" unless open(OUT_GDKKEYSYMS_COMPAT, ">:utf8", "gdkkeysyms-compat.h");
68
69 my $LICENSE_HEADER= <<EOF;
70 /* GDK - The GIMP Drawing Kit
71  * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
72  * Copyright (C) 2005, 2006, 2007, 2009 GNOME Foundation
73  *
74  * This library is free software; you can redistribute it and/or
75  * modify it under the terms of the GNU Lesser General Public
76  * License as published by the Free Software Foundation; either
77  * version 2 of the License, or (at your option) any later version.
78  *
79  * This library is distributed in the hope that it will be useful,
80  * but WITHOUT ANY WARRANTY; without even the implied warranty of
81  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
82  * Lesser General Public License for more details.
83  *
84  * You should have received a copy of the GNU Lesser General Public
85  * License along with this library; if not, write to the
86  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
87  * Boston, MA 02111-1307, USA.
88  */
89
90 EOF
91
92 print OUT_GDKKEYSYMS $LICENSE_HEADER;
93 print OUT_GDKKEYSYMS_COMPAT $LICENSE_HEADER;
94
95 print OUT_GDKKEYSYMS<<EOF;
96
97 /*
98  * File auto-generated from script http://git.gnome.org/cgit/gtk+/tree/gdk/gdkkeysyms-update.pl
99  * using the input file
100  * http://gitweb.freedesktop.org/?p=xorg/proto/x11proto.git;a=blob_plain;f=keysymdef.h
101  * and
102  * http://gitweb.freedesktop.org/?p=xorg/proto/x11proto.git;a=blob_plain;f=XF86keysym.h
103  */
104
105 /*
106  * Modified by the GTK+ Team and others 1997-2007.  See the AUTHORS
107  * file for a list of people on the GTK+ Team.  See the ChangeLog
108  * files for a list of changes.  These files are distributed with
109  * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
110  */
111
112 #ifndef __GDK_KEYSYMS_H__
113 #define __GDK_KEYSYMS_H__
114
115
116 EOF
117
118 print OUT_GDKKEYSYMS_COMPAT<<EOF;
119 /*
120  * Compatibility version of gdkkeysyms.h.
121  *
122  * In GTK3, keysyms changed to have a KEY_ prefix.  This is a compatibility header
123  * your application can include to gain access to the old names as well.  Consider
124  * porting to the new names instead.
125  */
126
127 #ifndef __GDK_KEYSYMS_COMPAT_H__
128 #define __GDK_KEYSYMS_COMPAT_H__
129
130 EOF
131
132 while (<IN_KEYSYMDEF>)
133 {
134         next if ( ! /^#define / );
135
136         @keysymelements = split(/\s+/);
137         die "Internal error, no \@keysymelements: $_\n" unless @keysymelements;
138
139         $_ = $keysymelements[1];
140         die "Internal error, was expecting \"XC_*\", found: $_\n" if ( ! /^XK_/ );
141         
142         $_ = $keysymelements[2];
143         die "Internal error, was expecting \"0x*\", found: $_\n" if ( ! /^0x/ );
144
145         my $element = $keysymelements[1];
146         my $binding = $element;
147         $binding =~ s/^XK_/GDK_KEY_/g;
148         my $compat_binding = $element;
149         $compat_binding =~ s/^XK_/GDK_/g;
150
151         printf OUT_GDKKEYSYMS "#define %s 0x%03x\n", $binding, hex($keysymelements[2]);
152         printf OUT_GDKKEYSYMS_COMPAT "#define %s 0x%03x\n", $compat_binding, hex($keysymelements[2]);
153 }
154
155 close IN_KEYSYMDEF;
156
157 #$gdksyms{"0"} = "0000";
158
159 # Source: http://gitweb.freedesktop.org/?p=xorg/proto/x11proto.git;a=blob;f=XF86keysym.h
160 die "Could not open file XF86keysym.h: $!\n" unless open(IN_XF86KEYSYM, "<:utf8", "XF86keysym.h");
161
162 while (<IN_XF86KEYSYM>)
163 {
164         next if ( ! /^#define / );
165
166         @keysymelements = split(/\s+/);
167         die "Internal error, no \@keysymelements: $_\n" unless @keysymelements;
168
169         $_ = $keysymelements[1];
170         die "Internal error, was expecting \"XF86XK_*\", found: $_\n" if ( ! /^XF86XK_/ );
171
172         # Work-around https://bugs.freedesktop.org/show_bug.cgi?id=11193
173         if ($_ eq "XF86XK_XF86BackForward") {
174                 $keysymelements[1] = "XF86XK_AudioForward";
175         }
176         # XF86XK_Clear could end up a dupe of XK_Clear
177         # XF86XK_Select could end up a dupe of XK_Select
178         if ($_ eq "XF86XK_Clear") {
179                 $keysymelements[1] = "XF86XK_WindowClear";
180         }
181         if ($_ eq "XF86XK_Select") {
182                 $keysymelements[1] = "XF86XK_SelectButton";
183         }
184
185         # Ignore XF86XK_Q
186         next if ( $_ eq "XF86XK_Q");
187         # XF86XK_Calculater is misspelled, and a dupe
188         next if ( $_ eq "XF86XK_Calculater");
189
190         $_ = $keysymelements[2];
191         die "Internal error, was expecting \"0x*\", found: $_\n" if ( ! /^0x/ );
192
193         my $element = $keysymelements[1];
194         my $binding = $element;
195         $binding =~ s/^XF86XK_/GDK_KEY_/g;
196         my $compat_binding = $element;
197         $compat_binding =~ s/^XF86XK_/GDK_/g;
198
199         printf OUT_GDKKEYSYMS "#define %s 0x%03x\n", $binding, hex($keysymelements[2]);
200         printf OUT_GDKKEYSYMS_COMPAT "#define %s 0x%03x\n", $compat_binding, hex($keysymelements[2]);
201 }
202
203 close IN_XF86KEYSYM;
204
205
206 print OUT_GDKKEYSYMS<<EOF;
207
208 #endif /* __GDK_KEYSYMS_H__ */
209 EOF
210
211 print OUT_GDKKEYSYMS_COMPAT<<EOF;
212
213 #endif /* __GDK_KEYSYMS_COMPAT_H__ */
214 EOF
215
216 printf "We just finished converting keysymdef.h to gdkkeysyms.h and gdkkeysyms-compat.h\nThank you\n";