X-Git-Url: http://git.demorecorder.com/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=tools%2Fapi_conv.pl;h=2e6a1d0610ba6c5dc62d7ec82ae91035ea1f7157;hb=c912187f15c560c46768acb88aae30e67b0f78ce;hp=36f45ea3b751e932c89ada112c412b2322d2eef7;hpb=cdffbdd7ef9dee58b3c36ca46bb88aa187b46526;p=free-sw%2Fxcb%2Flibxcb diff --git a/tools/api_conv.pl b/tools/api_conv.pl old mode 100644 new mode 100755 index 36f45ea..2e6a1d0 --- a/tools/api_conv.pl +++ b/tools/api_conv.pl @@ -1,77 +1,50 @@ -#!/usr/bin/perl -w +#!/usr/bin/perl -plw use strict; -sub trans_lines($); - -my @xids=("WINDOW","VISUALTYPE","DRAWABLE","FONT","ATOM","COLORMAP","FONTABLE","GCONTEXT","PIXMAP","SCREEN"); - -my $input = $ARGV[0]; - -open(INFILE,"<",$input) or die("Couldn't open file $input.\n"); - -my @in_data = ; -my @out_data; - -foreach my $line (@in_data) { - - if($line =~ /#[a-z]/ or $line =~ /print/ or $line =~ /\/\// or $line =~ /\/\*/) { - $out_data[@out_data] = $line; - next; +BEGIN { + %::const = map { $_ => 1 } ( + "XCBNone", + "XCBCopyFromParent", + "XCBCurrentTime", + "XCBNoSymbol", + "XCBError", + "XCBReply", + ); + open(CONST, shift) or die "failed to open constants list: $!"; + while() + { + chomp; + die "invalid constant name: \"$_\"" unless /^XCB[A-Za-z0-9_]*$/; + $::const{$_} = 1; } - - trans_lines($line); + close(CONST); } - -foreach my $newline (@out_data) { - print $newline; -} - -################# -sub trans_lines($) +sub convert($$) { - my $line = $_[0]; - - $line =~ s/XCB/xcb_/g; - - foreach my $xid (@xids) { - if($line =~ /$xid/ and $line =~ /xcb_/) { - my $lcxid = lc($xid); - - #var - my $xidsp = $lcxid . " "; - my $xidspun = $lcxid . "_t "; - - ## - $line =~ s/$xid/$lcxid/g; + local $_ = shift; + my ($fun) = @_; - #var - $line =~ s/$xidsp/$xidspun/g; - } - } - - #func without XID in it - my $funcline = $line; + return "uint$1_t" if /^CARD(8|16|32)$/; + return "int$1_t" if /^INT(8|16|32)$/; + return "uint8_t" if $_ eq 'BOOL' or $_ eq 'BYTE'; + return $_ if /_/ or !/^XCB(.+)/; + my $const = defined $::const{$_}; + $_ = $1; - if($funcline =~ /xcb_/) { - $funcline =~ s/[A-Z]/"_" . lc($&)/eg; - $funcline =~ s/__/_/g; + my %abbr = ( + "Iter" => "iterator", + "Req" => "request", + "Rep" => "reply", + ); - if($funcline =~ /event/i) { - $funcline =~ /event/i; - $funcline = $` . "event" . "_t" . $'; + s/[A-Z](?:[A-Z0-9]*|[a-z0-9]*)(?=[A-Z]|$)/"_" . ($abbr{$&} or lc($&))/eg; - $funcline =~ s/__/_/g; - } + return "XCB" . uc($_) if $const; - #repair NULL's - $funcline =~ s/_n_u_l_l/NULL/g; - #repair XCBSCREEN - $funcline =~ s/s_c_r_e_e_n/screen/g; - } + $_ .= "_t" unless $fun; - $line = $funcline; - - $out_data[@out_data] = $line; + return "xcb" . $_; } +s/([_A-Za-z][_A-Za-z0-9]*)([ \t]*\()?/convert($1, defined $2) . ($2 or "")/eg;