h2ph
Convert C header files to Perl equivalents
SYNOPSIS
h2ph [options] [header_files...]
PARAMETERS
-d directory
Specify the directory to output the generated Perl files. If not specified, the current directory is used.
-h
Display help information.
-v
Verbose mode. Print more information during the conversion process.
DESCRIPTION
h2ph is a utility that converts C header files into Perl include files. It parses C header files and generates corresponding Perl code that defines constants and structures found within the headers. This allows Perl scripts to directly access C-level definitions, facilitating interaction with C libraries and system calls.
The primary purpose of h2ph is to simplify the integration of Perl with existing C codebases. By automatically creating Perl equivalents of C header files, it eliminates the need for manual translation, which can be time-consuming and error-prone. The output of h2ph consists of Perl files (typically with the '.ph' extension) that can be included in Perl scripts using the `require` or `use` statements.
The generated Perl code defines constants as Perl variables, and provides mechanisms for accessing structure members. Using this functionality, Perl programs can then easily read and write directly to system structures, or call C functions that require predefined constant values.
CAVEATS
h2ph may not be able to handle all C header file constructs. Complex preprocessor directives, macros, and certain data types might cause issues. Careful review of the generated Perl code is always recommended.
USAGE EXAMPLE
To convert the standard system header file `stdio.h` and place the resulting Perl file in a directory named `MyPerlHeaders`, you would use the command: `h2ph -d MyPerlHeaders /usr/include/stdio.h`
HISTORY
h2ph was created to bridge the gap between Perl and C programming languages. As Perl gained popularity, the need to interact with existing C libraries and system calls became apparent. h2ph addressed this need by providing an automated way to generate Perl equivalents of C header files, thus simplifying the integration process. The tool has been widely used in Perl projects that require low-level system access or interaction with C-based APIs.
SEE ALSO
perl(1)