This is the mail archive of the
guile@sourceware.cygnus.com
mailing list for the Guile project.
scm_ftell sometimes needs scm_fill_input?
- To: guile at sourceware dot cygnus dot com
- Subject: scm_ftell sometimes needs scm_fill_input?
- From: Jan Nieuwenhuizen <janneke at gnu dot org>
- Date: Tue, 26 Oct 1999 11:36:03 +0200
- cc: "ir. Wendy" <hanwen at cs dot uu dot nl>
Hi,
Last week we've hooked up the GUILE parser to LilyPond, which enables
us to use pure GUILE constructs in Lily's input language.
The problem:
> Now my question: how do I set up a string port that does this, and how
> do I read back the number of characters taken from the port?
Gary Houston provided us with the useful tip to write a modified version
of scm_eval_string, which was simple enough. However, it turned out that
for certain scheme constructs read by scm_read, scm_ftell failed to return
the correct number of characters read. After digging into the GUILE
sources, I found scm_fill_input, which seems to reset read/saved-read
buffers. Is this a buglet, or am I doing something wrong? See below.
Greetings,
Jan.
SCM
ly_parse_scm (char const* s, int* n)
{
SCM str = gh_str02scm ((char*)s);
SCM port = scm_mkstrport (SCM_INUM0, str, SCM_OPN | SCM_RDNG,
"scm_eval_0str");
SCM from = scm_ftell (port);
SCM form;
SCM answer = SCM_UNSPECIFIED;
/* Read expression from port */
if (!SCM_EOF_OBJECT_P (form = scm_read (port)))
answer = scm_eval_x (form);
/*
After parsing
(begin (foo 1 2))
all seems fine, but after parsing
(foo 1 2)
read_buf has been advanced to read_pos - 1,
so that scm_ftell returns 1, instead of #parsed chars
*/
/*
urg: reset read_buf for scm_ftell
shouldn't scm_read () do this for us?
*/
scm_fill_input (port);
SCM to = scm_ftell (port);
*n = gh_scm2int (to) - gh_scm2int (from);
/* Don't close the port here; if we re-enter this function via a
continuation, then the next time we enter it, we'll get an error.
It's a string port anyway, so there's no advantage to closing it
early.
scm_close_port (port);
*/
return answer;
}
--
Jan Nieuwenhuizen <janneke@gnu.org> | GNU LilyPond - The music typesetter
http://www.xs4all.nl/~jantien/ | http://www.lilypond.org/