Sign in Join
Wiki copytemporary

Chelper: what changed

Revision 3 to 4. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
11### About
22
33Chelper is Lazarus extension tool, that helps converting C headers to Pascal. Yes, it's yet another C-to-Pascal converting tool like lot of similar ([[H2Pas]], ToPas), but one might find it more useful.
44
55The extension doesn't try to convert a header for the user, instead it's a tool to help with manual translation, doing almost all of "dirty work" for the user.
66
77Chelper also supports converting Objective-C declarations into Objective-P.
88
99### Author
1010
1111Dmitry 'skalogryz' Boyarintsev
1212
1313### License
1414
1515[modified](http://svn.freepascal.org/svn/lazarus/trunk/COPYING.modifiedLGPL) [LGPL](http://svn.freepascal.org/svn/lazarus/trunk/COPYING.LGPL) (same as the FPC RTL and the Lazarus LCL). You can contact the author if the modified LGPL doesn't work with your project licensing.
1616
1717### Download
1818
1919There's no "downloadable" package yet, you can access the tool from SVN:
2020
2121<https://sourceforge.net/p/lazarus-ccr/svn/HEAD/tree/components/chelper/>
2222
23-```
23+```text
2424svn checkout https://svn.code.sf.net/p/lazarus-ccr/svn/components/chelper/
2525```
2626
2727### Change Log
2828
2929- Version 0.8, 8 Aug 2010
3030
3131### Dependencies / System Requirements
3232
3333- Lazarus 0.9.29 or Higher
3434
3535Status: *Beta*
3636
3737### Issues
3838
3939- No complete expression parser to construct the expression tree.
4040
4141If you find a bug in the converter please report it to [bugs.freepascal.org](http://bugs.freepascal.org) for Lazarus-CCR project. Please attach the C-header text and the explanation what doesn't work as expected.
4242
4343### Installation
4444
4545- Get the package from SVN
4646- Install Chelper.lpk package to the Lazarus.
4747- Go to *Tools-\>C to Pascal Options-\>Converter*, uncheck *Use external converter* if you want to use the package built-in converter.
4848
4949Using built-in converter has an advantage of the performance. However, if you'll need to update converter, you'll need to rebuild the whole IDE. It's also possible that converter might cause crashes or hangs. You should bug report it, but you're risking to loose all of your data.
5050
5151It's much safer to use the external cconvert tool. It's also easier to update the converter if a new features are added or bugs fixed. All you need is to rebuild the cconverter executable a lot of faster than rebuilding Lazarus.
5252
5353To use the external tool, you need to do the following:
5454
5555- Open and build cconvert.lpi project (located at the package directory). You should get "cconvert" executable file.
5656- Open Tools-\>C to Pascal Options-\>Converter, press Select and choose cconvert executable file.
5757- Check *Use external converter* at *Tools-\>C to Pascal Options-\>Converter*
5858
5959### How to use
6060
6161#### Shortkeys
6262
6363- ctrl+b - convert a single C declaration to Pascal
6464- ctrl+shift+b - convert all C declarations to Pascal from the current cursor position to the end of the file.
6565
6666#### General
6767
6868- Open a file with C declarations in Lazarus IDE or start a new file copying declarations there
6969- Place the cursor at the line where C declaration and press Ctrl+B (the shortcut would be modifiable in future).
7070
7171for example:
7272
73-```
73+```text
7474int c;
7575int b;
7676```
7777
7878if the cursor placed at 'inc c;' line and ctrl+b pressed the result would be:
7979
8080``` pascal
8181var
8282 c : Integer;
8383int b;
8484```
8585
8686exactly one definition is converted. The cursor would be place right after the converted definition. You can press ctrl+b again, and the result would be:
8787
8888``` pascal
8989var
9090 c : Integer;
9191var
9292 b : Integer;
9393```
9494
9595Parsing definitions one-by-one will get your C headers ready with a very short period of time, as well as keeping it clean and correct from Pascal point of view.
9696
9797- If you're sure your defines (explained below) are configured well enough. You can try to convert the rest of the file in one call by pressing ctrl+shift+b
9898
9999i.e. you have 2 declarations in the file:
100100
101-```
101+```text
102102int fn(int, float);
103103extern int v;
104104```
105105
106106placing the cursor before them and pressing ctrl+shift+b, would generate.
107107
108108``` pascal
109109function fn(par0: Integer; par1: Single): Integer; cdecl; external;
110110
111111var
112112 v : Integer; external;
113113```
114114
115115**You must be careful, because it's common to use macros in C headers. Leaving any of macros undefined might produce wrong pascal declaration**. The next section explains how to define a macro for the chelper.
116116
117117#### Defines
118118
119119In most cases parameterless macro definitions, like
120120
121-```
121+```text
122122#define VALUE 1 << 2;
123123```
124124
125125are used like constant values. Chelper translates them as constants trying to convert the define expression.
126126
127127``` pascal
128128const
129129 VALUE = 1 shr 2;
130130```
131131
132132In other cases defines are used for some "special" markings or additional information for external tools.
133133
134-```
134+```text
135135#define LIB_DEPRECATED
136136LIB_DEPRECATED int somefunc(int p);
137137```
138138
139139without the knowledge of LIB_DEPRECATED being the macro (of nothing), it's impossible to parse function declaration correctly. You can specify macros used by Chelper in the special defines file.
140140
141141Select Tools-\>C to Pascal options-\>Main select the defines file and press Edit.
142142
143143This would open the custom defines file in Lazarus IDE. All macros declared at this file are used by Chelper. After adding/editing macro defines save the file and you can return to the C header converting.
144144
145145Chelper handles parameter macros as well.
146146
147-```
147+```text
148148int somefunc SAFE_PARAMS( (int i))
149149```
150150
151151adding the the following declaration into defines file
152152
153-```
153+```text
154154#define SAFE_PARAMS(x) x
155155```
156156
157157will allow to parse the declaration correctly
158158
159159``` pascal
160160function somefunc(i: Integer): Integer;
161161```
162162
163163#### Configuration File
164164
165165Configuration file represents itself a simple .ini file. Following section are used in the file:
166166
167167- Main - for general declarations, that effects
168168
169169- Types - custom type conversion section. Name=Value, where Name is the c-type name, Value is resulting pascal type
170170
171171example:
172172
173-```
173+```text
174174[Types]
175175int=integer
176176int*=PInteger
177177float=single
178178float*=PSingle
179179```
180180
181181---
182182*From the Free Pascal wiki, page "Chelper", as it stood on 2022-04-30 after a change by E-ric, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*

Back to history