Sign in Join
Wiki copytemporary

Chelper: what changed

Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.

Title: Chelper

OldNewLine
1+### About
2+
3+Chelper 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.
4+
5+The 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.
6+
7+Chelper also supports converting Objective-C declarations into Objective-P.
8+
9+### Author
10+
11+Dmitry 'skalogryz' Boyarintsev
12+
13+### License
14+
15+[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.
16+
17+### Download
18+
19+There's no "downloadable" package yet, you can access the tool from SVN:
20+
21+<https://sourceforge.net/p/lazarus-ccr/svn/HEAD/tree/components/chelper/>
22+
23+`svn checkout `[`https://svn.code.sf.net/p/lazarus-ccr/svn/components/chelper/`](https://svn.code.sf.net/p/lazarus-ccr/svn/components/chelper/)
24+
25+### Change Log
26+
27+- Version 0.8, 8 Aug 2010
28+
29+### Dependencies / System Requirements
30+
31+- Lazarus 0.9.29 or Higher
32+
33+Status: *Beta*
34+
35+### Issues
36+
37+- No complete expression parser to construct the expression tree.
38+
39+If 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.
40+
41+### Installation
42+
43+- Get the package from SVN
44+- Install Chelper.lpk package to the Lazarus.
45+- Go to *Tools-\>C to Pascal Options-\>Converter*, uncheck *Use external converter* if you want to use the package built-in converter.
46+
47+Using 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.
48+
49+It'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.
50+
51+To use the external tool, you need to do the following:
52+
53+- Open and build cconvert.lpi project (located at the package directory). You should get "cconvert" executable file.
54+- Open Tools-\>C to Pascal Options-\>Converter, press Select and choose cconvert executable file.
55+- Check *Use external converter* at *Tools-\>C to Pascal Options-\>Converter*
56+
57+### How to use
58+
59+#### Shortkeys
60+
61+- ctrl+b - convert a single C declaration to Pascal
62+- ctrl+shift+b - convert all C declarations to Pascal from the current cursor position to the end of the file.
63+
64+#### General
65+
66+- Open a file with C declarations in Lazarus IDE or start a new file copying declarations there
67+- Place the cursor at the line where C declaration and press Ctrl+B (the shortcut would be modifiable in future).
68+
69+for example:
70+
71+`int c;`\
72+`int b; `
73+
74+if the cursor placed at 'inc c;' line and ctrl+b pressed the result would be:
75+
76+`var`\
77+`  c : Integer;`\
78+`int b;`
79+
80+exactly 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:
81+
82+`var`\
83+`  c : Integer;`\
84+`var `\
85+`  b : Integer;`
86+
87+Parsing 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.
88+
89+- 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
90+
91+i.e. you have 2 declarations in the file:
92+
93+`int fn(int, float);`\
94+`extern int v;`
95+
96+placing the cursor before them and pressing ctrl+shift+b, would generate.
97+
98+`function fn(par0: Integer; par1: Single): Integer; cdecl; external;`\
99+\
100+`var`\
101+`  v : Integer; external;`
102+
103+**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.
104+
105+#### Defines
106+
107+In most cases parameterless macro definitions, like
108+
109+`#define VALUE 1 << 2;`
110+
111+are used like constant values. Chelper translates them as constants trying to convert the define expression.
112+
113+`const`\
114+`  VALUE = 1 shr 2;`
115+
116+In other cases defines are used for some "special" markings or additional information for external tools.
117+
118+`#define LIB_DEPRECATED `\
119+`LIB_DEPRECATED int somefunc(int p);`
120+
121+without 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.
122+
123+Select Tools-\>C to Pascal options-\>Main select the defines file and press Edit.
124+
125+This 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.
126+
127+Chelper handles parameter macros as well.
128+
129+`int somefunc SAFE_PARAMS( (int i))`
130+
131+adding the the following declaration into defines file
132+
133+`#define SAFE_PARAMS(x) x`
134+
135+will allow to parse the declaration correctly
136+
137+`function somefunc(i: Integer): Integer;`
138+
139+#### Configuration File
140+
141+Configuration file represents itself a simple .ini file. Following section are used in the file:
142+
143+- Main - for general declarations, that effects
144+
145+- Types - custom type conversion section. Name=Value, where Name is the c-type name, Value is resulting pascal type
146+
147+example:
148+
149+`[Types]`\
150+`int=integer`\
151+`int*=PInteger`\
152+`float=single`\
153+`float*=PSingle`
154+
155+---
156+*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