call_(pv|etc.) for Devel::PPPort
[p5sagit/p5-mst-13.2.git] / ext / Errno / Errno_pm.PL
index d429146..22171fa 100644 (file)
@@ -5,6 +5,7 @@ use strict;
 our $VERSION = "1.09_00";
 
 my %err = ();
+my %wsa = ();
 
 unlink "Errno.pm" if -f "Errno.pm";
 open OUT, ">Errno.pm" or die "Cannot open Errno.pm: $!";
@@ -20,6 +21,7 @@ sub process_file {
     my($file) = @_;
 
     return unless defined $file and -f $file;
+#   warn "Processing $file\n";
 
     local *FH;
     if (($^O eq 'VMS') && ($Config{vms_cc_type} ne 'gnuc')) {
@@ -55,6 +57,10 @@ sub process_file {
        while(<FH>) {
            $err{$1} = 1
                if /^\s*#\s*define\s+(E\w+)\s+/;
+            if ($^O eq 'MSWin32') {
+               $wsa{$1} = 1
+                   if /^\s*#\s*define\s+WSA(E\w+)\s+/;
+            }
        }
     }
     close(FH);
@@ -113,14 +119,21 @@ sub get_files {
        # hidden in a special place
        $file{'/boot/develop/headers/posix/errno.h'} = 1;
 
+    } elsif ($^O eq 'vos') {
+       # avoid problem where cpp returns non-POSIX pathnames
+       $file{'/system/include_library/errno.h'} = 1;
     } else {
        open(CPPI,"> errno.c") or
            die "Cannot open errno.c";
 
        if ($^O eq 'NetWare') {
-               print CPPI "#include <nwerrno.h>\n";
+           print CPPI "#include <nwerrno.h>\n";
        } else {
-               print CPPI "#include <errno.h>\n";
+           print CPPI "#include <errno.h>\n";
+           if ($^O eq 'MSWin32') {
+               print CPPI "#define _WINSOCKAPI_\n"; # don't drag in everything
+               print CPPI "#include <winsock.h>\n";
+           }
        }
 
        close(CPPI);
@@ -172,11 +185,21 @@ sub write_errno_pm {
        die "Cannot open errno.c";
 
     if ($^O eq 'NetWare') {
-               print CPPI "#include <nwerrno.h>\n";
-       } else {
-               print CPPI "#include <errno.h>\n";
+       print CPPI "#include <nwerrno.h>\n";
+       } 
+    else {
+       print CPPI "#include <errno.h>\n";
+    }
+    if ($^O eq 'MSWin32') {
+       print CPPI "#include <winsock.h>\n";
+       foreach $err (keys %wsa) {
+           print CPPI "#ifndef $err\n";
+           print CPPI "#define $err WSA$err\n";
+           print CPPI "#endif\n";
+           $err{$err} = 1;
        }
-
+    }
     foreach $err (keys %err) {
        print CPPI '"',$err,'" [[',$err,']]',"\n";
     }
@@ -206,9 +229,17 @@ sub write_errno_pm {
            my($name,$expr);
            next unless ($name, $expr) = /"(.*?)"\s*\[\s*\[\s*(.*?)\s*\]\s*\]/;
            next if $name eq $expr;
-           $expr =~ s/(\d+)[LU]+\b/$1/g; # 2147483647L et alia
+           $expr =~ s/\(?\(\w+\)([^\)]*)\)?/$1/; # ((type)0xcafebabe) at alia
+           $expr =~ s/((?:0x)?[0-9a-fA-F]+)[LU]+\b/$1/g; # 2147483647L et alia
+           next if $expr =~ m/^[a-zA-Z]+$/; # skip some Win32 functions
+           if($expr =~ m/^0[xX]/) {
+               $err{$name} = hex $expr;
+           }
+           else {
            $err{$name} = eval $expr;
        }
+           delete $err{$name} unless defined $err{$name};
+       }
        close(CPPO);
     }
 
@@ -264,6 +295,7 @@ use strict;
        die "Errno architecture ($Config{'archname'}-$Config{'osvers'}) does not match executable architecture (\$Config{'archname'}-\$Config{'osvers'})";
 
 \$VERSION = "$VERSION";
+\$VERSION = eval \$VERSION;
 \@ISA = qw(Exporter);
 
 EDQ