2 eval 'exec perl -S $0 ${1+"$@"}'
4 #*************************************************************************
6 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 # Copyright 2008 by Sun Microsystems, Inc.
10 # OpenOffice.org - a multi-platform office productivity suite
12 # $RCSfile: api-to-idl.pl,v $
16 # This file is part of OpenOffice.org.
18 # OpenOffice.org is free software: you can redistribute it and/or modify
19 # it under the terms of the GNU Lesser General Public License version 3
20 # only, as published by the Free Software Foundation.
22 # OpenOffice.org is distributed in the hope that it will be useful,
23 # but WITHOUT ANY WARRANTY; without even the implied warranty of
24 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 # GNU Lesser General Public License version 3 for more details
26 # (a copy is included in the LICENSE file that accompanied this code).
28 # You should have received a copy of the GNU Lesser General Public License
29 # version 3 along with OpenOffice.org. If not, see
30 # <http://www.openoffice.org/license.html>
31 # for a copy of the LGPLv3 License.
33 #*************************************************************************
36 print "Usage: api-to-idl.pl source.api destination_path\n";
38 print "This tool converts oovbaapi *.api files into *.idl's.\n";
45 if ( !defined( $src ) || !defined( $dest ) || $src eq "-h" || $src eq "--help" ) {
57 # Process element start event
58 sub start_element
($) {
61 @element_attr = split( /\s+/, $el );
62 my $element = $element_attr[0];
64 if ( $element eq "element" ) {
65 if ( $element_attr[1] =~ /type="?([^"]*)"?/ && $1 eq "constant" ) {
72 elsif ( $state eq "constant" && $element eq "source" ) {
74 if ( $element_attr[1] =~ /id="?([^"]*)"?/ ) {
75 chomp( $source = $1 );
78 elsif ( $state eq "source" && $element eq "name" ) {
81 elsif ( $state eq "source" && $element eq "value" ) {
86 # Process element end event
90 if ( $state eq "name" && $element eq "name" ) {
93 elsif ( $state eq "value" && $element eq "value" ) {
96 elsif ( $state ne "" && $element eq "element" ) {
99 my @destination = split( /\./, $source );
100 my $module = shift( @destination );
101 my $type = shift( @destination );
103 $module =~ tr/[A-Z]/[a-z]/;
105 $result{$module} = {} unless exists $result{$module};
106 $result{$module}{$type} = [] unless exists $result{$module}{$type};
108 push( @
{$result{$module}{$type}},
109 { "name" => $name, "value" => $value } );
117 if ( $state eq "name" ) {
118 chomp( $name = $data );
120 elsif ( $state eq "value" ) {
121 chomp( $value = $data );
125 # Create idls from the parsed data
126 sub generate_idls
($) {
129 foreach $module ( keys %result ) {
130 foreach $type ( keys %{$result{$module}} ) {
131 my $fname = $path . "/" . $type . ".idl";
132 open( IDL
, ">$fname" ) || die "Cannot write $fname.";
134 if( $module eq "vba" ) {
135 print IDL
"module ooo { module $module {\n";
138 print IDL
"module ooo { module vba { module $module {\n";
141 print IDL
" constants $type {\n";
142 foreach $constant ( @
{$result{$module}{$type}} ) {
143 print IDL
" const long $constant->{'name'} = $constant->{'value'};\n";
145 if( $module eq "vba" ) {
146 print IDL
" };\n}; };\n";
149 print IDL
" };\n}; }; };\n";
158 open( IN
, "<$src" ) || die "Cannot open $src.";
169 elsif ( /-->/ && $in_comment ) {
173 elsif ( $in_comment ) {
180 next if ( $_ eq "" );
182 # take care of lines where element continues
192 my @starts = split( /</, $line );
194 foreach $start ( @starts ) {
195 next if ( $start eq "" );
197 @ends = split( />/, $start );
198 my $element = $ends[0];
201 # start or end element
202 if ( $element =~ /^\/(.*)/ ) {
206 start_element
( $element );
215 # Generate the output
216 generate_idls
($dest);