home *** CD-ROM | disk | FTP | other *** search
/ Chip: Windows 2000 Professional Resource Kit / W2KPRK.iso / apps / perl / ActivePerl.exe / data.z / h2ph.bat < prev    next >
Encoding:
DOS Batch File  |  1999-10-16  |  19.8 KB  |  709 lines

  1. @rem = '--*-Perl-*--
  2. @echo off
  3. if "%OS%" == "Windows_NT" goto WinNT
  4. perl -x -S "%0" %1 %2 %3 %4 %5 %6 %7 %8 %9
  5. goto endofperl
  6. :WinNT
  7. perl -x -S "%0" %*
  8. if NOT "%COMSPEC%" == "%SystemRoot%\system32\cmd.exe" goto endofperl
  9. if %errorlevel% == 9009 echo You do not have Perl in your PATH.
  10. goto endofperl
  11. @rem ';
  12. #!perl
  13. #line 14
  14.     eval 'exec P:\Apps\ActivePerl\temp\bin\MSWin32-x86-object\perl.exe -S $0 ${1+"$@"}'
  15.     if $running_under_some_shell;
  16.  
  17. use Config;
  18. use File::Path qw(mkpath);
  19. use Getopt::Std;
  20.  
  21. getopts('Dd:rlhaQ');
  22. die "-r and -a options are mutually exclusive\n" if ($opt_r and $opt_a);
  23. @inc_dirs = inc_dirs() if $opt_a;
  24.  
  25. my $Exit = 0;
  26.  
  27. my $Dest_dir = $opt_d || $Config{installsitearch};
  28. die "Destination directory $Dest_dir doesn't exist or isn't a directory\n"
  29.     unless -d $Dest_dir;
  30.  
  31. @isatype = split(' ',<<END);
  32.     char    uchar    u_char
  33.     short    ushort    u_short
  34.     int    uint    u_int
  35.     long    ulong    u_long
  36.     FILE    key_t    caddr_t
  37. END
  38.  
  39. @isatype{@isatype} = (1) x @isatype;
  40. $inif = 0;
  41.  
  42. @ARGV = ('-') unless @ARGV;
  43.  
  44. build_preamble_if_necessary();
  45.  
  46. while (defined ($file = next_file())) {
  47.     if (-l $file and -d $file) {
  48.         link_if_possible($file) if ($opt_l);
  49.         next;
  50.     }
  51.  
  52.     # Recover from header files with unbalanced cpp directives
  53.     $t = '';
  54.     $tab = 0;
  55.  
  56.     # $eval_index goes into ``#line'' directives, to help locate syntax errors:
  57.     $eval_index = 1;
  58.  
  59.     if ($file eq '-') {
  60.     open(IN, "-");
  61.     open(OUT, ">-");
  62.     } else {
  63.     ($outfile = $file) =~ s/\.h$/.ph/ || next;
  64.     print "$file -> $outfile\n" unless $opt_Q;
  65.     if ($file =~ m|^(.*)/|) {
  66.         $dir = $1;
  67.         mkpath "$Dest_dir/$dir";
  68.     }
  69.  
  70.     if ($opt_a) { # automagic mode:  locate header file in @inc_dirs
  71.         foreach (@inc_dirs) {
  72.         chdir $_;
  73.         last if -f $file;
  74.         }
  75.     }
  76.  
  77.     open(IN,"$file") || (($Exit = 1),(warn "Can't open $file: $!\n"),next);
  78.     open(OUT,">$Dest_dir/$outfile") || die "Can't create $outfile: $!\n";
  79.     }
  80.  
  81.     print OUT "require '_h2ph_pre.ph';\n\n";
  82.     while (<IN>) {
  83.     chop;
  84.     while (/\\$/) {
  85.         chop;
  86.         $_ .= <IN>;
  87.         chop;
  88.     }
  89.     print OUT "# $_\n" if $opt_D;
  90.  
  91.     if (s:/\*:\200:g) {
  92.         s:\*/:\201:g;
  93.         s/\200[^\201]*\201//g;    # delete single line comments
  94.         if (s/\200.*//) {        # begin multi-line comment?
  95.         $_ .= '/*';
  96.         $_ .= <IN>;
  97.         redo;
  98.         }
  99.     }
  100.     if (s/^\s*\#\s*//) {
  101.         if (s/^define\s+(\w+)//) {
  102.         $name = $1;
  103.         $new = '';
  104.         s/\s+$//;
  105.         if (s/^\(([\w,\s]*)\)//) {
  106.             $args = $1;
  107.                     my $proto = '() ';
  108.             if ($args ne '') {
  109.                         $proto = '';
  110.             foreach $arg (split(/,\s*/,$args)) {
  111.                 $arg =~ s/^\s*([^\s].*[^\s])\s*$/$1/;
  112.                 $curargs{$arg} = 1;
  113.             }
  114.             $args =~ s/\b(\w)/\$$1/g;
  115.             $args = "local($args) = \@_;\n$t    ";
  116.             }
  117.             s/^\s+//;
  118.             expr();
  119.             $new =~ s/(["\\])/\\$1/g;       #"]);
  120.             $new = reindent($new);
  121.             $args = reindent($args);
  122.             if ($t ne '') {
  123.             $new =~ s/(['\\])/\\$1/g;   #']);
  124.             if ($opt_h) {
  125.                 print OUT $t,
  126.                             "eval \"\\n#line $eval_index $outfile\\n\" . 'sub $name $proto\{\n$t    ${args}eval q($new);\n$t}' unless defined(\&$name);\n";
  127.                             $eval_index++;
  128.             } else {
  129.                 print OUT $t,
  130.                             "eval 'sub $name $proto\{\n$t    ${args}eval q($new);\n$t}' unless defined(\&$name);\n";
  131.             }
  132.             } else {
  133.                       print OUT "unless(defined(\&$name)) {\n    sub $name $proto\{\n\t${args}eval q($new);\n    }\n}\n";
  134.             }
  135.             %curargs = ();
  136.         } else {
  137.             s/^\s+//;
  138.             expr();
  139.             $new = 1 if $new eq '';
  140.             $new = reindent($new);
  141.             $args = reindent($args);
  142.             if ($t ne '') {
  143.             $new =~ s/(['\\])/\\$1/g;        #']);
  144.  
  145.             if ($opt_h) {
  146.                 print OUT $t,"eval \"\\n#line $eval_index $outfile\\n\" . 'sub $name () {",$new,";}' unless defined(\&$name);\n";
  147.                 $eval_index++;
  148.             } else {
  149.                 print OUT $t,"eval 'sub $name () {",$new,";}' unless defined(\&$name);\n";
  150.             }
  151.             } else {
  152.                 # Shunt around such directives as `#define FOO FOO':
  153.                 next if " \&$name" eq $new;
  154.  
  155.                       print OUT $t,"unless(defined(\&$name)) {\n    sub $name () {\t",$new,";}\n}\n";
  156.             }
  157.         }
  158.         } elsif (/^(include|import)\s*[<"](.*)[>"]/) {
  159.         ($incl = $2) =~ s/\.h$/.ph/;
  160.         print OUT $t,"require '$incl';\n";
  161.         } elsif(/^include_next\s*[<"](.*)[>"]/) {
  162.         ($incl = $1) =~ s/\.h$/.ph/;
  163.         print OUT ($t,
  164.                "eval {\n");
  165.                 $tab += 4;
  166.                 $t = "\t" x ($tab / 8) . ' ' x ($tab % 8);
  167.         print OUT ($t,
  168.                "my(\%INCD) = map { \$INC{\$_} => 1 } ",
  169.                "(grep { \$_ eq \"$incl\" } keys(\%INC));\n");
  170.         print OUT ($t,
  171.                "my(\@REM) = map { \"\$_/$incl\" } ",
  172.                "(grep { not exists(\$INCD{\"\$_/$incl\"})",
  173.                "and -f \"\$_/$incl\" } \@INC);\n");
  174.         print OUT ($t,
  175.                "require \"\$REM[0]\" if \@REM;\n");
  176.                 $tab -= 4;
  177.                 $t = "\t" x ($tab / 8) . ' ' x ($tab % 8);
  178.                 print OUT ($t,
  179.                "};\n");
  180.         print OUT ($t,
  181.                "warn(\$\@) if \$\@;\n");
  182.         } elsif (/^ifdef\s+(\w+)/) {
  183.         print OUT $t,"if(defined(&$1)) {\n";
  184.         $tab += 4;
  185.         $t = "\t" x ($tab / 8) . ' ' x ($tab % 8);
  186.         } elsif (/^ifndef\s+(\w+)/) {
  187.         print OUT $t,"unless(defined(&$1)) {\n";
  188.         $tab += 4;
  189.         $t = "\t" x ($tab / 8) . ' ' x ($tab % 8);
  190.         } elsif (s/^if\s+//) {
  191.         $new = '';
  192.         $inif = 1;
  193.         expr();
  194.         $inif = 0;
  195.         print OUT $t,"if($new) {\n";
  196.         $tab += 4;
  197.         $t = "\t" x ($tab / 8) . ' ' x ($tab % 8);
  198.         } elsif (s/^elif\s+//) {
  199.         $new = '';
  200.         $inif = 1;
  201.         expr();
  202.         $inif = 0;
  203.         $tab -= 4;
  204.         $t = "\t" x ($tab / 8) . ' ' x ($tab % 8);
  205.         print OUT $t,"}\n elsif($new) {\n";
  206.         $tab += 4;
  207.         $t = "\t" x ($tab / 8) . ' ' x ($tab % 8);
  208.         } elsif (/^else/) {
  209.         $tab -= 4;
  210.         $t = "\t" x ($tab / 8) . ' ' x ($tab % 8);
  211.         print OUT $t,"} else {\n";
  212.         $tab += 4;
  213.         $t = "\t" x ($tab / 8) . ' ' x ($tab % 8);
  214.         } elsif (/^endif/) {
  215.         $tab -= 4;
  216.         $t = "\t" x ($tab / 8) . ' ' x ($tab % 8);
  217.         print OUT $t,"}\n";
  218.         } elsif(/^undef\s+(\w+)/) {
  219.         print OUT $t, "undef(&$1) if defined(&$1);\n";
  220.         } elsif(/^error\s+(".*")/) {
  221.         print OUT $t, "die($1);\n";
  222.         } elsif(/^error\s+(.*)/) {
  223.         print OUT $t, "die(\"", quotemeta($1), "\");\n";
  224.         } elsif(/^warning\s+(.*)/) {
  225.         print OUT $t, "warn(\"", quotemeta($1), "\");\n";
  226.         } elsif(/^ident\s+(.*)/) {
  227.         print OUT $t, "# $1\n";
  228.         }
  229.      } elsif(/^\s*(typedef\s*)?enum\s*(\s+[a-zA-Z_]\w*\s*)?\{/) {
  230.         until(/\}.*?;/) {
  231.         chomp($next = <IN>);
  232.         $_ .= $next;
  233.         print OUT "# $next\n" if $opt_D;
  234.         }
  235.         s@/\*.*?\*/@@g;
  236.         s/\s+/ /g;
  237.         /^\s?(typedef\s?)?enum\s?([a-zA-Z_]\w*)?\s?\{(.*)\}\s?([a-zA-Z_]\w*)?\s?;/;
  238.         ($enum_subs = $3) =~ s/\s//g;
  239.         @enum_subs = split(/,/, $enum_subs);
  240.         $enum_val = -1;
  241.         for $enum (@enum_subs) {
  242.         ($enum_name, $enum_value) = $enum =~ /^([a-zA-Z_]\w*)(=.+)?$/;
  243.         $enum_value =~ s/^=//;
  244.         $enum_val = (length($enum_value) ? $enum_value : $enum_val + 1);
  245.         if ($opt_h) {
  246.             print OUT ($t,
  247.                    "eval(\"\\n#line $eval_index $outfile\\n",
  248.                    "sub $enum_name () \{ $enum_val; \}\") ",
  249.                    "unless defined(\&$enum_name);\n");
  250.             ++ $eval_index;
  251.         } else {
  252.             print OUT ($t,
  253.                    "eval(\"sub $enum_name () \{ $enum_val; \}\") ",
  254.                    "unless defined(\&$enum_name);\n");
  255.         }
  256.         }
  257.     }
  258.     }
  259.     print OUT "1;\n";
  260.  
  261.     $is_converted{$file} = 1;
  262.     queue_includes_from($file) if ($opt_a);
  263. }
  264.  
  265. exit $Exit;
  266.  
  267. sub reindent($) {
  268.     my($text) = shift;
  269.     $text =~ s/\n/\n    /g;
  270.     $text =~ s/        /\t/g;
  271.     $text;
  272. }
  273.  
  274. sub expr {
  275.     if(keys(%curargs)) {
  276.     my($joined_args) = join('|', keys(%curargs));
  277.     }
  278.     while ($_ ne '') {
  279.     s/^\&\&// && do { $new .= " &&"; next;}; # handle && operator
  280.     s/^\&([\(a-z\)]+)/$1/i;    # hack for things that take the address of
  281.     s/^(\s+)//        && do {$new .= ' '; next;};
  282.     s/^(0X[0-9A-F]+)[UL]*//i    && do {$new .= lc($1); next;};
  283.     s/^(-?\d+\.\d+E[-+]\d+)F?//i    && do {$new .= $1; next;};
  284.     s/^(\d+)\s*[LU]*//i    && do {$new .= $1; next;};
  285.     s/^("(\\"|[^"])*")//    && do {$new .= $1; next;};
  286.     s/^'((\\"|[^"])*)'//    && do {
  287.         if ($curargs{$1}) {
  288.         $new .= "ord('\$$1')";
  289.         } else {
  290.         $new .= "ord('$1')";
  291.         }
  292.         next;
  293.     };
  294.         # replace "sizeof(foo)" with "{foo}"
  295.         # also, remove * (C dereference operator) to avoid perl syntax
  296.         # problems.  Where the %sizeof array comes from is anyone's
  297.         # guess (c2ph?), but this at least avoids fatal syntax errors.
  298.         # Behavior is undefined if sizeof() delimiters are unbalanced.
  299.         # This code was modified to able to handle constructs like this:
  300.         #   sizeof(*(p)), which appear in the HP-UX 10.01 header files.
  301.         s/^sizeof\s*\(// && do {
  302.             $new .= '$sizeof';
  303.             my $lvl = 1;  # already saw one open paren
  304.             # tack { on the front, and skip it in the loop
  305.             $_ = "{" . "$_";
  306.             my $index = 1;
  307.             # find balanced closing paren
  308.             while ($index <= length($_) && $lvl > 0) {
  309.                 $lvl++ if substr($_, $index, 1) eq "(";
  310.                 $lvl-- if substr($_, $index, 1) eq ")";
  311.                 $index++;
  312.             }
  313.             # tack } on the end, replacing )
  314.             substr($_, $index - 1, 1) = "}";
  315.             # remove pesky * operators within the sizeof argument
  316.             substr($_, 0, $index - 1) =~ s/\*//g;
  317.             next;
  318.         };
  319.     # Eliminate typedefs
  320.     /\(([\w\s]+)[\*\s]*\)\s*[\w\(]/ && do {
  321.         foreach (split /\s+/, $1) {  # Make sure all the words are types,
  322.         last unless ($isatype{$_} or $_ eq 'struct');
  323.         }
  324.         s/\([\w\s]+[\*\s]*\)// && next;      # then eliminate them.
  325.     };
  326.     # struct/union member, including arrays:
  327.     s/^([_A-Z]\w*(\[[^\]]+\])?((\.|->)[_A-Z]\w*(\[[^\]]+\])?)+)//i && do {
  328.         $id = $1;
  329.         $id =~ s/(\.|(->))([^\.\-]*)/->\{$3\}/g;
  330.         $id =~ s/\b([^\$])($joined_args)/$1\$$2/g if length($joined_args);
  331.         while($id =~ /\[\s*([^\$\&\d\]]+)\]/) {
  332.         my($index) = $1;
  333.         $index =~ s/\s//g;
  334.         if(exists($curargs{$index})) {
  335.             $index = "\$$index";
  336.         } else {
  337.             $index = "&$index";
  338.         }
  339.         $id =~ s/\[\s*([^\$\&\d\]]+)\]/[$index]/;
  340.         }
  341.         $new .= " (\$$id)";
  342.     };
  343.     s/^([_a-zA-Z]\w*)//    && do {
  344.         $id = $1;
  345.         if ($id eq 'struct') {
  346.         s/^\s+(\w+)//;
  347.         $id .= ' ' . $1;
  348.         $isatype{$id} = 1;
  349.         } elsif ($id =~ /^((un)?signed)|(long)|(short)$/) {
  350.         while (s/^\s+(\w+)//) { $id .= ' ' . $1; }
  351.         $isatype{$id} = 1;
  352.         }
  353.         if ($curargs{$id}) {
  354.         $new .= "\$$id";
  355.         $new .= '->' if /^[\[\{]/;
  356.         } elsif ($id eq 'defined') {
  357.         $new .= 'defined';
  358.         } elsif (/^\(/) {
  359.         s/^\((\w),/("$1",/ if $id =~ /^_IO[WR]*$/i;    # cheat
  360.         $new .= " &$id";
  361.         } elsif ($isatype{$id}) {
  362.         if ($new =~ /{\s*$/) {
  363.             $new .= "'$id'";
  364.         } elsif ($new =~ /\(\s*$/ && /^[\s*]*\)/) {
  365.             $new =~ s/\(\s*$//;
  366.             s/^[\s*]*\)//;
  367.         } else {
  368.             $new .= q(').$id.q(');
  369.         }
  370.         } else {
  371.         if ($inif && $new !~ /defined\s*\($/) {
  372.             $new .= '(defined(&' . $id . ') ? &' . $id . ' : 0)';
  373.         } elsif (/^\[/) {
  374.             $new .= " \$$id";
  375.         } else {
  376.             $new .= ' &' . $id;
  377.         }
  378.         }
  379.         next;
  380.     };
  381.     s/^(.)// && do { if ($1 ne '#') { $new .= $1; } next;};
  382.     }
  383. }
  384.  
  385.  
  386. # Handle recursive subdirectories without getting a grotesquely big stack.
  387. # Could this be implemented using File::Find?
  388. sub next_file
  389. {
  390.     my $file;
  391.  
  392.     while (@ARGV) {
  393.         $file = shift @ARGV;
  394.  
  395.         if ($file eq '-' or -f $file or -l $file) {
  396.             return $file;
  397.         } elsif (-d $file) {
  398.             if ($opt_r) {
  399.                 expand_glob($file);
  400.             } else {
  401.                 print STDERR "Skipping directory `$file'\n";
  402.             }
  403.         } elsif ($opt_a) {
  404.             return $file;
  405.         } else {
  406.             print STDERR "Skipping `$file':  not a file or directory\n";
  407.         }
  408.     }
  409.  
  410.     return undef;
  411. }
  412.  
  413.  
  414. # Put all the files in $directory into @ARGV for processing.
  415. sub expand_glob
  416. {
  417.     my ($directory)  = @_;
  418.  
  419.     $directory =~ s:/$::;
  420.  
  421.     opendir DIR, $directory;
  422.         foreach (readdir DIR) {
  423.             next if ($_ eq '.' or $_ eq '..');
  424.  
  425.             # expand_glob() is going to be called until $ARGV[0] isn't a
  426.             # directory; so push directories, and unshift everything else.
  427.             if (-d "$directory/$_") { push    @ARGV, "$directory/$_" }
  428.             else                    { unshift @ARGV, "$directory/$_" }
  429.         }
  430.     closedir DIR;
  431. }
  432.  
  433.  
  434. # Given $file, a symbolic link to a directory in the C include directory,
  435. # make an equivalent symbolic link in $Dest_dir, if we can figure out how.
  436. # Otherwise, just duplicate the file or directory.
  437. sub link_if_possible
  438. {
  439.     my ($dirlink)  = @_;
  440.     my $target  = eval 'readlink($dirlink)';
  441.  
  442.     if ($target =~ m:^\.\./: or $target =~ m:^/:) {
  443.         # The target of a parent or absolute link could leave the $Dest_dir
  444.         # hierarchy, so let's put all of the contents of $dirlink (actually,
  445.         # the contents of $target) into @ARGV; as a side effect down the
  446.         # line, $dirlink will get created as an _actual_ directory.
  447.         expand_glob($dirlink);
  448.     } else {
  449.         if (-l "$Dest_dir/$dirlink") {
  450.             unlink "$Dest_dir/$dirlink" or
  451.                 print STDERR "Could not remove link $Dest_dir/$dirlink:  $!\n";
  452.         }
  453.  
  454.         if (eval 'symlink($target, "$Dest_dir/$dirlink")') {
  455.             print "Linking $target -> $Dest_dir/$dirlink\n";
  456.  
  457.             # Make sure that the link _links_ to something:
  458.             if (! -e "$Dest_dir/$target") {
  459.                 mkpath("$Dest_dir/$target", 0755) or
  460.                     print STDERR "Could not create $Dest_dir/$target/\n";
  461.             }
  462.         } else {
  463.             print STDERR "Could not symlink $target -> $Dest_dir/$dirlink:  $!\n";
  464.         }
  465.     }
  466. }
  467.  
  468.  
  469. # Push all #included files in $file onto our stack, except for STDIN
  470. # and files we've already processed.
  471. sub queue_includes_from
  472. {
  473.     my ($file)    = @_;
  474.     my $line;
  475.  
  476.     return if ($file eq "-");
  477.  
  478.     open HEADER, $file or return;
  479.         while (defined($line = <HEADER>)) {
  480.             while (/\\$/) { # Handle continuation lines
  481.                 chop $line;
  482.                 $line .= <HEADER>;
  483.             }
  484.  
  485.             if ($line =~ /^#\s*include\s+<(.*?)>/) {
  486.                 push(@ARGV, $1) unless $is_converted{$1};
  487.             }
  488.         }
  489.     close HEADER;
  490. }
  491.  
  492.  
  493. # Determine include directories; $Config{usrinc} should be enough for (all
  494. # non-GCC?) C compilers, but gcc uses an additional include directory.
  495. sub inc_dirs
  496. {
  497.     my $from_gcc    = `$Config{cc} -v 2>&1`;
  498.     $from_gcc       =~ s:^Reading specs from (.*?)/specs\b.*:$1/include:s;
  499.  
  500.     length($from_gcc) ? ($from_gcc, $Config{usrinc}) : ($Config{usrinc});
  501. }
  502.  
  503.  
  504. # Create "_h2ph_pre.ph", if it doesn't exist or was built by a different
  505. # version of h2ph.
  506. sub build_preamble_if_necessary
  507. {
  508.     # Increment $VERSION every time this function is modified:
  509.     my $VERSION     = 1;
  510.     my $preamble    = "$Dest_dir/_h2ph_pre.ph";
  511.  
  512.     # Can we skip building the preamble file?
  513.     if (-r $preamble) {
  514.         # Extract version number from first line of preamble:
  515.         open  PREAMBLE, $preamble or die "Cannot open $preamble:  $!";
  516.             my $line = <PREAMBLE>;
  517.             $line =~ /(\b\d+\b)/;
  518.         close PREAMBLE            or die "Cannot close $preamble:  $!";
  519.  
  520.         # Don't build preamble if a compatible preamble exists:
  521.         return if $1 == $VERSION;
  522.     }
  523.  
  524.     my (%define) = _extract_cc_defines();
  525.  
  526.     open  PREAMBLE, ">$preamble" or die "Cannot open $preamble:  $!";
  527.         print PREAMBLE "# This file was created by h2ph version $VERSION\n";
  528.  
  529.         foreach (sort keys %define) {
  530.             if ($opt_D) {
  531.                 print PREAMBLE "# $_=$define{$_}\n";
  532.             }
  533.  
  534.             if ($define{$_} =~ /^\d+$/) {
  535.                 print PREAMBLE
  536.                     "unless (defined &$_) { sub $_() { $define{$_} } }\n\n";
  537.             } else {
  538.                 print PREAMBLE
  539.                     "unless (defined &$_) { sub $_() { \"",
  540.                     quotemeta($define{$_}), "\" } }\n\n";
  541.             }
  542.         }
  543.     close PREAMBLE               or die "Cannot close $preamble:  $!";
  544. }
  545.  
  546.  
  547. # %Config contains information on macros that are pre-defined by the
  548. # system's compiler.  We need this information to make the .ph files
  549. # function with perl as the .h files do with cc.
  550. sub _extract_cc_defines
  551. {
  552.     my %define;
  553.     my $allsymbols = join " ", @Config{ccsymbols, cppsymbols, cppccsymbols};
  554.  
  555.     # Split compiler pre-definitions into `key=value' pairs:
  556.     foreach (split /\s+/, $allsymbols) {
  557.         /(.*?)=(.*)/;
  558.         $define{$1} = $2;
  559.  
  560.         if ($opt_D) {
  561.             print STDERR "$_:  $1 -> $2\n";
  562.         }
  563.     }
  564.  
  565.     return %define;
  566. }
  567.  
  568.  
  569. 1;
  570.  
  571. ##############################################################################
  572. __END__
  573.  
  574. =head1 NAME
  575.  
  576. h2ph - convert .h C header files to .ph Perl header files
  577.  
  578. =head1 SYNOPSIS
  579.  
  580. B<h2ph [-d destination directory] [-r | -a] [-l] [headerfiles]>
  581.  
  582. =head1 DESCRIPTION
  583.  
  584. I<h2ph>
  585. converts any C header files specified to the corresponding Perl header file
  586. format.
  587. It is most easily run while in /usr/include:
  588.  
  589.     cd /usr/include; h2ph * sys/*
  590.  
  591. or
  592.  
  593.     cd /usr/include; h2ph -r -l .
  594.  
  595. The output files are placed in the hierarchy rooted at Perl's
  596. architecture dependent library directory.  You can specify a different
  597. hierarchy with a B<-d> switch.
  598.  
  599. If run with no arguments, filters standard input to standard output.
  600.  
  601. =head1 OPTIONS
  602.  
  603. =over 4
  604.  
  605. =item -d destination_dir
  606.  
  607. Put the resulting B<.ph> files beneath B<destination_dir>, instead of
  608. beneath the default Perl library location (C<$Config{'installsitsearch'}>).
  609.  
  610. =item -r
  611.  
  612. Run recursively; if any of B<headerfiles> are directories, then run I<h2ph>
  613. on all files in those directories (and their subdirectories, etc.).  B<-r>
  614. and B<-a> are mutually exclusive.
  615.  
  616. =item -a
  617.  
  618. Run automagically; convert B<headerfiles>, as well as any B<.h> files
  619. which they include.  This option will search for B<.h> files in all
  620. directories which your C compiler ordinarily uses.  B<-a> and B<-r> are
  621. mutually exclusive.
  622.  
  623. =item -l
  624.  
  625. Symbolic links will be replicated in the destination directory.  If B<-l>
  626. is not specified, then links are skipped over.
  627.  
  628. =item -h
  629.  
  630. Put ``hints'' in the .ph files which will help in locating problems with
  631. I<h2ph>.  In those cases when you B<require> a B<.ph> file containing syntax
  632. errors, instead of the cryptic
  633.  
  634.     [ some error condition ] at (eval mmm) line nnn
  635.  
  636. you will see the slightly more helpful
  637.  
  638.     [ some error condition ] at filename.ph line nnn
  639.  
  640. However, the B<.ph> files almost double in size when built using B<-h>.
  641.  
  642. =item -D
  643.  
  644. Include the code from the B<.h> file as a comment in the B<.ph> file.
  645. This is primarily used for debugging I<h2ph>.
  646.  
  647. =item -Q
  648.  
  649. ``Quiet'' mode; don't print out the names of the files being converted.
  650.  
  651. =back
  652.  
  653. =head1 ENVIRONMENT
  654.  
  655. No environment variables are used.
  656.  
  657. =head1 FILES
  658.  
  659.  /usr/include/*.h
  660.  /usr/include/sys/*.h
  661.  
  662. etc.
  663.  
  664. =head1 AUTHOR
  665.  
  666. Larry Wall
  667.  
  668. =head1 SEE ALSO
  669.  
  670. perl(1)
  671.  
  672. =head1 DIAGNOSTICS
  673.  
  674. The usual warnings if it can't read or write the files involved.
  675.  
  676. =head1 BUGS
  677.  
  678. Doesn't construct the %sizeof array for you.
  679.  
  680. It doesn't handle all C constructs, but it does attempt to isolate
  681. definitions inside evals so that you can get at the definitions
  682. that it can translate.
  683.  
  684. It's only intended as a rough tool.
  685. You may need to dicker with the files produced.
  686.  
  687. Doesn't run with C<use strict>
  688.  
  689. You have to run this program by hand; it's not run as part of the Perl
  690. installation.
  691.  
  692. Doesn't handle complicated expressions built piecemeal, a la:
  693.  
  694.     enum {
  695.         FIRST_VALUE,
  696.         SECOND_VALUE,
  697.     #ifdef ABC
  698.         THIRD_VALUE
  699.     #endif
  700.     };
  701.  
  702. Doesn't necessarily locate all of your C compiler's internally-defined
  703. symbols.
  704.  
  705. =cut
  706.  
  707. __END__
  708. :endofperl
  709.