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

Carlos E. R. robin.listas at telefonica.net
Sun Feb 25 23:07:08 CET 2018


On 2018-02-25 21:26, Mark Morgan Lloyd via Lazarus wrote:
> On 25/02/18 20:00, Carlos E. R. via Lazarus wrote:


>> Hi,
>> 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:
>> <http://wiki.freepascal.org/C_to_Pascal>
>> I used "OpenC2Pas" but there remains quite a lot to translate.
> 
> etc. Presumably the original looks something like
> https://github.com/unterwulf/egctl/blob/master/egctl.c

Absolutely! :-)

How did you find out that fast?

> I've just been through a comparable exercise writing a utility to
> program a Logitech G600 gamer's mouse, and my suggestion would be to use
> Wireshark etc. to get an understanding of the messages going over the
> network then to transcribe the bits of the program you need into Pascal
> manually.

I don't think I have the skill set for that. I guess that the author of
that code, Vitaly Sinilin, had the Windows SDK for the device (a power
strip controllable and programmable via Ethernet, LAN or WAN) and did a
translation to Linux of the Windows command line tool. The SDK comes
with the CD when purchasing the power strip, but the box I bought on
Amazon had none. Perhaps it can be downloaded for free (I did not look
yet), but anyway, it is for Windows (and probably C).

> Assuming that since you're asking on the Lazarus ML you're putting
> together a GUI to control the device you probably won't want roughly
> half of the original code which is using C-style string operations to
> read a configuration file.

No, I'm not writing a GUI, I'm attempting to write a daemon. :-)

I have a router that hangs randomly, and I can't replace it because it
is ISP supplied with a complex configuration. So the idea is to ping the
router and when it goes silent power cycle it. I have tested the idea, I
can power a socket off from Linux using that utility, and then a
programmed schedule switches it back on on the 00 seconds mark (the
power strip syncs via NTP). The period can be programmed to anything,
but currently it is set to every minute.

So first I have to handle that powering off some seconds before the "00"
mark, then I have to add the ping, wait for router come back alive, log
the event, update the dynamic dns, email me, and go back to watch.

Of course, I could do it all from a bash script, maybe easier. But I
want to have a go at doing it in Pascal first. :-)


The funny thing is, I programmed for a living in C two decades ago, I
was good. It seems I fave forgotten most of it. :-}


I hopped to find people here familiar with C to pas translation. I also
did this type of things long ago... I translated some windows api
headers to pascal back then.

-- 
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/20180225/ccb742e4/attachment.sig>


More information about the Lazarus mailing list