Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Bigloo && C-interface

25 views
Skip to first unread message

Oliver Bandel

unread,
Jan 8, 2002, 2:47:45 PM1/8/02
to

Hello,

is there anybody out there, using bigloo with
C-interface?

I try to start with such applications, but have no
starting point. In the documentation is a program
cigloo mentioned, but it is not in the bigloo
distribution. So examples are missing.

Any small examples out there?

I try to use the stat(2) function to get the
filestatus. It needs a filename and gives back
informations of the struct stat.

So I want to write a scheme-procedure with one arg
(the filename), which calls a C-routine and gets
the results of the C-function, giving it back to the
scheme-language-level.


Any hints or small examples would help a lot.


Ciao,
Oliver

P.S.: It would be nice to habe a scheme-interface to
a lot of functions of the system. Is this planned
to implement such a system-near library?
(If I have some experience with the C-Interface
of bigloo, I can provide code for it...)

( Hello Michael, are you reading this? )

Manuel Serrano

unread,
Jan 9, 2002, 4:17:32 AM1/9/02
to
> Hello,
>
> is there anybody out there, using bigloo with
> C-interface?
>
> I try to start with such applications, but have no
> starting point. In the documentation is a program
> cigloo mentioned, but it is not in the bigloo
> distribution. So examples are missing.
>
> Any small examples out there?
>
> I try to use the stat(2) function to get the
> filestatus. It needs a filename and gives back
> informations of the struct stat.
>
> So I want to write a scheme-procedure with one arg
> (the filename), which calls a C-routine and gets
> the results of the C-function, giving it back to the
> scheme-language-level.
>
>
> Any hints or small examples would help a lot.
>
>
> Ciao,
> Oliver
The Bigloo distribution does contain Cigloo, a tool for extracting C
headers and C prototypes. In order to compile and install Cigloo, please
refer to the Bigloo INSTALL file.

The Bigloo distribution contains several examples of connection to C.
For instance, in bigloo2.4b/examples/Runtime there is an example of Scheme
code using C rusage facility. There is also in the bigloo2.4b/xlib
an example of Scheme code calling X functions.

In addition in the Bigloo home page (that is now located at
http://www-sop.inria.fr/mimosa/fp/Bigloo/), you will find other examples
of programs using Scheme and C (see the Features section).

--Manuel Serrano--

David Rush

unread,
Jan 9, 2002, 6:35:37 AM1/9/02
to
Oliver Bandel <oli...@first.in-berlin.de> writes:
> is there anybody out there, using bigloo with
> C-interface?

I have done. It's actually pretty smooth.

> In the documentation is a program
> cigloo mentioned, but it is not in the bigloo
> distribution. So examples are missing.

Cigloo is in the source dist, but I don't much like it (although my
experiences with it are based on the Bigloo 2.1 release). I have found
that you get clearer, briefer, and more accurate specs when you
build them by hand. You have to spend a lot of effort tweaking
Cigloo params if you want it to get it right. This isn't Cigloo's
fault really, the C run-time library is terribly inbred. I find it
easier just to define the bits I need.

> Any small examples out there?

<http://people.netscape.com/drush/scheme/xed.bgl> is a command-line
binary file editor in the spirit of dd (but more user-friendly ;) You
might find it a good short example of using the Bigloo C interface to
C file I/O.

david rush
--
Research is what I am doing when I don't know what I am doing."
-- Wernher von Braun

Oliver Bandel

unread,
Jan 9, 2002, 7:58:55 AM1/9/02
to

Hi!

Manuel Serrano <Manuel....@sophia.inria.fr> wrote:
>> Hello,
>>
>> is there anybody out there, using bigloo with
>> C-interface?
>>
>> I try to start with such applications, but have no
>> starting point. In the documentation is a program
>> cigloo mentioned, but it is not in the bigloo
>> distribution. So examples are missing.
>>
>> Any small examples out there?
>>
>> I try to use the stat(2) function to get the
>> filestatus. It needs a filename and gives back
>> informations of the struct stat.
>>
>> So I want to write a scheme-procedure with one arg
>> (the filename), which calls a C-routine and gets
>> the results of the C-function, giving it back to the
>> scheme-language-level.
>>
>>
>> Any hints or small examples would help a lot.
>>
>>
>> Ciao,
>> Oliver
> The Bigloo distribution does contain Cigloo, a tool for extracting C
> headers and C prototypes. In order to compile and install Cigloo, please
> refer to the Bigloo INSTALL file.

OOPS, sorry, I did not know that Cigloo is part of the
BEE-environment. I thought it's part of the main distribution
and that's the reason why I searched for the cigloo-executable
in the directory, where the bigloo-executable is.
But I had not compiled/installed BEE before, so I searched
in the wrong places.


> The Bigloo distribution contains several examples of connection to C.
> For instance, in bigloo2.4b/examples/Runtime there is an example of Scheme
> code using C rusage facility.

Yes, there is a file runtime.scm and I will look at it.

I also found in bigloo2.4b/cigloo/examples/ some stuff.

> There is also in the bigloo2.4b/xlib
> an example of Scheme code calling X functions.

Oh, that's interesting! :)
I will have a look at it!
Maybe that can replace other languages... maybe it's
an idea to mariage scheme/bigloo) and Tk?


> In addition in the Bigloo home page (that is now located at
> http://www-sop.inria.fr/mimosa/fp/Bigloo/), you will find other examples
> of programs using Scheme and C (see the Features section).

OK, thank you for that informations and sorry for that
trouble.


Ciao,
Oliver

Oliver Bandel

unread,
Jan 9, 2002, 12:52:01 PM1/9/02
to

Ok, I have installed bigloo now, but have
extremely much problems with the *.h-files.

I will better write that stuff by hand and
do not use cigloo. I have a suse-distribution
and it's known for messy header-file-handling.

I think Suse's messiness is stronger than
cigloo's cleverness. :(

Ciao,
Oliver

P.S.: I will use the other ressources (docs/examples)
you have mentioned. I think (hope) there will be a way
of getting work done.

Oliver Bandel

unread,
Jan 10, 2002, 9:22:59 AM1/10/02
to

David Rush <ku...@bellsouth.net> wrote:
[...]

> <http://people.netscape.com/drush/scheme/xed.bgl> is a command-line
> binary file editor in the spirit of dd (but more user-friendly ;) You
> might find it a good short example of using the Bigloo C interface to
> C file I/O.

Thanks.
It's bigger than I thought.

If it is not too much effort, I would be happy
to have a little hint, how to start with my
problem...


I have a little C-Code here and now
the question is: How to marriage it with bigloo.


The source is only a little part of the planned thing.
I give back an int, but I think about giving back
a list of pairs, so that I can use assq to get the
needed mamber of the stat-structure...

If I see it correctly, I have to compile the C-code
to an object-file, create a *.sch-file and then compile
the scheme-code (*.scm) (which can use the last_modified()-C-function).
After creating the object-files I can link them together
bith bigloo and use the executable.

Is that right? Is that all?


My next questions are:

- How looks the *.sch-file for that function?

- How looks the *.scm-file for that function?
There must be some code, which is necessary to use the
C-function.

- What changes are necessary in the *.sch / *.scm-code
to give back a list of pairs?

- How do I give back a list of pairs from the C-code?


It would be very good to have such minimal starting-point
for that minimal C-source. I then can use that example-code,
look again into the bigloo-documentation and can go further
step-by-step then, increasing complexity of my code ( and
maybe can provide some code for the public later, maybe a
unix-api-library for bigloo or such... :) ).

############################################################
#include <time.h>
#include <sys/stat.h>
#include <unistd.h>
#include <sys/types.h>


int last_modified( char* filename )
{
struct stat filestatus; /* buffer for stat-infos */
int ret; /* return-value of int-functions */
time_t last_modified; /* last-modified-value of file */
time_t now; /* the unix-time now */
time_t age; /* age of the file in seconds */


/* check the filename-ptr */
/* ---------------------- */
if( filename == NULL )
return 0; /* error-case! */

/* set the values of the filestatus-buffer, if possible, */
/* or go back with obviously-wrong value (error-case) */
/* ----------------------------------------------------- */
ret = stat(filename, &filestatus);
if( ret )
return 0; /* error-case! */

now = time(NULL); /* for future deveopments */
last_modified = filestatus.st_mtime;
age = now - last_modified; /* for future deveopments */


return last_modified;
}
############################################################


TIA,
Oliver

Manuel Serrano

unread,
Jan 11, 2002, 3:15:47 AM1/11/02
to
> My next questions are:
>
> - How looks the *.sch-file for that function?
>
> - How looks the *.scm-file for that function?
> There must be some code, which is necessary to use the
> C-function.
>
> - What changes are necessary in the *.sch / *.scm-code
> to give back a list of pairs?
>
> - How do I give back a list of pairs from the C-code?
>
>
> It would be very good to have such minimal starting-point
> for that minimal C-source. I then can use that example-code,
> look again into the bigloo-documentation and can go further
> step-by-step then, increasing complexity of my code ( and
> maybe can provide some code for the public later, maybe a
> unix-api-library for bigloo or such... :) ).

Let see this on an example using your C file. That is let's suppose the
following C file:

-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----


#include <time.h>
#include <sys/stat.h>
#include <unistd.h>
#include <sys/types.h>


int last_modified( char* filename )
{
struct stat filestatus; /* buffer for stat-infos */
int ret; /* return-value of int-functions */
time_t last_modified; /* last-modified-value of file */
time_t now; /* the unix-time now */
time_t age; /* age of the file in seconds */


/* check the filename-ptr */
/* ---------------------- */
if( filename == NULL )
return 0; /* error-case! */

/* set the values of the filestatus-buffer, if possible, */
/* or go back with obviously-wrong value (error-case) */
/* ----------------------------------------------------- */
ret = stat(filename, &filestatus);
if( ret )
return 0; /* error-case! */

now = time(NULL); /* for future deveopments */
last_modified = filestatus.st_mtime;
age = now - last_modified; /* for future deveopments */


return last_modified;
}
-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----

Now let's see an example of Bigloo source file using the C function
last_modified:

-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----
(module bigloo-c-test
(main main)
(extern (last-modified::int (::string) "last_modified")))

(define (main argv)
(let ((fname (if (pair? (cdr argv)) (cadr argv) "/etc/passwd")))
(print (last-modified fname))))
-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----

Then, we have to compile and link the two files as follow:

-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----
> gcc -c foo.c
> bigloo -c btest.scm
> bigloo btest.o foo.o -o btest
> ./btest
-68590411
> ./btest foo.c
-63005387
-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----

Now let's have a look at a second example where the C source code build a
Bigloo data list:

-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----


#include <time.h>
#include <sys/stat.h>
#include <unistd.h>
#include <sys/types.h>

#include "bigloo.h"

obj_t last_modified( char* filename )


{
struct stat filestatus; /* buffer for stat-infos */
int ret; /* return-value of int-functions */
time_t last_modified; /* last-modified-value of file */
time_t now; /* the unix-time now */
time_t age; /* age of the file in seconds */


/* check the filename-ptr */
/* ---------------------- */
if( filename == NULL )
return 0; /* error-case! */

/* set the values of the filestatus-buffer, if possible, */
/* or go back with obviously-wrong value (error-case) */
/* ----------------------------------------------------- */
ret = stat(filename, &filestatus);
if( ret )
return 0; /* error-case! */

now = time(NULL); /* for future deveopments */
last_modified = filestatus.st_mtime;
age = now - last_modified; /* for future deveopments */


return MAKE_PAIR( string_to_bstring( filename ), BINT( last_modified ) );
}
-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----

Then, the Bigloo source file is turned to:

-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----
(module bigloo-c-test
(main main)
(extern (last-modified::pair (::string) "last_modified")))

(define (main argv)
(let ((fname (if (pair? (cdr argv)) (cadr argv) "/etc/passwd")))
(print (last-modified fname))))
-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----|-----

The compilation remains the same.

--Manuel Serrano--

0 new messages