X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=h2ph.SH;h=fbab3b4345179acb39b8c1a00552f68651f45fa3;hb=3b35bae3d5913952e779006fe378c78297e23080;hp=903cad3a70f88fdf8e03ad8fdf32ecf256b12435;hpb=d9d8d8de9462d72f6b4520fc11dd84dbe2c8bf1d;p=p5sagit%2Fp5-mst-13.2.git diff --git a/h2ph.SH b/h2ph.SH old mode 100644 new mode 100755 index 903cad3..fbab3b4 --- a/h2ph.SH +++ b/h2ph.SH @@ -5,8 +5,8 @@ case $CONFIG in ln ../../config.sh . || \ ln ../../../config.sh . || \ (echo "Can't find config.sh."; exit 1) - fi - . config.sh + fi 2>/dev/null + . ./config.sh ;; esac : This forces SH files to create target in same directory as SH file. @@ -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 <>h2ph <<'!NO!SUBS!' chdir '/usr/include' || die "Can't cd /usr/include"; -%isatype = ('char',1,'short',1,'int',1,'long',1); +@isatype = split(' ',< $outfile\n"; - if ($file =~ m|^(.*)/|) { - $dir = $1; - if (!-d "$perlincl/$dir") { - mkdir("$perlincl/$dir",0777); + if ($file eq '-') { + open(IN, "-"); + open(OUT, ">-"); + } + else { + ($outfile = $file) =~ s/\.h$/.ph/ || next; + print "$file -> $outfile\n"; + if ($file =~ m|^(.*)/|) { + $dir = $1; + if (!-d "$perlincl/$dir") { + mkdir("$perlincl/$dir",0777); + } } + open(IN,"$file") || ((warn "Can't open $file: $!\n"),next); + open(OUT,">$perlincl/$outfile") || die "Can't create $outfile: $!\n"; } - open(IN,"$file") || ((warn "Can't open $file: $!\n"),next); - open(OUT,">$perlincl/$outfile") || die "Can't create $outfile: $!\n"; while () { chop; while (/\\$/) { @@ -70,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; @@ -101,7 +121,7 @@ foreach $file (@ARGV) { } } } - elsif (/^include <(.*)>/) { + elsif (/^include\s+<(.*)>/) { ($incl = $1) =~ s/\.h$/.ph/; print OUT $t,"require '$incl';\n"; } @@ -117,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"; @@ -163,13 +187,22 @@ sub expr { } next; }; - s/^(struct\s+\w+)// && do {$new .= "'$1'"; next;}; s/^sizeof\s*\(([^)]+)\)/{$1}/ && do { $new .= '$sizeof'; next; }; s/^([_a-zA-Z]\w*)// && do { $id = $1; + if ($id eq 'struct') { + s/^\s+(\w+)//; + $id .= ' ' . $1; + $isatype{$id} = 1; + } + elsif ($id eq 'unsigned') { + s/^\s+(\w+)//; + $id .= ' ' . $1; + $isatype{$id} = 1; + } if ($curargs{$id}) { $new .= '$' . $id; } @@ -177,14 +210,27 @@ sub expr { $new .= 'defined'; } elsif (/^\(/) { - s/^\((\w),/("$1",/ if $id =~ /^_IO[WR]*$/; # cheat + s/^\((\w),/("$1",/ if $id =~ /^_IO[WR]*$/i; # cheat $new .= " &$id"; } elsif ($isatype{$id}) { - $new .= "'$id'"; + if ($new =~ /{\s*$/) { + $new .= "'$id'"; + } + elsif ($new =~ /\(\s*$/ && /^[\s*]*\)/) { + $new =~ s/\(\s*$//; + s/^[\s*]*\)//; + } + else { + $new .= $id; + } } else { - $new .= ' &' . $id; + if ($inif && $new !~ /defined\($/) { + $new .= '(defined(&' . $id . ') ? &' . $id . ' : 0)'; + } else { + $new .= ' &' . $id; + } } next; }; @@ -195,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 @@ -217,6 +263,7 @@ It is most easily run while in /usr/include: cd /usr/include; h2ph * sys/* .fi +If run with no arguments, filters standard input to standard output. .SH ENVIRONMENT No environment variables are used. .SH FILES