This is the mail archive of the guile@cygnus.com mailing list for the guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

readline and guile


Hi!

First of all, I would like to share my excitement with guile. being old
scheme fan, I am very glad to be able to have nice scheme-based scripting
language in my apps. I've already used guile for one project and it was
very easy.

Now I am facing bigger challenge :-) I am trying to write app which should
be able to do simultaneously 2 things:

1. Accept command line user input using readline. it should not be in
scheme syntax. I mean, I want "QUIT" not "(QUIT)" command.

2. Listen to am TCP socket connection and read and process data as it
becomes available.

All data gathered from socket and command line will be first analyzed by C
code and them eventually might call one or move guile functions.

Looks like in my case control should be in C code, which will read user
and socket input as invoke functions of the guile interpreter as needed. I
was thinking about writing simple loop with call to readline() in it to
read keyboard input. For socket, I was thinking about setting
'rl_event_handler' function pointer to my function which will do select()
with 0 timeout on my socket. This function will be called internally from
readline() while user typing, or while waiting for used to start typing.

So, I've wrote something like:

int main(int argc, char **argv)
{
	 gh_enter(argc, argv, main_prog);
}

void main_prog()
{
    while(1)
    {
        char *res = readline("Prompt:");
        if(res)
            fprintf(stderr,"Ok, %s\n",res);
    }
}

it compiles, starts, gives prompt and immediately core dumps (somewhere
inside libreadline) before I even have a chance to press a key.

I suspect this core dump is related to fact that guile itself is using
readline library, and it somehow initialize it the way it become not
usable from my code (sets some kind of hooks perhaps).

What can I do? If there is any way to avoid this problem? Any advise is
appreciated.

Sincerely,
Vadim

P.S. I am using guile-1.3 under RedHat Linux 5.2

;;----------------------------------+-----------------------------------+
;; Vadim Zaliva                     + Those who do not understand Unix  +
;; mailto:lord@crocodile.org        + are condemned to reinvent it,     +
;; http://www.crocodile.org         + poorly.          (H. Spencer)     +
;;----------------------------------+-----------------------------------+