1h2pas(1) Free Pascal C header conversion utility h2pas(1)
2
3
4
6 h2pas - The C header to pascal unit conversion program.
7
8
10 h2pas [options] filename
11
12
14 h2pas attempts to convert a C header file to a pascal unit. it can
15 handle most C constructs that one finds in a C header file, and
16 attempts to translate them to their pascal counterparts. see the CON‐
17 STRUCTS section for a full description of what the translator can han‐
18 dle.
19
20
22 H2pas is a command-line tool that translates a C header file to a spas‐
23 cal unit. It reads the C header file and translates the C declarations
24 to equivalent pascal declarations that can be used to access code writ‐
25 ten in C.
26
27 The output of the h2pas program is written to a file with the same name
28 as the C header file that was used as input, but with the extension
29 .pp. The output file that h2pas creates can be customized in a number
30 of ways by means of many options.
31
32
34 The output of h2pas can be controlled with the following options:
35
36
37
38 -d use external; for all procedure and function declarations.
39
40 -D use external libname name 'func_name' for function and procedure
41 declarations.
42
43 -e Emit a series of constants instead of an enumeration type for
44 the C enum construct.
45
46 -i create an include file instead of a unit (omits the unit
47 header).
48
49 -l libname
50 specify the library name for external function declarations.
51
52 -o outfile
53 Specify the output file name. Default is the input file name
54 with the extension replaced by .pp "."
55
56 -p use the letter P in front of pointer type parameters instead of
57 "^".
58
59 -s Strip comments from the input file. By default comments are con‐
60 verted to comments, but they may be displaced, since a comment
61 is handled by the scanner.
62
63 -t prepend typedef type names with the letter T (used to follow
64 Borland's convention that all types should be defined with T).
65
66 -v replace pointer parameters by call by reference parameters. Use
67 with care because some calls can expect a NIL pointer.
68
69 -w Header file is a win32 header file (adds support for some spe‐
70 cial macros).
71
72 -x handle SYS_TRAP of the PalmOS header files.
73
74
76 The following C declarations and statements are recognized:
77
78
79 defines
80 defines are changed into pascal constants if they are simple
81 defines. macros are changed - wherever possible to functions;
82 however the arguments are all integers, so these must be changed
83 manually. Simple expressions in define staments are recognized,
84 as are most arithmetic operators: addition, substraction, multi‐
85 plication, division, logical operators, comparision operators,
86 shift operators. The C construct ( A ? B : C) is also recognized
87 and translated to a pascal construct with an IF statement (this
88 is buggy, however).
89
90
91 preprocessor statements
92 the conditional preprocessing commands are recognized and trans‐
93 lated into equivalent pascal compiler directives. The special
94 #ifdef __cplusplus is also recognized and removed.
95
96
97
98 typedef
99 A typedef statement is changed into a pascal type statement. The
100 following basic types are recognized:
101
102 char changed to char.
103
104 float changed to real (=double in free pascal).
105
106 int changed to longint.
107
108 long changed to longint.
109
110 long int
111 changed to longint.
112
113 short changed to integer.
114
115 unsigned
116 changed to cardinal.
117
118 unsigned char
119 changed to byte.
120
121 unsigned int
122 changed to cardinal.
123
124 unsigned long int
125 changed to cardinal.
126
127 unsigned short
128 changed to word.
129
130 void ignored.
131 These types are also changed if they appear in the arguments of a func‐
132 tion or procedure.
133
134 functions and procedures
135 functions and procedures are translated as well; pointer types
136 may be changed to call by reference arguments (using the var
137 argument) by using the -p command line argument. functions that
138 have a variable number of arguments are changed to a function
139 with an array of const argument.
140
141 specifiers
142 the extern specifier is recognized; however it is ignored. the
143 packed specifier is also recognised and changed with the PACK‐
144 RECORDS directive. The const specifier is also recognized, but
145 is ignored.
146
147
148 modifiers
149 If the -w option is specified, then the following modifiers are
150 recognized: STDCALL , CDECL , CALLBACK , PASCAL , WINAPI , API‐
151 ENTRY , WINGDIAPI as defined in the win32 headers. If addition‐
152 ally the -x option is specified then the SYS_TRAP specifier is
153 also recognized.
154
155
156 enums enum constructs are changed into enumeration types; bear in mind
157 that in C enumeration types can have values assigned to them;
158 Free Pascal also allows this to a certain degree. If you know
159 that values are assigned to enums, it is best to use the -e
160 option to change the enus to a series of integer constants.
161
162
163 unions unions are changed to variant records.
164
165
166 structs
167 are changed to pascal records, with C packing.
168
169
171 ppc386(1) ppumove(1)
172
173
174
175Free Pascal 12 Dec 1999 h2pas(1)