Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Accessing variables in langinfo.h through CFFI

7 views
Skip to first unread message

Teemu Likonen

unread,
Oct 16, 2010, 7:02:52 AM10/16/10
to
I have this function to get locale information from the system:

(cffi:defcfun "nl_langinfo" :string
(item :int))

For example:

(nl-langinfo 14) ; 14 = CODESET
=> "UTF-8"

The parameter for POSIX nl_langinfo() function is called "item" and it's
an integer. C programmer's use constants defined in langinfo.h. Is it
possible to access those constants through Common Lisp CFFI interface?
How? I can check those constants with a simple C program but it would be
nicer to refer directly to langinfo.h constants in Lisp program.

Pascal J. Bourguignon

unread,
Oct 16, 2010, 1:46:38 PM10/16/10
to
Teemu Likonen <tlik...@iki.fi> writes:

I don't really know, but I guess the groveller may be able to collect
these constant definitions and generate them in lisp.

http://common-lisp.net/project/cffi/manual/html_node/The-Groveller.html

--
__Pascal Bourguignon__ http://www.informatimago.com/

Teemu Likonen

unread,
Oct 16, 2010, 3:21:47 PM10/16/10
to
* 2010-10-16 19:46 (+0200), Pascal J. Bourguignon wrote:

> I don't really know, but I guess the groveller may be able to collect
> these constant definitions and generate them in lisp.
>
> http://common-lisp.net/project/cffi/manual/html_node/The-Groveller.html

You guessed right. In short, one has to create a grovel definition file
like this:

;;;; langinfo.lisp

(include "langinfo.h")
(constant (+codeset+ "CODESET"))
(constant (+month-10+ "MON_10"))

Then

(cffi-grovel:process-grovel-file (merge-pathnames "langinfo.lisp"))

will create file "langinfo.grovel-tmp.lisp" with the following content:

;;;; This file has been automatically generated by cffi-grovel.
;;;; Do not edit it by hand.

(cl:defconstant +codeset+ 14)
(cl:defconstant +month-10+ 131107)

CFFI-GROVEL has some kind of ASDF system integration but I don't know
yet how it works.

0 new messages