IP : 3.21.34.214Hostname : server86.web-hosting.comKernel : Linux server86.web-hosting.com 4.18.0-513.18.1.lve.el8.x86_64 #1 SMP Thu Feb 22 12:55:50 UTC 2024 x86_64Disable Function : None :) OS : Linux
PATH:
/
home/
./
../
../
./
usr/
bin/
h2ph/
/
#!/usr/bin/perl eval 'exec /usr/bin/perl -S $0 ${1+"$@"}' if $running_under_some_shell;
BEGIN { pop @INC if $INC[-1] eq '.' }
use strict;
use Config; use File::Path qw(mkpath); use Getopt::Std;
# Make sure read permissions for all are set: if (defined umask && (umask() & 0444)) { umask (umask() & ~0444); }
getopts('Dd:rlhaQe'); use vars qw($opt_D $opt_d $opt_r $opt_l $opt_h $opt_a $opt_Q $opt_e); die "-r and -a options are mutually exclusive\n" if ($opt_r and $opt_a); my @inc_dirs = inc_dirs() if $opt_a;
my $Exit = 0;
my $Dest_dir = $opt_d || $Config{installsitearch}; die "Destination directory $Dest_dir doesn't exist or isn't a directory\n" unless -d $Dest_dir;
my @isatype = qw( char uchar u_char short ushort u_short int uint u_int long ulong u_long FILE key_t caddr_t float double size_t );
my %isatype; @isatype{@isatype} = (1) x @isatype; my $inif = 0; my %Is_converted; my %bad_file = ();
# Handle recursive subdirectories without getting a grotesquely big stack. # Could this be implemented using File::Find? sub next_file { my $file;
while (@ARGV) { $file = shift @ARGV;
if ($file eq '-' or -f $file or -l $file) { return $file; } elsif (-d $file) { if ($opt_r) { expand_glob($file); } else { print STDERR "Skipping directory '$file'\n"; } } elsif ($opt_a) { return $file; } else { print STDERR "Skipping '$file': not a file or directory\n"; } }
return undef; }
# Put all the files in $directory into @ARGV for processing. sub expand_glob { my ($directory) = @_;
$directory =~ s:/$::;
opendir DIR, $directory; foreach (readdir DIR) { next if ($_ eq '.' or $_ eq '..');
# expand_glob() is going to be called until $ARGV[0] isn't a # directory; so push directories, and unshift everything else. if (-d "$directory/$_") { push @ARGV, "$directory/$_" } else { unshift @ARGV, "$directory/$_" } } closedir DIR; }
# Given $file, a symbolic link to a directory in the C include directory, # make an equivalent symbolic link in $Dest_dir, if we can figure out how. # Otherwise, just duplicate the file or directory. sub link_if_possible { my ($dirlink) = @_; my $target = eval 'readlink($dirlink)';
if ($target =~ m:^\.\./: or $target =~ m:^/:) { # The target of a parent or absolute link could leave the $Dest_dir # hierarchy, so let's put all of the contents of $dirlink (actually, # the contents of $target) into @ARGV; as a side effect down the # line, $dirlink will get created as an _actual_ directory. expand_glob($dirlink); } else { if (-l "$Dest_dir/$dirlink") { unlink "$Dest_dir/$dirlink" or print STDERR "Could not remove link $Dest_dir/$dirlink: $!\n"; }
if (eval 'symlink($target, "$Dest_dir/$dirlink")') { print "Linking $target -> $Dest_dir/$dirlink\n";
# Make sure that the link _links_ to something: if (! -e "$Dest_dir/$target") { mkpath("$Dest_dir/$target", 0755) or print STDERR "Could not create $Dest_dir/$target/\n"; } } else { print STDERR "Could not symlink $target -> $Dest_dir/$dirlink: $!\n"; } } }
# Push all #included files in $file onto our stack, except for STDIN # and files we've already processed. sub queue_includes_from { my ($file) = @_; my $line;
return if ($file eq "-");
open HEADER, "<", $file or return; while (defined($line = <HEADER>)) { while (/\\$/) { # Handle continuation lines chop $line; $line .= <HEADER>; }
if ($line =~ /^#\s*include\s+([<"])(.*?)[>"]/) { my ($delimiter, $new_file) = ($1, $2); # copy the prefix in the quote syntax (#include "x.h") case if ($delimiter eq q{"} && $file =~ m|^(.*)/|) { $new_file = "$1/$new_file"; } push(@ARGV, $new_file) unless $Is_converted{$new_file}; } } close HEADER; }
# Determine include directories; $Config{usrinc} should be enough for (all # non-GCC?) C compilers, but gcc uses additional include directories. sub inc_dirs { my $from_gcc = `LC_ALL=C $Config{cc} -v -E - < /dev/null 2>&1 | awk '/^#include/, /^End of search list/' | grep '^ '`; length($from_gcc) ? (split(' ', $from_gcc), $Config{usrinc}) : ($Config{usrinc}); }
# Create "_h2ph_pre.ph", if it doesn't exist or was built by a different # version of h2ph. sub build_preamble_if_necessary { # Increment $VERSION every time this function is modified: my $VERSION = 4; my $preamble = "$Dest_dir/_h2ph_pre.ph";
# Can we skip building the preamble file? if (-r $preamble) { # Extract version number from first line of preamble: open PREAMBLE, "<", $preamble or die "Cannot open $preamble: $!"; my $line = <PREAMBLE>; $line =~ /(\b\d+\b)/; close PREAMBLE or die "Cannot close $preamble: $!";
# Don't build preamble if a compatible preamble exists: return if $1 == $VERSION; }
my (%define) = _extract_cc_defines();
open PREAMBLE, ">", $preamble or die "Cannot open $preamble: $!"; print PREAMBLE "# This file was created by h2ph version $VERSION\n"; # Prevent non-portable hex constants from warning. # # We still produce an overflow warning if we can't represent # a hex constant as an integer. print PREAMBLE "no warnings qw(portable);\n";
foreach (sort keys %define) { if ($opt_D) { print PREAMBLE "# $_=$define{$_}\n"; } if ($define{$_} =~ /^\((.*)\)$/) { # parenthesized value: d=(v) $define{$_} = $1; } if (/^(\w+)\((\w)\)$/) { my($macro, $arg) = ($1, $2); my $def = $define{$_}; $def =~ s/$arg/\$\{$arg\}/g; print PREAMBLE <<DEFINE; unless (defined &$macro) { sub $macro(\$) { my (\$$arg) = \@_; \"$def\" } }
DEFINE } elsif ($define{$_} =~ /^([+-]?(\d+)?\.\d+([eE][+-]?\d+)?)[FL]?$/) { # float: print PREAMBLE "unless (defined &$_) { sub $_() { $1 } }\n\n"; } elsif ($define{$_} =~ /^([+-]?\d+)U?L{0,2}$/i) { # integer: print PREAMBLE "unless (defined &$_) { sub $_() { $1 } }\n\n"; } elsif ($define{$_} =~ /^([+-]?0x[\da-f]+)U?L{0,2}$/i) { # hex integer # Special cased, since perl warns on hex integers # that can't be represented in a UV. # # This way we get the warning at time of use, so the user # only gets the warning if they happen to use this # platform-specific definition. my $code = $1; $code = "hex('$code')" if length $code > 10; print PREAMBLE "unless (defined &$_) { sub $_() { $code } }\n\n"; } elsif ($define{$_} =~ /^\w+$/) { my $def = $define{$_}; if ($isatype{$def}) { print PREAMBLE "unless (defined &$_) { sub $_() { \"$def\" } }\n\n"; } else { print PREAMBLE "unless (defined &$_) { sub $_() { &$def } }\n\n"; } } else { print PREAMBLE "unless (defined &$_) { sub $_() { \"", quotemeta($define{$_}), "\" } }\n\n"; } } print PREAMBLE "\n1;\n"; # avoid 'did not return a true value' when empty close PREAMBLE or die "Cannot close $preamble: $!"; }
# %Config contains information on macros that are pre-defined by the # system's compiler. We need this information to make the .ph files # function with perl as the .h files do with cc. sub _extract_cc_defines { my %define; my $allsymbols = join " ", @Config{'ccsymbols', 'cppsymbols', 'cppccsymbols'};
# If optimizing -O2 is used, add the definition if ($Config{'ccflags'} =~ /(?:\s+|^)-O([\d]+)(?:\s+|$)/) { $allsymbols .= " __OPTIMIZE__=$1"; }
# Split compiler pre-definitions into 'key=value' pairs: while ($allsymbols =~ /([^\s]+)=((\\\s|[^\s])+)/g) { $define{$1} = $2; if ($opt_D) { print STDERR "$_: $1 -> $2\n"; } }
I<h2ph> converts any C header files specified to the corresponding Perl header file format. It is most easily run while in /usr/include:
cd /usr/include; h2ph * sys/*
or
cd /usr/include; h2ph * sys/* arpa/* netinet/*
or
cd /usr/include; h2ph -r -l .
The output files are placed in the hierarchy rooted at Perl's architecture dependent library directory. You can specify a different hierarchy with a B<-d> switch.
If run with no arguments, filters standard input to standard output.
=head1 OPTIONS
=over 4
=item -d destination_dir
Put the resulting B<.ph> files beneath B<destination_dir>, instead of beneath the default Perl library location (C<$Config{'installsitearch'}>).
=item -r
Run recursively; if any of B<headerfiles> are directories, then run I<h2ph> on all files in those directories (and their subdirectories, etc.). B<-r> and B<-a> are mutually exclusive.
=item -a
Run automagically; convert B<headerfiles>, as well as any B<.h> files which they include. This option will search for B<.h> files in all directories which your C compiler ordinarily uses. B<-a> and B<-r> are mutually exclusive.
=item -l
Symbolic links will be replicated in the destination directory. If B<-l> is not specified, then links are skipped over.
=item -h
Put 'hints' in the .ph files which will help in locating problems with I<h2ph>. In those cases when you B<require> a B<.ph> file containing syntax errors, instead of the cryptic
[ some error condition ] at (eval mmm) line nnn
you will see the slightly more helpful
[ some error condition ] at filename.ph line nnn
However, the B<.ph> files almost double in size when built using B<-h>.
=item -e
If an error is encountered during conversion, output file will be removed and a warning emitted instead of terminating the conversion immediately.
=item -D
Include the code from the B<.h> file as a comment in the B<.ph> file. This is primarily used for debugging I<h2ph>.
=item -Q
'Quiet' mode; don't print out the names of the files being converted.
=back
=head1 ENVIRONMENT
No environment variables are used.
=head1 FILES
/usr/include/*.h /usr/include/sys/*.h
etc.
=head1 AUTHOR
Larry Wall
=head1 SEE ALSO
perl(1)
=head1 DIAGNOSTICS
The usual warnings if it can't read or write the files involved.
=head1 BUGS
Doesn't construct the %sizeof array for you.
It doesn't handle all C constructs, but it does attempt to isolate definitions inside evals so that you can get at the definitions that it can translate.
It's only intended as a rough tool. You may need to dicker with the files produced.
You have to run this program by hand; it's not run as part of the Perl installation.
Doesn't handle complicated expressions built piecemeal, a la: