#!perl # # hsplit is too lame to handle OLE interfaces, so I have to # write this program myself. It only handles the OLE stuff; # I leave hsplit to manage the regular % stuff. # # Makes it clearer what's going on when we pass it as a flag $A = 0; $W = 1; # # Dummy prototype gizmos for EmitWrapper. # @proto = ( "p", "p,a", "p,a,b", "p,a,b,c", "p,a,b,c,d", "p,a,b,c,d,e", "p,a,b,c,d,e,f", "p,a,b,c,d,e,f,g", "p,a,b,c,d,e,f,g,h", ); ############################################################################## # # Main loop # # Things between ";begin_doc" and ";end_doc" are ignored. # # Else, echo everything that isn't between ";begin_interface" and # ";end_interface". For the stuff between, collect it. If the # interface name contains a "%", then emit separate W and A versions. # ############################################################################## while (<>) { if (/^;begin_doc$/) { while (<>) { last if $_ eq ";end_doc\n"; } next; } ($itf) = /^;begin_interface\s+(\S+)/; unless ($itf) { print; next; } # Oh boy, we found the start of an interface. # Collect the methods. $_ = <>; die ";begin_methods expected here" unless $_ eq ";begin_methods\n"; # An interface is an array of methods # A method is an array, $m[0] is the method name, $m[1] is the arglist @itf = (); while (<>) { last if $_ eq ";end_methods\n"; ($m, $arg) = /^;method\s+(\S+)\s*\((.*)\)$/; push(@itf, [ $m, $arg ]) if $m; } $_ = <>; die ";end_interface expected here" unless $_ eq ";end_interface\n"; if ($itf =~ /%/) { &DoItf($W, $itf, @itf); &DoItf($A, $itf, @itf); } else { &DoItf($W, $itf, @itf); } &DoAfterItf($itf, @itf); } ############################################################################## # # Given a line, remove percent signs, converting to W or A accordingly. # ############################################################################## sub DePercent { my($fW, $line) = @_; if ($fW) { $line =~ s/STR%/WSTR/g; $line =~ s/%/W/g; } else { $line =~ s/STR%/STR/g; $line =~ s/%/A/g; } $line; } ############################################################################## # # Emit the interface definition. # ############################################################################## sub DoItf { my($fW, $itf, @itf) = @_; $itf = &DePercent($fW, $itf); print < $#proto; print "#define ${itf}_$m($proto[$arity]) (p)->lpVtbl->$m($proto[$arity])\n"; }