[Lazarus] Translating a small C program to pascal (on lazarus)

Carlos E. R. robin.listas at telefonica.net
Mon Feb 26 03:51:29 CET 2018


On 2018-02-26 01:11, Giuliano Colla via Lazarus wrote:
> Il 25/02/2018 20:52, Carlos E. R. via Lazarus ha scritto:
> 
>> I want to translate a little Linux C program (600 lines) to pascal (so
>> that I can then add my parts in comfort). I failed to find a good
>> automated tool in Linux. I had a look here: 
> 
> Did you consider h2pas (which comes with fpc/Lazarus)?
> It's only intended to translate C headers to Pascal, but it makes a good
> job on this.
> 
> You can only use it to translate declarations, but once declarations are
> in Pascal, converting the code becomes much easier.

Ah!  I didn't realize it could translate the declarations on a .c file,
I thought it was only for .h files.

I just had a quick test, but... I'll have to read on it, the quick test
crashes:

cer at Telcontar:~/bin/lazarus/mios/egctl> h2pas egctl.c
at line 49 error : syntax error
at line 82 error : syntax error
An unhandled exception occurred at $00000000004089F2:
EAccessViolation: Access violation
  $00000000004089F2

cer at Telcontar:~/bin/lazarus/mios/egctl>

It did some translation, though:

-rw-r--r-- 1 cer users       0 Feb 26 03:36 ext2.tmp
-rw-r--r-- 1 cer users       0 Feb 26 03:36 ext.tmp
-rw-r--r-- 1 cer users    1579 Feb 26 03:36 ext3.tmp


The last file contains a translation till it crashed:


{$include <arpa/inet.h>}
...
  const
    TASK_LEN = 4;
    STATCRYP_LEN = 4;
    CTRLCRYP_LEN = 4;
    KEY_LEN = 8;
...
    SOCKET_COUNT = 4;
(* error
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
in define line 49 *)


    type
      Protocol = (EG_PROTO_V20,EG_PROTO_V21,EG_PROTO_WLAN
        );

      Action = (ACTION_ON,ACTION_OFF,ACTION_TOGGLE,ACTION_LEFT,
        ACTION_INVALID);

      Actions = record
          socket : array[0..(SOCKET_COUNT)-1] of Action;
        end;

      Key = record
          octets : array[0..(KEY_LEN)-1] of uint8_t;
        end;
    { since the protocol is little-endian, low word comes first  }


and here it crashes.

-- 
Cheers / Saludos,

		Carlos E. R.
		(from 42.2 x86_64 "Malachite" at Telcontar)

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: OpenPGP digital signature
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20180226/ecf6c09c/attachment.sig>


More information about the Lazarus mailing list