chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] List -> C strings


From: Robin Lee Powell
Subject: Re: [Chicken-users] List -> C strings
Date: Tue, 10 Jul 2007 16:03:06 -0700
User-agent: Mutt/1.5.13 (2006-08-11)

For the record, because I've found people asking this before, here's
what I did:

#>
char **make_strings(C_word lst)
{
   int len, i;
   C_word tmp;
   char **hlist;

   len = C_unfix(C_i_length(lst));
   hlist = (char**) malloc(sizeof(char*) * (len + 1));

   for(i = 0, tmp = lst; i < len; i++, tmp = C_u_i_cdr(tmp)) {
         char *sstring;
         char *cstring;
         unsigned int slength=C_unfix(C_i_string_length(C_u_i_car(tmp)));


         cstring = (char *)malloc( (slength + 1) * sizeof( char ));
         strncpy( cstring, C_c_string(C_u_i_car(tmp)), slength );
         cstring[slength] = 0;
         hlist[i] = cstring;
   }
   hlist[i] = NULL;

   return hlist;
}
<#

The unfortunate part is that C_i_string_length isn't documented at
all; I'll see if I can find some time to do that.

-Robin

On Mon, Jul 09, 2007 at 09:57:58PM -0500, Zbigniew wrote:
> $ pwd
> ~/build/chicken
> $ grep string-length library.scm
> (define (string-length s) (##core#inline "C_i_string_length" s))
> $ grep C_i_string_length runtime.c
> C_regparm C_word C_fcall C_i_string_length(C_word s)
> 
> Hope that helps.
> Zb
> 
> On 7/9/07, Robin Lee Powell <address@hidden> wrote:
> >Except: Problem: no way to get the length of the Scheme string!
> 
> 
> _______________________________________________
> Chicken-users mailing list
> address@hidden
> http://lists.nongnu.org/mailman/listinfo/chicken-users

-- 
http://www.digitalkingdom.org/~rlpowell/ *** http://www.lojban.org/
Reason #237 To Learn Lojban: "Homonyms: Their Grate!"
Proud Supporter of the Singularity Institute - http://singinst.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]