diff options
author | Jamey Sharp <jamey@minilop.net> | 2006-09-17 23:38:57 -0700 |
---|---|---|
committer | Jamey Sharp <jamey@minilop.net> | 2006-09-17 23:38:57 -0700 |
commit | 06fba014435cfbdd1ff284d6d513d114503d02c2 (patch) | |
tree | 64c7b2bd1d75b08209777fc7bf035373c30bceb0 | |
parent | bf41af718d6a83532d1c2f63ac16e6484e8e8b68 (diff) |
Complete rewrite of api_conv.pl.
Now handles all API changes except constant names, which are treated like type names.
-rwxr-xr-x | tools/api_conv.pl | 61 |
1 files changed, 18 insertions, 43 deletions
diff --git a/tools/api_conv.pl b/tools/api_conv.pl index c7b97ee..98402bf 100755 --- a/tools/api_conv.pl +++ b/tools/api_conv.pl @@ -1,52 +1,27 @@ -#!/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"); - -while(<>) { - - trans_lines() unless (/#[a-z]/ or /print/ or /\/\// or /\/\*/); - print; -} - -################# -sub trans_lines() +sub convert($$) { - s/XCB/xcb_/g; - - foreach my $xid (@xids) { - if(/$xid/ and /xcb_/) { - my $lcxid = lc($xid); - - #var - my $xidsp = $lcxid . " "; - my $xidspun = $lcxid . "_t "; - - ## - s/$xid/$lcxid/g; - - #var - s/$xidsp/$xidspun/g; - } - } + local $_ = shift; + my ($fun) = @_; - #func without XID in it - if(/xcb_/) { - s/[A-Z]/"_" . lc($&)/eg; - s/__/_/g; + 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(.+)/; + $_ = $1; - if(/event/i) { - $_ = $` . "event" . "_t" . $'; + my %abbr = ( + "Iter" => "iterator", + "Req" => "request", + "Rep" => "reply", + ); - s/__/_/g; - } + s/[A-Z](?:[A-Z0-9]*|[a-z0-9]*)(?=[A-Z]|$)/"_" . ($abbr{$&} or lc($&))/eg; + $_ .= "_t" unless $fun; - #repair NULL's - s/_n_u_l_l/NULL/g; - #repair XCBSCREEN - s/s_c_r_e_e_n/screen/g; - } + return "xcb" . $_; } +s/([_A-Za-z][_A-Za-z0-9]*)([ \t]*\()?/convert($1, defined $2) . ($2 or "")/eg; |