First set of licensing changes
[mono.git] / mcs / class / Mono.WebBrowser / tools / xpidl2cs / xpidl2cs.pl
index 4a9fb3e84034602f8a708b0f4ae5241aaa49ed0a..0e2a01190908f45ca20d357485ac7db8c67c57d8 100755 (executable)
@@ -6,29 +6,18 @@
 #
 # Copyright (c) 2007 Novell, Inc.
 #
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of version 2 of the GNU General Public
-# License as published by the Free Software Foundation.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# General Public License for more details.
-#
-# You should have received a copy of the GNU General Public
-# License along with this program; if not, write to the
-# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-# Boston, MA 02111-1307, USA.
-##############################################################
+# Licensed under the MIT license. See LICENSE file in the project root for full license information.
+
 
-die "Usage: xpidl2cs.pl file.idl [/path/to/idl/]" if scalar(@ARGV) < 1;
 
-my $file = shift;
-my $path = shift if scalar(@ARGV) > 0;
-my $nosig = shift if scalar(@ARGV) > 0;
-$nosig = "" if !$nosig;
 
-open FILE, '<', $path.$file or die "Can't open file $path$file";
+my $file;
+my $path;
+my $nosig;
+my $_class;
+my %opt=();
+
+#open FILE, '<', $path.$file or die "Can't open file $path$file";
 
 my %interface = (
                 properties => (), 
@@ -45,11 +34,16 @@ my %methods = {
 
 my %types;
 $types{"short"} = {name => "short", out => "out", marshal => ""};
+$types{"PRUint8"} = {name => "char", out => "out", marshal => ""};
+$types{"PRInt8"} = {name => "char", out => "out", marshal => ""};
 $types{"unsigned,short"} = {name => "ushort", out => "out", marshal => ""};
+$types{"PRUint16"} = {name => "ushort", out => "out", marshal => ""};
+$types{"PRInt16"} = {name => "short", out => "out", marshal => ""};
 $types{"int"} = {name => "int", out => "out", marshal => ""};
 $types{"nsresult"} = {name => "int", out => "out", marshal => ""};
 $types{"unsigned,int"} = {name => "uint", out => "out", marshal => ""};
 $types{"PRUint32"} = {name => "UInt32", out => "out", marshal => ""};
+$types{"PRInt32"} = {name => "Int32", out => "out", marshal => ""};
 $types{"PRInt64"} = {name => "long", out => "out", marshal => ""};
 $types{"long"} = {name => "int", out => "out", marshal => ""};
 $types{"size_t"} = {name => "int", out => "out", marshal => ""};
@@ -59,31 +53,39 @@ $types{"boolean"} = {name => "bool", out => "out", marshal => ""};
 $types{"PRBool"} = {name => "bool", out => "out", marshal => ""};
 $types{"void"} = {name => "", out => "", marshal => ""};
 $types{"octet"} = {name => "byte", out => "out", marshal => ""};
+$types{"octet[]"} = {name => "IntPtr", out => "out", marshal => " "};
 $types{"byte"} = {name => "byte", out => "out", marshal => ""};
 $types{"DOMString"} = {name => "/*DOMString*/ HandleRef", out => "", marshal => ""};
 $types{"AUTF8String"} = {name => "/*AUTF8String*/ HandleRef", out => "", marshal => ""};
 $types{"ACString"} = {name => "/*ACString*/ HandleRef", out => "", marshal => ""};
 $types{"AString"} = {name => "/*AString*/ HandleRef", out => "", marshal => ""};
-$types{"wstring"} = {name => "string", out => "", marshal => "MarshalAs(UnmanagedType.LPWStr) "};
-$types{"nsCIDRef"} = {name => "Guid", out => "out", marshal => "MarshalAs (UnmanagedType.LPStruct) "};
-$types{"nsIIDRef"} = {name => "Guid", out => "out", marshal => "MarshalAs (UnmanagedType.LPStruct) "};
-$types{"Guid"} = {name => "Guid", out => "out", marshal => "MarshalAs (UnmanagedType.LPStruct) "};
-$types{"nsCID"} = {name => "Guid", out => "out", marshal => "MarshalAs (UnmanagedType.LPStruct) "};
-$types{"nsCIDPtr"} = {name => "Guid", out => "out", marshal => "MarshalAs (UnmanagedType.LPStruct) "};
-$types{"string"} = {name => "string", out => "ref", marshal => "MarshalAs (UnmanagedType.LPStr) "};
+$types{"wstring"} = {name => "string", out => "", marshal => "MarshalAs(UnmanagedType.LPWStr)"};
+$types{"nsCIDRef"} = {name => "Guid", out => "out", marshal => "MarshalAs (UnmanagedType.LPStruct)"};
+$types{"nsIIDRef"} = {name => "Guid", out => "out", marshal => "MarshalAs (UnmanagedType.LPStruct)"};
+$types{"Guid"} = {name => "Guid", out => "out", marshal => "MarshalAs (UnmanagedType.LPStruct)"};
+$types{"nsCID"} = {name => "Guid", out => "out", marshal => "MarshalAs (UnmanagedType.LPStruct)"};
+$types{"nsCIDPtr"} = {name => "Guid", out => "out", marshal => "MarshalAs (UnmanagedType.LPStruct)"};
+$types{"string"} = {name => "string", out => "ref", marshal => "MarshalAs (UnmanagedType.LPStr)"};
 $types{"refstring"} = {name => "IntPtr", out => "ref", marshal => ""};
 $types{"charPtr"} = {name => "StringBuilder", out => "", marshal => ""};
 $types{"voidPtr"} = {name => "IntPtr", out => "", marshal => ""};
-$types{"nsISupports"} = {name => "IntPtr", out => "out", marshal =>"MarshalAs (UnmanagedType.Interface) "};
+$types{"nsISupports"} = {name => "IntPtr", out => "out", marshal =>"MarshalAs (UnmanagedType.Interface)"};
 $types{"DOMTimeStamp"} = {name => "int", out => "out", marshal => ""};
 $types{"nsWriteSegmentFun"} = {name => "nsIWriteSegmentFunDelegate", out => "", marshal => ""};
+$types{"nsReadSegmentFun"} = {name => "nsIReadSegmentFunDelegate", out => "", marshal => ""};
+$types{"nsTimerCallbackFunc"} = {name => "nsITimerCallbackDelegate", out => "", marshal => ""};
 $types{"nsLoadFlags"} = {name => "ulong", out => "out", marshal => ""};
 $types{"nsQIResult"} = {name => "IntPtr", out => "out", marshal => ""};
 $types{"nsIIDPtr[]"} = {name => "IntPtr", out => "out", marshal => ""};
 $types{"PRFileDescStar"} = {name => "IntPtr", out => "out", marshal => ""};
 $types{"PRLibraryStar"} = {name => "IntPtr", out => "out", marshal => ""};
 $types{"FILE"} = {name => "IntPtr", out => "out", marshal => ""};
-$types{"others"} = {name => "", out => "out", marshal => "MarshalAs (UnmanagedType.Interface) "};
+$types{"nsIPresShell"} = {name => "/*nsIPresShell*/ IntPtr", out => "out", marshal => ""};
+$types{"nsIDocument"} = {name => "/*nsIDocument*/ IntPtr", out => "out", marshal => ""};
+$types{"nsIFrame"} = {name => "/*nsIFrame*/ IntPtr", out => "out", marshal => ""};
+$types{"nsObjectFrame"} = {name => "/*nsObjectFrame*/ IntPtr", out => "out", marshal => ""};
+$types{"nsIContent"} = {name => "/*nsIContent*/ IntPtr", out => "out", marshal => ""};
+$types{"others"} = {name => "", out => "out", marshal => "MarshalAs (UnmanagedType.Interface)"};
 
 my %returnvalues;
 $returnvalues{"short"} = {value => "0"};
@@ -115,6 +117,39 @@ my %dependents;
    
 my $class_implementation;
 
+
+
+sub usage ()
+{
+       print STDERR << "EOF";
+    Usage: xpidl2cs.pl -f file -p path/to/idl [-nh -c class]
+    -h         : this help
+    -f         : idl file to parse, with extension
+    -p         : path to the idl file directory
+    -n         : generate files with no PreserveSig attribute (optional, defaults to adding the attribute)
+    -c         : specific class to use inside the idl file (optional)
+EOF
+       exit;
+}
+
+sub init ()
+{
+       use Getopt::Std;
+       my $opts = 'f:p:c:n';
+       getopts( "$opts", \%opt ) or usage();
+       usage if $opt{h};
+
+       usage() if !$opt{f} or !$opt{p};
+
+       $file = $opt{f};
+       $path = $opt{p};
+       open FILE, '<', $path.$file or die "Can't open file $path$file";
+       
+       $nosig = 1 if $opt{n};
+       $_class = $opt{c};
+}
+
+
 sub trim{
 #print "trim\n";
     $_[0]=~s/^\s+//;
@@ -350,23 +385,28 @@ sub get_params {
 
                $marshal = "" if $marshal eq " ";
 
-               my $tmp = "\n\t\t\t\t";
+#              my $tmp = "\n\t\t\t\t";
+               my $tmp = "";
                $tmp .= "[$marshal] " if $marshal;
                $tmp .= "$out $type $name";
                push (@ret, $tmp);
                $lastoutparam = $name if $isout;
+#print "tmp:$tmp\n";
     }
 
 #print "$methods{$x}->{\"type\"}\n";
+#print "nosig:$nosig;x:$x;type:" . &get_type ($methods{$x}->{"type"}) . ";\n";
        if (!$nosig && $x !~ /void/ && &get_type ($methods{$x}->{"type"}) ne "") {
                $type = $methods{$x}->{"type"};
                $type =~ s/\[.*\],//;
                $marshal = &get_marshal ($type);
 
-               my $tmp = "[$marshal] " if $marshal;
+               my $tmp = "";
+               $tmp = "[$marshal] " if $marshal;
                $tmp .= &get_out($type);
                $tmp .= " " . &get_type ($type);
                $tmp .= " ret";
+#print "tmp 2:$tmp\n";
                push (@ret, $tmp);
                
                &add_external ($type);
@@ -378,7 +418,7 @@ sub get_params {
        }
 #print "@ret\n";
        
-       return join (",", @ret);
+       return join (",\n\t\t\t\t", @ret);
 }
 
 sub parse_file {
@@ -424,6 +464,19 @@ sub parse_file {
                                my $class = $line;
                                $class =~ s/interface ([^\:|\s]+)\s*:\s*(.*)/\1/;
 #              print "\t\tclass:$class\n";
+#              print "\t\t_class:$_class\n";
+                               if ($_class && $_class !~ $class) {
+                                       $uuid = '';
+                                       $class = '';
+                                       $method = 0;
+                                       $mname = '';
+                                       $mtype = '';
+                                       $mparams = '';
+                                       $start = 0;
+                                       $comment = 0;
+                                       next;
+                               }
+
                                my $parent = $line;
                                $parent =~ s/([^\:]+):\s*(.*)[\s|\{]/\2/;
 #              print "\t\tparent:$parent\n";
@@ -663,7 +716,9 @@ sub generate_dependents {
     for my $dependent (keys %dependents) {
                if (! (-e "$dependent.cs") && -e "$path$dependent.idl" && $file != $dependent) {
                        print "generating $path$dependent.idl\n";
-                       my $ret = `perl xpidl2cs.pl $dependent.idl $path $nosig`;
+                       my $cmd = "perl xpidl2cs.pl -f $dependent.idl -p $path";
+                       $cmd .= "-n" if $nosig;
+                       my $ret = `$cmd`;
                        print "\n$ret";
                }
     }
@@ -785,7 +840,7 @@ sub generate_class_implementation_example {
        
 }
 
-
+&init();
 &parse_file ();
 &output ();
 &generate_dependents ();