chicken-users
[Top][All Lists]
Advanced

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

Re: [Chicken-users] lolevel help: array of c-pointers from string-list?


From: John Cowan
Subject: Re: [Chicken-users] lolevel help: array of c-pointers from string-list?
Date: Tue, 26 Sep 2006 17:40:46 -0400
User-agent: Mutt/1.3.28i

Graham Fawcett scripsit:

> Regardless, I'm stuck, and could use help. :-) Advice, anyone?

You need to create a little bit of C glue.  I had the same situation
for invoking some C functions that want their own argc and argv; this
is what I did.  I used a static rather than a dynamic array to hold the
strings, for the sake of simplicity, but it wouldn't be hard to realloc()
the array instead if you know its size in advance.

===== cut here =====
#>
int argc = 0;           /* Argument count */
# define MAXARGC 125    /* Maximum arg count for Chicken functions */
char *argv[MAXARGC];    /* Argument vector */
<#

;; Initialize the argv array, freeing any strings still retained.
(define argv-init! (foreign-lambda* void () "
        int n;
        for (n = 0; n < argc; n++) {
                free(argv[n]);
                argv[n] = NULL;
                }
        argc = 0;
"))

;; Load the nth argument into the argv array.
(define argv-set! (foreign-lambda* void ((int n) (c-string s)) "
        if (n >= 0 && n < MAXARGC) {
                argv[n++] = s;
                if (argc < n) argc = n;
                }
"))
===== cut here =====

-- 
There is / One art                      John Cowan <address@hidden>
No more / No less                       http://www.ccil.org/~cowan
To do / All things
With art- / Lessness                     -- Piet Hein




reply via email to

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