[plug] Reading a horrible C file in PHP.

Shayne O'Neill shayneo at bestflights.com.au
Tue Aug 8 14:09:52 WST 2006


Aye. Problem is, I don't have the luxury to change the damn C cgi's, and
ultimately all I really do have the luxury of is running some php

Things took a twist for the more interesting today when I built a swig
wrapper for the c cgi (its shockingly easy, you just copy the apropriate
.h bits into the .i file, swig -python blah.i gcc <all your stuff and
the wrapper> ld <all the resulting stuff> and load it in python, and as
it pans out the c source I have doesn't actually work with the .dat
files. Doh. 

I still can not fathom why anyone would use C to write a web app
anymore. Segfault hell!
 

-----Original Message-----
From: plug-bounces at plug.org.au [mailto:plug-bounces at plug.org.au] On
Behalf Of Lance Duivenbode
Sent: Tuesday, 8 August 2006 9:48 AM
To: plug at plug.org.au
Subject: Re: [plug] Reading a horrible C file in PHP.

Alternatively you could just write a custom PHP extension. I have done
this in the past and while it's not simple, I wouldn't say it's overly
difficult if you've got some C experience. The only problem would be
trying to convince the hosting company to let you use it.

In terms of simplicity, I'm with Kirk on this one. Converting to some
other format (CSV,XML, etc) is probably the most time efficient and
effective way to do things.

Lance

On Mon, 7 Aug 2006 06:05 pm, Shayne O'Neill wrote:
> I have infact been eyeing off writing a swig wrapper for the function 
> (I've done a fair bit with python and swig), but honestly its goofy as

> hell, and I wonder whether it'd be kosher with the hosting company.
>
> Hmm. Must think thru.
>
> -----Original Message-----
> From: plug-bounces at plug.org.au [mailto:plug-bounces at plug.org.au] On 
> Behalf Of Kirk Turner
> Sent: Monday, 7 August 2006 4:49 PM
> To: plug at plug.org.au
> Subject: Re: [plug] Reading a horrible C file in PHP.
>
> On 8/7/06, Shayne O'Neill <shayneo at bestflights.com.au> wrote:
> > Ok. I've been tasked to convert this horrible C cgi to php.
> >
> >
> > The stupid thing reads in a data file like this;-
>
> ...
>
> > Nasty huh?
>
> Its not exactly a nasty way - as more an efficient way - unless as you

> have to read it in another language that doesn't support structs. Its 
> essentially just writing out memory for the struct directly in a form 
> of binary serialisation (you'll see this in many a C data function).
>
> However that said it should be fairly straight forward in the way it 
> is handled looking at it (and a hexdump -C should reveal some of this
too).
> It should look something like this:
>
> flightid - an int coming from 32 bytes (byte order and size will 
> depend on the platform) name - the next 256 bytes, you'll need to 
> search for the 0x00 byte (NULL, or \0 character) and termiate the 
> string there - how to convert it into a php string you'll have to work

> out, php is not my strong point.
> price - next 128 bytes
> description - next 65535 bytes
> 50x depature struct following the same process
>
> and then repeat ad nauseum for each part.
>
> You might find it easier to convert the data in C itself into a format

> that is a bit more compatible with PHP (XML for example) or if you 
> need to have compatability between C and PHP write an extension in php

> to load it (there might already be one that converts structs to php 
> classes for example?)
>
> Kirk
> _______________________________________________
> PLUG discussion list: plug at plug.org.au 
> http://www.plug.org.au/mailman/listinfo/plug
> Committee e-mail: committee at plug.linux.org.au 
> _______________________________________________
> PLUG discussion list: plug at plug.org.au 
> http://www.plug.org.au/mailman/listinfo/plug
> Committee e-mail: committee at plug.linux.org.au
_______________________________________________
PLUG discussion list: plug at plug.org.au
http://www.plug.org.au/mailman/listinfo/plug
Committee e-mail: committee at plug.linux.org.au



More information about the plug mailing list