3 if test ! -f config.sh; then
5 ln ../../config.sh . || \
6 ln ../../../config.sh . || \
7 (echo "Can't find config.sh."; exit 1)
12 : This forces SH files to create target in same directory as SH file.
13 : This is so that make depend always knows where to find SH derivatives.
15 */*) cd `expr X$0 : 'X\(.*\)/'` ;;
17 echo "Extracting h2ph (with variable substitutions)"
18 : This section of the file will have variable substitutions done on it.
19 : Move anything that needs config subs from !NO!SUBS! section to !GROK!THIS!.
20 : Protect any dollar signs and backticks that you do not want interpreted
21 : by putting a backslash in front. You may delete these comments.
23 $spitshell >h2ph <<!GROK!THIS!
29 \$perlincl = '$archlibexp';
32 : In the following dollars and backticks do not need the extra backslash.
33 $spitshell >>h2ph <<'!NO!SUBS!'
35 chdir '/usr/include' || die "Can't cd /usr/include";
37 @isatype = split(' ',<<END);
45 @isatype{@isatype} = (1) x @isatype;
48 @ARGV = ('-') unless @ARGV;
50 foreach $file (@ARGV) {
56 ($outfile = $file) =~ s/\.h$/.ph/ || next;
57 print "$file -> $outfile\n";
58 if ($file =~ m|^(.*)/|) {
60 if (!-d "$perlincl/$dir") {
61 mkdir("$perlincl/$dir",0777);
64 open(IN,"$file") || ((warn "Can't open $file: $!\n"),next);
65 open(OUT,">$perlincl/$outfile") || die "Can't create $outfile: $!\n";
76 s/\200[^\201]*\201//g; # delete single line comments
77 if (s/\200.*//) { # begin multi-line comment?
84 if (s/^define\s+(\w+)//) {
88 if (s/^\(([\w,\s]*)\)//) {
91 foreach $arg (split(/,\s*/,$args)) {
92 $arg =~ s/^\s*([^\s].*[^\s])\s*$/$1/;
95 $args =~ s/\b(\w)/\$$1/g;
96 $args = "local($args) = \@_;\n$t ";
100 $new =~ s/(["\\])/\\$1/g;
102 $new =~ s/(['\\])/\\$1/g;
104 "eval 'sub $name {\n$t ${args}eval \"$new\";\n$t}';\n";
107 print OUT "sub $name {\n ${args}eval \"$new\";\n}\n";
114 $new = 1 if $new eq '';
116 $new =~ s/(['\\])/\\$1/g;
117 print OUT $t,"eval 'sub $name {",$new,";}';\n";
120 print OUT $t,"sub $name {",$new,";}\n";
124 elsif (/^include\s+<(.*)>/) {
125 ($incl = $1) =~ s/\.h$/.ph/;
126 print OUT $t,"require '$incl';\n";
128 elsif (/^ifdef\s+(\w+)/) {
129 print OUT $t,"if (defined &$1) {\n";
131 $t = "\t" x ($tab / 8) . ' ' x ($tab % 8);
133 elsif (/^ifndef\s+(\w+)/) {
134 print OUT $t,"if (!defined &$1) {\n";
136 $t = "\t" x ($tab / 8) . ' ' x ($tab % 8);
143 print OUT $t,"if ($new) {\n";
145 $t = "\t" x ($tab / 8) . ' ' x ($tab % 8);
147 elsif (s/^elif\s+//) {
153 $t = "\t" x ($tab / 8) . ' ' x ($tab % 8);
154 print OUT $t,"}\n${t}elsif ($new) {\n";
156 $t = "\t" x ($tab / 8) . ' ' x ($tab % 8);
160 $t = "\t" x ($tab / 8) . ' ' x ($tab % 8);
161 print OUT $t,"}\n${t}else {\n";
163 $t = "\t" x ($tab / 8) . ' ' x ($tab % 8);
167 $t = "\t" x ($tab / 8) . ' ' x ($tab % 8);
177 s/^(\s+)// && do {$new .= ' '; next;};
178 s/^(0x[0-9a-fA-F]+)// && do {$new .= $1; next;};
179 s/^(\d+)// && do {$new .= $1; next;};
180 s/^("(\\"|[^"])*")// && do {$new .= $1; next;};
181 s/^'((\\"|[^"])*)'// && do {
183 $new .= "ord('\$$1')";
190 s/^sizeof\s*\(([^)]+)\)/{$1}/ && do {
194 s/^([_a-zA-Z]\w*)// && do {
196 if ($id eq 'struct') {
201 elsif ($id eq 'unsigned') {
209 elsif ($id eq 'defined') {
213 s/^\((\w),/("$1",/ if $id =~ /^_IO[WR]*$/i; # cheat
216 elsif ($isatype{$id}) {
217 if ($new =~ /{\s*$/) {
220 elsif ($new =~ /\(\s*$/ && /^[\s*]*\)/) {
229 if ($inif && $new !~ /defined\($/) {
230 $new .= '(defined(&' . $id . ') ? &' . $id . ' : 0)';
237 s/^(.)// && do {$new .= $1; next;};
240 ##############################################################################
242 # These next few lines are legal in both Perl and nroff.
246 'di \" finish diversion--previous line must be blank
247 .nr nl 0-1 \" fake up transition to first page again
248 .nr % 0 \" start at page 1
249 '; __END__ ############# From here on it's a standard manual page ############
250 .TH H2PH 1 "August 8, 1990"
253 h2ph \- convert .h C header files to .ph Perl header files
255 .B h2ph [headerfiles]
258 converts any C header files specified to the corresponding Perl header file
260 It is most easily run while in /usr/include:
263 cd /usr/include; h2ph * sys/*
266 If run with no arguments, filters standard input to standard output.
268 No environment variables are used.
280 The usual warnings if it can't read or write the files involved.
282 Doesn't construct the %sizeof array for you.
284 It doesn't handle all C constructs, but it does attempt to isolate
285 definitions inside evals so that you can get at the definitions
286 that it can translate.
288 It's only intended as a rough tool.
289 You may need to dicker with the files produced.