Difference between revisions of "Chelper/fr"

From Lazarus wiki
Jump to navigationJump to search
(Created page with "{{Chelper}} === A propos === Chelper est un outil d'extension de Lazarus, qui aide à convertir les fichiers d'entête C en Pascal. Oui c'est un autre outil de conversion C v...")
 
Line 45: Line 45:
 
Pour utiliser l'outil externe, vous devez faire ce qui suit:
 
Pour utiliser l'outil externe, vous devez faire ce qui suit:
 
* Ouvrir et construire le projet cconvert.lpi (placé dans le répertoire du paquet). Vous devriez obtenir le fichier exécutable "cconvert".
 
* Ouvrir et construire le projet cconvert.lpi (placé dans le répertoire du paquet). Vous devriez obtenir le fichier exécutable "cconvert".
*  
+
* Ouvrir Outils->C to Pascal Options->Converter, pressez sur Select et choisissez le fichier exécutable cconvert.
 
+
* Contrôlez ''Use external converter'' depuis ''Tools->C to Pascal Options->Converter''.
Open Tools->C to Pascal Options->Converter, press Select and choose cconvert executable file.
 
* Check ''Use external converter'' at ''Tools->C to Pascal Options->Converter''
 
  
 
=== Comment l'utiliser  ===
 
=== Comment l'utiliser  ===

Revision as of 10:32, 30 April 2022

English (en) français (fr)

A propos

Chelper est un outil d'extension de Lazarus, qui aide à convertir les fichiers d'entête C en Pascal. Oui c'est un autre outil de conversion C vers Pascal comme beaucoup qui lui sont similaires (H2Pas, ToPas), mais on pourrait le trouver plus utile.

L'extension n'essaie pas de convertir un en-tête pour l'utilisateur, c'est plutôt un outil d'aide à la traduction manuelle, faisant presque tout le "sale boulot" pour l'utilisateur.

Chelper supporte aussi la conversion des déclarations Objective-C vers Objective-P.

Auteur

Dmitry 'skalogryz' Boyarintsev

Licence

modified LGPL (comme pour les FPC RTL et Lazarus LCL). Vous pouvez contacter l'auteur si la LGPL ne convient pas à la licence de votre projet.

Téléchargement

Il n'y a pas encore de paquet téléchargeable", vous pouvez accéder à louil depuis 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/

Journal des modifications

  • Version 0.8, 8 août 2010

Dependencies / System Requirements

  • Lazarus 0.9.29 ou supérieur

Etat: Beta

Problèmes

Aucun analyseur d'expression complet pour construire l'arborescence d'expression.

i vous trouvez un bug dans la convertisseur, veuillez le rapporter dans bugs.freepascal.org pour le projet Lazarus-CCR. Merci d'attacher le fichier d'entête C et les explications sur ce qui ne fonctionne pas comme voulu.

Installation

  • Obtenez le paquet depuis SVN.
  • Installez le paquet Chelper.lpk depuis Lazarus.
  • Allez vers Outils->C to Pascal Options->Converter, décochez Use external converter si vous voulez utiliser le paquet de convertisseur intégré.

L'utilisation du convertisseur intégré présente un avantage en termes de performances. Cependant, si vous devez mettre à jour le convertisseur, vous devrez reconstruire l'intégralité de l'IDE. Il est également possible que le convertisseur provoque des plantages ou des blocages. Vous devriez le signaler, mais vous risquez de perdre toutes vos données.

Il est beaucoup plus sûr d'utiliser l'outil externe cconvert. Il est également plus facile de mettre à jour le convertisseur si de nouvelles fonctionnalités sont ajoutées ou si des bogues sont corrigés. Tout ce dont vous avez besoin est de reconstruire l'exécutable cconverter beaucoup plus rapidement que de reconstruire Lazarus.

Pour utiliser l'outil externe, vous devez faire ce qui suit:

  • Ouvrir et construire le projet cconvert.lpi (placé dans le répertoire du paquet). Vous devriez obtenir le fichier exécutable "cconvert".
  • Ouvrir Outils->C to Pascal Options->Converter, pressez sur Select et choisissez le fichier exécutable cconvert.
  • Contrôlez Use external converter depuis Tools->C to Pascal Options->Converter.

Comment l'utiliser

Shortkeys

  • ctrl+b - convert a single C declaration to Pascal
  • ctrl+shift+b - convert all C declarations to Pascal from the current cursor position to the end of the file.

General

  • Open a file with C declarations in Lazarus IDE or start a new file copying declarations there
  • Place the cursor at the line where C declaration and press Ctrl+B (the shortcut would be modifiable in future).

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.

  • 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

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;

Fichier de configuration

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

  • Main - for general declarations, that effects
  • Types - custom type conversion section. Name=Value, where Name is the c-type name, Value is resulting pascal type

example:

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