This is my patch patch.1n for perl5.001.
[p5sagit/p5-mst-13.2.git] / h2ph.SH
diff --git a/h2ph.SH b/h2ph.SH
old mode 100644 (file)
new mode 100755 (executable)
index 1e5ac0b..cb36ada
--- a/h2ph.SH
+++ b/h2ph.SH
@@ -19,12 +19,14 @@ echo "Extracting h2ph (with variable substitutions)"
 : Move anything that needs config subs from !NO!SUBS! section to !GROK!THIS!.
 : Protect any dollar signs and backticks that you do not want interpreted
 : by putting a backslash in front.  You may delete these comments.
+rm -f h2ph
 $spitshell >h2ph <<!GROK!THIS!
-#!$bin/perl
-'di';
-'ig00';
+#!$binexp/perl
+'di ';
+'ds 00 \"';
+'ig 00 ';
 
-\$perlincl = '$privlib';
+\$perlincl = '$archlibexp';
 !GROK!THIS!
 
 : In the following dollars and backticks do not need the extra backslash.
@@ -40,7 +42,8 @@ chdir '/usr/include' || die "Can't cd /usr/include";
        FILE
 END
 
-$isatype{@isatype} = (1) x @isatype;
+@isatype{@isatype} = (1) x @isatype;
+$inif = 0;
 
 @ARGV = ('-') unless @ARGV;
 
@@ -86,6 +89,7 @@ foreach $file (@ARGV) {
                    $args = $1;
                    if ($args ne '') {
                        foreach $arg (split(/,\s*/,$args)) {
+                           $arg =~ s/^\s*([^\s].*[^\s])\s*$/$1/;
                            $curargs{$arg} = 1;
                        }
                        $args =~ s/\b(\w)/\$$1/g;
@@ -117,7 +121,7 @@ foreach $file (@ARGV) {
                    }
                }
            }
-           elsif (/^include <(.*)>/) {
+           elsif (/^include\s+<(.*)>/) {
                ($incl = $1) =~ s/\.h$/.ph/;
                print OUT $t,"require '$incl';\n";
            }
@@ -133,14 +137,18 @@ foreach $file (@ARGV) {
            }
            elsif (s/^if\s+//) {
                $new = '';
+               $inif = 1;
                do expr();
+               $inif = 0;
                print OUT $t,"if ($new) {\n";
                $tab += 4;
                $t = "\t" x ($tab / 8) . ' ' x ($tab % 8);
            }
            elsif (s/^elif\s+//) {
                $new = '';
+               $inif = 1;
                do expr();
+               $inif = 0;
                $tab -= 4;
                $t = "\t" x ($tab / 8) . ' ' x ($tab % 8);
                print OUT $t,"}\n${t}elsif ($new) {\n";
@@ -218,7 +226,11 @@ sub expr {
                }
            }
            else {
-               $new .= ' &' . $id;
+               if ($inif && $new !~ /defined\($/) {
+                   $new .= '(defined(&' . $id . ') ? &' . $id . ' : 0)';
+               } else { 
+                   $new .= ' &' . $id;
+               }
            }
            next;
        };
@@ -229,8 +241,8 @@ sub expr {
 
        # These next few lines are legal in both Perl and nroff.
 
-.00;                   # finish .ig
+.00 ;                  # finish .ig
+
 'di                    \" finish diversion--previous line must be blank
 .nr nl 0-1             \" fake up transition to first page again
 .nr % 0                        \" start at page 1