Test the value of msg_controllen for platforms whose CMSG_FIRSTHDR() does not test...
[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                 "XCBGlxGC_GL_CURRENT_BIT",
23                 "XCBGlxGC_GL_POINT_BIT",
24                 "XCBGlxGC_GL_LINE_BIT",
25                 "XCBGlxGC_GL_POLYGON_BIT",
26                 "XCBGlxGC_GL_POLYGON_STIPPLE_BIT",
27                 "XCBGlxGC_GL_PIXEL_MODE_BIT",
28                 "XCBGlxGC_GL_LIGHTING_BIT",
29                 "XCBGlxGC_GL_FOG_BIT",
30                 "XCBGlxGC_GL_DEPTH_BUFFER_BIT",
31                 "XCBGlxGC_GL_ACCUM_BUFFER_BIT",
32                 "XCBGlxGC_GL_STENCIL_BUFFER_BIT",
33                 "XCBGlxGC_GL_VIEWPORT_BIT",
34                 "XCBGlxGC_GL_TRANSFORM_BIT",
35                 "XCBGlxGC_GL_ENABLE_BIT",
36                 "XCBGlxGC_GL_COLOR_BUFFER_BIT",
37                 "XCBGlxGC_GL_HINT_BIT",
38                 "XCBGlxGC_GL_EVAL_BIT",
39                 "XCBGlxGC_GL_LIST_BIT",
40                 "XCBGlxGC_GL_TEXTURE_BIT",
41                 "XCBGlxGC_GL_SCISSOR_BIT",
42                 "XCBGlxGC_GL_ALL_ATTRIB_BITS",
43                 "XCBGlxRM_GL_RENDER",
44                 "XCBGlxRM_GL_FEEDBACK",
45                 "XCBGlxRM_GL_SELECT",
46         );
47         open(CONST, shift) or die "failed to open constants list: $!";
48         while(<CONST>)
49         {
50                 chomp;
51                 die "invalid constant name: \"$_\"" unless /^XCB[A-Za-z0-9_]*$/;
52                 $::const{$_} = 1;
53         }
54         close(CONST);
55 }
56
57 sub convert($$)
58 {
59         local $_ = shift;
60         my ($fun) = @_;
61
62         return "xcb_generate_id" if /^xcb_[a-z0-9_]+_new$/ or /^XCB[A-Z0-9]+New$/;
63         return "uint$1_t" if /^CARD(8|16|32)$/;
64         return "int$1_t" if /^INT(8|16|32)$/;
65         return "uint8_t" if $_ eq 'BOOL' or $_ eq 'BYTE';
66         return $_ if /^[A-Z0-9]*_[A-Z0-9_]*$/ or !/^XCB(.+)/;
67         my $const = defined $::const{$_};
68         $_ = $1;
69
70         s/^(GX|RandR|XFixes|XP|XvMC|ScreenSaver)(.)/uc($1) . "_" . $2/e unless /^ScreenSaver(?:Reset|Active)$/;
71
72         my %abbr = (
73                 "Iter" => "iterator",
74                 "Req" => "request",
75                 "Rep" => "reply",
76         );
77
78         my $word;
79         if(/CHAR2B|INT64|FLOAT32|FLOAT64|BOOL32|STRING8/)
80         {
81                 $word = qr/[A-Z](?:[A-Z0-9]*|[a-z]*)/;
82         } else {
83                 $word = qr/[0-9]+|[A-Z](?:[A-Z]*|[a-z]*)/;
84         }
85         s/($word)_?(?=[0-9A-Z]|$)/"_" . ($abbr{$1} or lc($1))/eg;
86
87         s/^_shape_shape_/_shape_/;
88         s/^_xf_?86_dri/_xf86dri/;
89         $_ = "_family_decnet" if $_ eq "_family_de_cnet";
90         return "XCB" . uc($_) if $const;
91
92         $_ .= "_t" unless $fun or /_id$/;
93
94         return "xcb" . $_;
95 }
96
97 s/^(\s*#\s*include\s*<)X11\/XCB\//$1xcb\//;
98 s/([_A-Za-z][_A-Za-z0-9]*)([ \t]*\()?/convert($1, defined $2) . ($2 or "")/eg;