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.
: 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.
chdir '/usr/include' || die "Can't cd /usr/include";
-%isatype = ('char',1,'short',1,'int',1,'long',1);
+@isatype = split(' ',<<END);
+ char uchar u_char
+ short ushort u_short
+ int uint u_int
+ long ulong u_long
+ FILE
+END
+
+@isatype{@isatype} = (1) x @isatype;
+$inif = 0;
+
+@ARGV = ('-') unless @ARGV;
foreach $file (@ARGV) {
- ($outfile = $file) =~ s/\.h$/.ph/;
- print "$file -> $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 (<IN>) {
chop;
while (/\\$/) {
$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;
}
}
}
- elsif (/^include <(.*)>/) {
- print OUT $t,"do '$1' || die \"Can't include $1: \$!\";\n";
+ elsif (/^include\s+<(.*)>/) {
+ ($incl = $1) =~ s/\.h$/.ph/;
+ print OUT $t,"require '$incl';\n";
}
elsif (/^ifdef\s+(\w+)/) {
print OUT $t,"if (defined &$1) {\n";
}
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";
}
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;
}
$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;
};
# 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
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