Handle remaining incorrect API translations in api_conv.pl.
[free-sw/xcb/libxcb] / tools / api_conv.pl
1 #!/usr/bin/perl -plw
2 use strict;
3
4 BEGIN {
5         %::const = map { $_ => 1 } (
6                 # constants in xcb.h
7                 "XCBNone",
8                 "XCBCopyFromParent",
9                 "XCBCurrentTime",
10                 "XCBNoSymbol",
11                 "XCBError",
12                 "XCBReply",
13                 # renamed constants
14                 "XCBButtonAny",
15                 "XCBButton1",
16                 "XCBButton2",
17                 "XCBButton3",
18                 "XCBButton4",
19                 "XCBButton5",
20                 "XCBHostInsert",
21                 "XCBHostDelete",
22         );
23         open(CONST, shift) or die "failed to open constants list: $!";
24         while(<CONST>)
25         {
26                 chomp;
27                 die "invalid constant name: \"$_\"" unless /^XCB[A-Za-z0-9_]*$/;
28                 $::const{$_} = 1;
29         }
30         close(CONST);
31 }
32
33 sub convert($$)
34 {
35         local $_ = shift;
36         my ($fun) = @_;
37
38         return "uint$1_t" if /^CARD(8|16|32)$/;
39         return "int$1_t" if /^INT(8|16|32)$/;
40         return "uint8_t" if $_ eq 'BOOL' or $_ eq 'BYTE';
41         return $_ if /^[A-Z]*_[A-Z_]*$/ or !/^XCB(.+)/;
42         my $const = defined $::const{$_};
43         $_ = $1;
44
45         s/^(GX|RandR|XFixes|XP|XvMC)(.)/uc($1) . "_" . $2/e;
46
47         my %abbr = (
48                 "Iter" => "iterator",
49                 "Req" => "request",
50                 "Rep" => "reply",
51         );
52
53         s/([0-9]+|[A-Z](?:[A-Z]*|[a-z]*))_?(?=[0-9A-Z]|$)/"_" . ($abbr{$1} or lc($1))/eg;
54
55         $_ = "_family_decnet" if $_ eq "_family_de_cnet";
56         return "XCB" . uc($_) if $const;
57
58         $_ .= "_t" unless $fun or /_id$/;
59
60         return "xcb" . $_;
61 }
62
63 s/([_A-Za-z][_A-Za-z0-9]*)([ \t]*\()?/convert($1, defined $2) . ($2 or "")/eg;