Sign in Join
Wiki copytemporary

Chelper: what changed

Revision 1 to 2. 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
2323`svn checkout `[`https://svn.code.sf.net/p/lazarus-ccr/svn/components/chelper/`](https://svn.code.sf.net/p/lazarus-ccr/svn/components/chelper/)
2424
2525### Change Log
2626
2727- Version 0.8, 8 Aug 2010
2828
2929### Dependencies / System Requirements
3030
3131- Lazarus 0.9.29 or Higher
3232
3333Status: *Beta*
3434
3535### Issues
3636
3737- No complete expression parser to construct the expression tree.
3838
3939If 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.
4040
4141### Installation
4242
4343- Get the package from SVN
4444- Install Chelper.lpk package to the Lazarus.
4545- Go to *Tools-\>C to Pascal Options-\>Converter*, uncheck *Use external converter* if you want to use the package built-in converter.
4646
4747Using 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.
4848
4949It'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.
5050
5151To use the external tool, you need to do the following:
5252
5353- Open and build cconvert.lpi project (located at the package directory). You should get "cconvert" executable file.
5454- Open Tools-\>C to Pascal Options-\>Converter, press Select and choose cconvert executable file.
5555- Check *Use external converter* at *Tools-\>C to Pascal Options-\>Converter*
5656
5757### How to use
5858
5959#### Shortkeys
6060
6161- ctrl+b - convert a single C declaration to Pascal
6262- ctrl+shift+b - convert all C declarations to Pascal from the current cursor position to the end of the file.
6363
6464#### General
6565
6666- Open a file with C declarations in Lazarus IDE or start a new file copying declarations there
6767- Place the cursor at the line where C declaration and press Ctrl+B (the shortcut would be modifiable in future).
6868
6969for example:
7070
7171`int c;`\
7272`int b; `
7373
7474if the cursor placed at 'inc c;' line and ctrl+b pressed the result would be:
7575
7676`var`\
7777`  c : Integer;`\
7878`int b;`
7979
8080exactly 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:
8181
8282`var`\
8383`  c : Integer;`\
8484`var `\
8585`  b : Integer;`
8686
8787Parsing 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.
8888
8989- 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
9090
9191i.e. you have 2 declarations in the file:
9292
9393`int fn(int, float);`\
9494`extern int v;`
9595
9696placing the cursor before them and pressing ctrl+shift+b, would generate.
9797
9898`function fn(par0: Integer; par1: Single): Integer; cdecl; external;`\
99-\
99+
100100`var`\
101101`  v : Integer; external;`
102102
103103**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.
104104
105105#### Defines
106106
107107In most cases parameterless macro definitions, like
108108
109109`#define VALUE 1 << 2;`
110110
111111are used like constant values. Chelper translates them as constants trying to convert the define expression.
112112
113113`const`\
114114`  VALUE = 1 shr 2;`
115115
116116In other cases defines are used for some "special" markings or additional information for external tools.
117117
118118`#define LIB_DEPRECATED `\
119119`LIB_DEPRECATED int somefunc(int p);`
120120
121121without 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.
122122
123123Select Tools-\>C to Pascal options-\>Main select the defines file and press Edit.
124124
125125This 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.
126126
127127Chelper handles parameter macros as well.
128128
129129`int somefunc SAFE_PARAMS( (int i))`
130130
131131adding the the following declaration into defines file
132132
133133`#define SAFE_PARAMS(x) x`
134134
135135will allow to parse the declaration correctly
136136
137137`function somefunc(i: Integer): Integer;`
138138
139139#### Configuration File
140140
141141Configuration file represents itself a simple .ini file. Following section are used in the file:
142142
143143- Main - for general declarations, that effects
144144
145145- Types - custom type conversion section. Name=Value, where Name is the c-type name, Value is resulting pascal type
146146
147147example:
148148
149149`[Types]`\
150150`int=integer`\
151151`int*=PInteger`\
152152`float=single`\
153153`float*=PSingle`
154154
155155---
156156*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