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.
22 $spitshell >h2ph <<!GROK!THIS!
27 \$perlincl = '$privlib';
30 : In the following dollars and backticks do not need the extra backslash.
31 $spitshell >>h2ph <<'!NO!SUBS!'
33 chdir '/usr/include' || die "Can't cd /usr/include";
35 %isatype = ('char',1,'short',1,'int',1,'long',1);
37 foreach $file (@ARGV) {
38 ($outfile = $file) =~ s/\.h$/.ph/;
39 print "$file -> $outfile\n";
40 if ($file =~ m|^(.*)/|) {
42 if (!-d "$perlincl/$dir") {
43 mkdir("$perlincl/$dir",0777);
46 open(IN,"$file") || ((warn "Can't open $file: $!\n"),next);
47 open(OUT,">$perlincl/$outfile") || die "Can't create $outfile: $!\n";
57 s/\200[^\201]*\201//g; # delete single line comments
58 if (s/\200.*//) { # begin multi-line comment?
65 if (s/^define\s+(\w+)//) {
69 if (s/^\(([\w,\s]*)\)//) {
72 foreach $arg (split(/,\s*/,$args)) {
75 $args =~ s/\b(\w)/\$$1/g;
76 $args = "local($args) = \@_;\n$t ";
80 $new =~ s/(["\\])/\\$1/g;
82 $new =~ s/(['\\])/\\$1/g;
84 "eval 'sub $name {\n$t ${args}eval \"$new\";\n$t}';\n";
87 print OUT "sub $name {\n ${args}eval \"$new\";\n}\n";
94 $new = 1 if $new eq '';
96 $new =~ s/(['\\])/\\$1/g;
97 print OUT $t,"eval 'sub $name {",$new,";}';\n";
100 print OUT $t,"sub $name {",$new,";}\n";
104 elsif (/^include <(.*)>/) {
105 ($incl = $1) =~ s/\.h$/.ph/;
106 print OUT $t,"require '$incl';\n";
108 elsif (/^ifdef\s+(\w+)/) {
109 print OUT $t,"if (defined &$1) {\n";
111 $t = "\t" x ($tab / 8) . ' ' x ($tab % 8);
113 elsif (/^ifndef\s+(\w+)/) {
114 print OUT $t,"if (!defined &$1) {\n";
116 $t = "\t" x ($tab / 8) . ' ' x ($tab % 8);
121 print OUT $t,"if ($new) {\n";
123 $t = "\t" x ($tab / 8) . ' ' x ($tab % 8);
125 elsif (s/^elif\s+//) {
129 $t = "\t" x ($tab / 8) . ' ' x ($tab % 8);
130 print OUT $t,"}\n${t}elsif ($new) {\n";
132 $t = "\t" x ($tab / 8) . ' ' x ($tab % 8);
136 $t = "\t" x ($tab / 8) . ' ' x ($tab % 8);
137 print OUT $t,"}\n${t}else {\n";
139 $t = "\t" x ($tab / 8) . ' ' x ($tab % 8);
143 $t = "\t" x ($tab / 8) . ' ' x ($tab % 8);
153 s/^(\s+)// && do {$new .= ' '; next;};
154 s/^(0x[0-9a-fA-F]+)// && do {$new .= $1; next;};
155 s/^(\d+)// && do {$new .= $1; next;};
156 s/^("(\\"|[^"])*")// && do {$new .= $1; next;};
157 s/^'((\\"|[^"])*)'// && do {
159 $new .= "ord('\$$1')";
166 s/^(struct\s+\w+)// && do {$new .= "'$1'"; next;};
167 s/^sizeof\s*\(([^)]+)\)/{$1}/ && do {
171 s/^([_a-zA-Z]\w*)// && do {
176 elsif ($id eq 'defined') {
180 s/^\((\w),/("$1",/ if $id =~ /^_IO[WR]*$/i; # cheat
183 elsif ($isatype{$id}) {
191 s/^(.)// && do {$new .= $1; next;};
194 ##############################################################################
196 # These next few lines are legal in both Perl and nroff.
200 'di \" finish diversion--previous line must be blank
201 .nr nl 0-1 \" fake up transition to first page again
202 .nr % 0 \" start at page 1
203 '; __END__ ############# From here on it's a standard manual page ############
204 .TH H2PH 1 "August 8, 1990"
207 h2ph \- convert .h C header files to .ph Perl header files
209 .B h2ph [headerfiles]
212 converts any C header files specified to the corresponding Perl header file
214 It is most easily run while in /usr/include:
217 cd /usr/include; h2ph * sys/*
221 No environment variables are used.
233 The usual warnings if it can't read or write the files involved.
235 Doesn't construct the %sizeof array for you.
237 It doesn't handle all C constructs, but it does attempt to isolate
238 definitions inside evals so that you can get at the definitions
239 that it can translate.
241 It's only intended as a rough tool.
242 You may need to dicker with the files produced.