fix fs.t for VMS
[p5sagit/p5-mst-13.2.git] / utils / h2ph.PL
index ab6cad9..9082e14 100644 (file)
@@ -238,15 +238,19 @@ while (defined (my $file = next_file())) {
            } elsif(/^ident\s+(.*)/) {
                print OUT $t, "# $1\n";
            }
-       } elsif(/^\s*(typedef\s*)?enum\s*(\s+[a-zA-Z_]\w*\s*)?\{/) {
-           until(/\}.*?;/) {
-               chomp($next = <IN>);
+       } elsif(/^\s*(typedef\s*)?enum\s*(\s+[a-zA-Z_]\w*\s*)?/) {
+           until(/\{[^}]*\}.*;/ || /;/) {
+               last unless defined ($next = <IN>);
+               chomp $next;
+               # drop "#define FOO FOO" in enums
+               $next =~ s/^\s*#\s*define\s+(\w+)\s+\1\s*$//;
                $_ .= $next;
                print OUT "# $next\n" if $opt_D;
            }
+           s/#\s*if.*?#\s*endif//g; # drop #ifdefs
            s@/\*.*?\*/@@g;
            s/\s+/ /g;
-           /^\s?(typedef\s?)?enum\s?([a-zA-Z_]\w*)?\s?\{(.*)\}\s?([a-zA-Z_]\w*)?\s?;/;
+           next unless /^\s?(typedef\s?)?enum\s?([a-zA-Z_]\w*)?\s?\{(.*)\}\s?([a-zA-Z_]\w*)?\s?;/;
            (my $enum_subs = $3) =~ s/\s//g;
            my @enum_subs = split(/,/, $enum_subs);
            my $enum_val = -1;
@@ -370,8 +374,8 @@ sub expr {
                $new .= '->' if /^[\[\{]/;
            } elsif ($id eq 'defined') {
                $new .= 'defined';
-           } elsif (/^\(/) {
-               s/^\((\w),/("$1",/ if $id =~ /^_IO[WR]*$/i;     # cheat
+           } elsif (/^\s*\(/) {
+               s/^\s*\((\w),/("$1",/ if $id =~ /^_IO[WR]*$/i;  # cheat
                $new .= " &$id";
            } elsif ($isatype{$id}) {
                if ($new =~ /{\s*$/) {
@@ -401,6 +405,7 @@ sub expr {
 sub next_line
 {
     my ($in, $out);
+    my $pre_sub_tri_graphs = 1;
 
     READ: while (not eof IN) {
         $in  .= <IN>;
@@ -408,6 +413,19 @@ sub next_line
         next unless length $in;
 
         while (length $in) {
+            if ($pre_sub_tri_graphs) {
+                # Preprocess all tri-graphs 
+                # including things stuck in quoted string constants.
+                $in =~ s/\?\?=/#/g;                         # | ??=|  #|
+                $in =~ s/\?\?\!/|/g;                        # | ??!|  ||
+                $in =~ s/\?\?'/^/g;                         # | ??'|  ^|
+                $in =~ s/\?\?\(/[/g;                        # | ??(|  [|
+                $in =~ s/\?\?\)/]/g;                        # | ??)|  ]|
+                $in =~ s/\?\?\-/~/g;                        # | ??-|  ~|
+                $in =~ s/\?\?\//\\/g;                       # | ??/|  \|
+                $in =~ s/\?\?</{/g;                         # | ??<|  {|
+                $in =~ s/\?\?>/}/g;                         # | ??>|  }|
+            }
             if ($in =~ s/\\$//) {                           # \-newline
                 $out    .= ' ';
                 next READ;
@@ -592,9 +610,9 @@ sub build_preamble_if_necessary
                 print PREAMBLE "# $_=$define{$_}\n";
             }
 
-            if ($define{$_} =~ /^\d+$/) {
+            if ($define{$_} =~ /^(\d+)U?L{0,2}$/i) {
                 print PREAMBLE
-                    "unless (defined &$_) { sub $_() { $define{$_} } }\n\n";
+                    "unless (defined &$_) { sub $_() { $1 } }\n\n";
             } elsif ($define{$_} =~ /^\w+$/) {
                 print PREAMBLE
                     "unless (defined &$_) { sub $_() { &$define{$_} } }\n\n";