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!
28 \$perlincl = '$installprivlib';
31 : In the following dollars and backticks do not need the extra backslash.
32 $spitshell >>h2ph <<'!NO!SUBS!'
34 chdir '/usr/include' || die "Can't cd /usr/include";
36 @isatype = split(' ',<<END);
44 @isatype{@isatype} = (1) x @isatype;
46 @ARGV = ('-') unless @ARGV;
48 foreach $file (@ARGV) {
54 ($outfile = $file) =~ s/\.h$/.ph/ || next;
55 print "$file -> $outfile\n";
56 if ($file =~ m|^(.*)/|) {
58 if (!-d "$perlincl/$dir") {
59 mkdir("$perlincl/$dir",0777);
62 open(IN,"$file") || ((warn "Can't open $file: $!\n"),next);
63 open(OUT,">$perlincl/$outfile") || die "Can't create $outfile: $!\n";
74 s/\200[^\201]*\201//g; # delete single line comments
75 if (s/\200.*//) { # begin multi-line comment?
82 if (s/^define\s+(\w+)//) {
86 if (s/^\(([\w,\s]*)\)//) {
89 foreach $arg (split(/,\s*/,$args)) {
90 $arg =~ s/^\s*([^\s].*[^\s])\s*$/$1/;
93 $args =~ s/\b(\w)/\$$1/g;
94 $args = "local($args) = \@_;\n$t ";
98 $new =~ s/(["\\])/\\$1/g;
100 $new =~ s/(['\\])/\\$1/g;
102 "eval 'sub $name {\n$t ${args}eval \"$new\";\n$t}';\n";
105 print OUT "sub $name {\n ${args}eval \"$new\";\n}\n";
112 $new = 1 if $new eq '';
114 $new =~ s/(['\\])/\\$1/g;
115 print OUT $t,"eval 'sub $name {",$new,";}';\n";
118 print OUT $t,"sub $name {",$new,";}\n";
122 elsif (/^include\s+<(.*)>/) {
123 ($incl = $1) =~ s/\.h$/.ph/;
124 print OUT $t,"require '$incl';\n";
126 elsif (/^ifdef\s+(\w+)/) {
127 print OUT $t,"if (defined &$1) {\n";
129 $t = "\t" x ($tab / 8) . ' ' x ($tab % 8);
131 elsif (/^ifndef\s+(\w+)/) {
132 print OUT $t,"if (!defined &$1) {\n";
134 $t = "\t" x ($tab / 8) . ' ' x ($tab % 8);
139 print OUT $t,"if ($new) {\n";
141 $t = "\t" x ($tab / 8) . ' ' x ($tab % 8);
143 elsif (s/^elif\s+//) {
147 $t = "\t" x ($tab / 8) . ' ' x ($tab % 8);
148 print OUT $t,"}\n${t}elsif ($new) {\n";
150 $t = "\t" x ($tab / 8) . ' ' x ($tab % 8);
154 $t = "\t" x ($tab / 8) . ' ' x ($tab % 8);
155 print OUT $t,"}\n${t}else {\n";
157 $t = "\t" x ($tab / 8) . ' ' x ($tab % 8);
161 $t = "\t" x ($tab / 8) . ' ' x ($tab % 8);
171 s/^(\s+)// && do {$new .= ' '; next;};
172 s/^(0x[0-9a-fA-F]+)// && do {$new .= $1; next;};
173 s/^(\d+)// && do {$new .= $1; next;};
174 s/^("(\\"|[^"])*")// && do {$new .= $1; next;};
175 s/^'((\\"|[^"])*)'// && do {
177 $new .= "ord('\$$1')";
184 s/^sizeof\s*\(([^)]+)\)/{$1}/ && do {
188 s/^([_a-zA-Z]\w*)// && do {
190 if ($id eq 'struct') {
195 elsif ($id eq 'unsigned') {
203 elsif ($id eq 'defined') {
207 s/^\((\w),/("$1",/ if $id =~ /^_IO[WR]*$/i; # cheat
210 elsif ($isatype{$id}) {
211 if ($new =~ /{\s*$/) {
214 elsif ($new =~ /\(\s*$/ && /^[\s*]*\)/) {
227 s/^(.)// && do {$new .= $1; next;};
230 ##############################################################################
232 # These next few lines are legal in both Perl and nroff.
236 'di \" finish diversion--previous line must be blank
237 .nr nl 0-1 \" fake up transition to first page again
238 .nr % 0 \" start at page 1
239 '; __END__ ############# From here on it's a standard manual page ############
240 .TH H2PH 1 "August 8, 1990"
243 h2ph \- convert .h C header files to .ph Perl header files
245 .B h2ph [headerfiles]
248 converts any C header files specified to the corresponding Perl header file
250 It is most easily run while in /usr/include:
253 cd /usr/include; h2ph * sys/*
256 If run with no arguments, filters standard input to standard output.
258 No environment variables are used.
270 The usual warnings if it can't read or write the files involved.
272 Doesn't construct the %sizeof array for you.
274 It doesn't handle all C constructs, but it does attempt to isolate
275 definitions inside evals so that you can get at the definitions
276 that it can translate.
278 It's only intended as a rough tool.
279 You may need to dicker with the files produced.