2 eval 'exec perl -S $0 ${1+"$@"}'
4 #*************************************************************************
6 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 # Copyright 2000, 2010 Oracle and/or its affiliates.
10 # OpenOffice.org - a multi-platform office productivity suite
12 # This file is part of OpenOffice.org.
14 # OpenOffice.org is free software: you can redistribute it and/or modify
15 # it under the terms of the GNU Lesser General Public License version 3
16 # only, as published by the Free Software Foundation.
18 # OpenOffice.org is distributed in the hope that it will be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 # GNU Lesser General Public License version 3 for more details
22 # (a copy is included in the LICENSE file that accompanied this code).
24 # You should have received a copy of the GNU Lesser General Public License
25 # version 3 along with OpenOffice.org. If not, see
26 # <http://www.openoffice.org/license.html>
27 # for a copy of the LGPLv3 License.
29 #*************************************************************************
32 print "Usage: api-to-idl.pl source.api destination_path\n";
34 print "This tool converts oovbaapi *.api files into *.idl's.\n";
41 if ( !defined( $src ) || !defined( $dest ) || $src eq "-h" || $src eq "--help" ) {
53 # Process element start event
54 sub start_element
($) {
57 @element_attr = split( /\s+/, $el );
58 my $element = $element_attr[0];
60 if ( $element eq "element" ) {
61 if ( $element_attr[1] =~ /type="?([^"]*)"?/ && $1 eq "constant" ) {
68 elsif ( $state eq "constant" && $element eq "source" ) {
70 if ( $element_attr[1] =~ /id="?([^"]*)"?/ ) {
71 chomp( $source = $1 );
74 elsif ( $state eq "source" && $element eq "name" ) {
77 elsif ( $state eq "source" && $element eq "value" ) {
82 # Process element end event
86 if ( $state eq "name" && $element eq "name" ) {
89 elsif ( $state eq "value" && $element eq "value" ) {
92 elsif ( $state ne "" && $element eq "element" ) {
95 my @destination = split( /\./, $source );
96 my $module = shift( @destination );
97 my $type = shift( @destination );
99 $module =~ tr/[A-Z]/[a-z]/;
101 $result{$module} = {} unless exists $result{$module};
102 $result{$module}{$type} = [] unless exists $result{$module}{$type};
104 push( @
{$result{$module}{$type}},
105 { "name" => $name, "value" => $value } );
113 if ( $state eq "name" ) {
114 chomp( $name = $data );
116 elsif ( $state eq "value" ) {
117 chomp( $value = $data );
121 # Create idls from the parsed data
122 sub generate_idls
($) {
125 foreach $module ( keys %result ) {
126 foreach $type ( keys %{$result{$module}} ) {
127 my $fname = $path . "/" . $type . ".idl";
128 if ( uc($module) eq "ADODB" || uc($module) eq "DAO" ) {
129 $fname = $path . "/" . uc($module) . "_" . $type . ".idl";
131 open( IDL
, ">$fname" ) || die "Cannot write $fname.";
133 if( $module eq "vba" ) {
134 print IDL
"module ooo { module $module {\n";
137 print IDL
"module ooo { module vba { module $module {\n";
140 print IDL
" constants $type {\n";
141 foreach $constant ( @
{$result{$module}{$type}} ) {
142 print IDL
" const long $constant->{'name'} = $constant->{'value'};\n";
144 if( $module eq "vba" ) {
145 print IDL
" };\n}; };\n";
148 print IDL
" };\n}; }; };\n";
157 open( IN
, "<$src" ) || die "Cannot open $src.";
168 elsif ( /-->/ && $in_comment ) {
172 elsif ( $in_comment ) {
179 next if ( $_ eq "" );
181 # take care of lines where element continues
191 my @starts = split( /</, $line );
193 foreach $start ( @starts ) {
194 next if ( $start eq "" );
196 @ends = split( />/, $start );
197 my $element = $ends[0];
200 # start or end element
201 if ( $element =~ /^\/(.*)/ ) {
205 start_element
( $element );
214 # Generate the output
215 generate_idls
($dest);