On 2/21/07, Dharshana Eswaran <[EMAIL PROTECTED]> wrote:
On 2/20/07, Peter Scott <[EMAIL PROTECTED]> wrote:
>
> On Tue, 20 Feb 2007 12:19:22 +0530, Dharshana Eswaran wrote:
>
> > Hello All,
> >
> > I need to use a C header file in Perl program in Unix.
> >
> > Is it possible to use the header files from perl in any way? I do not
> want
> > to use any modules for the same.
> >
> > I do not want to enable the perl program to call a routine in C library
> > through XS. I just want to use the values rather than any code.
>
> If you were talking about just #define, I'd say
>
> http://search.cpan.org/~gbarr/Include-1.02a/Include.pm
>
> But:
>
> > For example, Consider "headerfile.h":
> >
> > struct sample {
> >     int x;
> > };
> >
> > Then in my C program I might do the following:
> >     printf("The size of a headerfile is %d\n",sizeof(headerfile));
> > Can i do the same in Perl?
>
> I am having a hard time picturing what you might use this for in Perl.
> You might look at h2ph, which comes with perl.  I also suggest reading
> http://xrl.us/uzcs (Link to www.amazon.com).


Thank you. I shall check the link and have a knowledge on it.

Actually, i just came up with an idea of merging the C header files in Perl.
And searched in net, since i could not get a proper solution, i mailed to
the list. It was just my idea and not for implementation. Wanted to learn
more on that.

Anyways, thanks once again.


Regards,
Dharshana


You really need to decide what you mean by "use" when it comes to the
header files. Do you want to import constants that are declared? Do
you want to have declared functions available? Structs? Do you just
want the actual C, or do you want the preprocessor directives, too? do
you need to execute preprocessor logic (e.g. ifdef, etc.)?

You can certainly do all of this in Perl, in a couple of differnt
ways. If you have access to a C compiler, you use various modules in
the Inline family (Inline::C, Inline::Structs, etc.) to compile the C
code in a way that lets Perl access it directly. If you just need the
#define statements, you can use Include, as Peter pointed out. If you
need something else, you can translate it using Parse::RecDescent or
something similar. The Parse::RecDescent grammar used by
Inline::Structs would be a goo place to start if you go the RecDescent
route.

HTH,

-- jay
--------------------------------------------------
This email and attachment(s): [  ] blogable; [ x ] ask first; [  ]
private and confidential

daggerquill [at] gmail [dot] com
http://www.tuaw.com  http://www.downloadsquad.com  http://www.engatiki.org

values of β will give rise to dom!

Reply via email to