[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: SCM to C string
From: |
Christopher Cramer |
Subject: |
Re: SCM to C string |
Date: |
Thu, 20 Jun 2002 17:04:54 -0500 |
User-agent: |
Mutt/1.2.5i |
On Thu, Jun 20, 2002 at 04:39:21PM -0400, Viktor Pavlenko wrote:
> My program parses a scheme config file. If configuration is not valid
> from the application point of view (but is a valid scheme expression)
> I signal error. What I would like to do is to dump the offending SCM
> object to C-style string so that I can display it as debugging
> information.
>
> For instance I'd like convert SCM object which contains '("a" 1) into
> C string "(\"a\" 1)".
char *objtostr(SCM object)
{
char *str;
size_t len;
SCM s_str = scm_object_to_string(object, SCM_UNDEFINED);
len = SCM_STRING_LENGTH(s_str);
str = malloc(len + 1);
if (!str) abort();
memcpy(str, SCM_STRING_CHARS(s_str), len);
str[len] = '\0';
return str;
}
I haven't tested this, so maybe there are typos or something, but it
should give you the general idea.
--
Christopher Cramer <address@hidden> <http://www.pyro.net/~crayc/>
On résiste à l'invasion des armées; on ne résiste pas à l'invasion
des idées. -- Victor Hugo