Hi Gary,
On 6 June 2016 at 20:14, Gary Pajer <
gary....@gmail.com> wrote:
> char **tmplist;
> FLIList(FLIDOMAIN_USB | FLIDEVICE_CAMERA, &tmplist);
In CFFI, you write:
tmplist_p = ffi.new("char ***")
FLIList(..., tmplist_p)
tmplist = tmplist_p[0]
> printf("\nDevice List:\n %s\n", *tmplist);
print "Device List:"
print ffi.string(tmplist[0])
> for (int i=0; tmplist[i] != NULL; i++)
> {
> for (int j = 0; tmplist[i][j] != '\0'; j++)
> if (tmplist[i][j] == ';')
> {
> tmplist[i][j] = '\0';
> break;
> }
> }
This part can have a one-to-one mapping to "while" loops, or else you
can use some more pythonic string manipulations instead of the inner
loop.
i = 0
while tmplist[i] != ffi.NULL:
s = ffi.string(tmplist[i])
if ';' in s:
s = s[:s.index(';')]
...
i += 1
Note also that if you have some example of C code that is hard to
follow, like this, you can also paste it verbatim in ffi.set_source(),
and put it inside another function which does only what you want
instead and has got a simpler C interface:
void print_stuff_to_stdout(void)
{
// all the code above is here
}
then you only have to mention ffi.cdef("void
print_stuff_to_stdout(void);") and call lib.print_stuff_to_stdout().
Of course you may want to grab some string instead of printing it to
stdout, then it becomes for example "char *fetch_stuff(void)" if there
is no concern about freeing the memory, or else more traditionally:
int fetch_stuff(char *out_buf, size_t bufsize)
{
// fetch...
strncpy(out_buf, tmplist[i], bufsize); // copies to out_buf
return 0; // 'success' indicator
}
A bientôt,
Armin.