Sign in Join
Wiki copytemporary

Chelper

English · Français

About

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.

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.

Chelper also supports converting Objective-C declarations into Objective-P.

Author

Dmitry 'skalogryz' Boyarintsev

License

modified 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.

Download

There's no "downloadable" package yet, you can access the tool from SVN:

https://sourceforge.net/p/lazarus-ccr/svn/HEAD/tree/components/chelper/

svn checkout https://svn.code.sf.net/p/lazarus-ccr/svn/components/chelper/

Change Log

Dependencies / System Requirements

Status: Beta

Issues

If you find a bug in the converter please report it to bugs.freepascal.org for Lazarus-CCR project. Please attach the C-header text and the explanation what doesn't work as expected.

Installation

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.

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.

To use the external tool, you need to do the following:

How to use

Shortkeys

General

for example:

int c;
int b; 

if the cursor placed at 'inc c;' line and ctrl+b pressed the result would be:

var
  c : Integer;
int b;

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:

var
  c : Integer;
var 
  b : Integer;

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.

i.e. you have 2 declarations in the file:

int fn(int, float);
extern int v;

placing the cursor before them and pressing ctrl+shift+b, would generate.

function fn(par0: Integer; par1: Single): Integer; cdecl; external;\

var
  v : Integer; external;

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.

Defines

In most cases parameterless macro definitions, like

#define VALUE 1 << 2;

are used like constant values. Chelper translates them as constants trying to convert the define expression.

const
  VALUE = 1 shr 2;

In other cases defines are used for some "special" markings or additional information for external tools.

#define LIB_DEPRECATED 
LIB_DEPRECATED int somefunc(int p);

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.

Select Tools->C to Pascal options->Main select the defines file and press Edit.

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.

Chelper handles parameter macros as well.

int somefunc SAFE_PARAMS( (int i))

adding the the following declaration into defines file

#define SAFE_PARAMS(x) x

will allow to parse the declaration correctly

function somefunc(i: Integer): Integer;

Configuration File

Configuration file represents itself a simple .ini file. Following section are used in the file:

example:

[Types]
int=integer
int*=PInteger
float=single
float*=PSingle


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.

Revision 2, last changed by WikiArchive .

Talk about this page

Nobody has opened a bench for this page yet. Sign in to open one.