开发者

How can I find the value of LC_XXX locale integr constants so that I can use them with cffi

开发者 https://www.devze.com 2023-03-11 06:40 出处:网络
I have this code开发者_JS百科: (define-foreign-library libc (:unix \"libc.so.6\")) (use-foreign-library libc)

I have this code开发者_JS百科:

(define-foreign-library libc
  (:unix "libc.so.6"))
(use-foreign-library libc)
(defcfun "setlocale" :pointer (category :int) (locale :pointer)) 

and I want to do:

(with-foreign-string (locale "en_US.UTF-8")
    (setlocale XXXX locale))

How can I find the integer values of the various LC_xxx constants so that I can pass them to the call above? Is there a better way of achieving this?


You should re-declare the constants in your Lisp code. In fact, CFFI can do this for you.


I see this in my locale.h:

/* These are the possibilities for the first argument to setlocale.
   The code assumes that the lowest LC_* symbol has the value zero.  */
#define LC_CTYPE          __LC_CTYPE
#define LC_NUMERIC        __LC_NUMERIC
#define LC_TIME           __LC_TIME
#define LC_COLLATE        __LC_COLLATE
#define LC_MONETARY       __LC_MONETARY
#define LC_MESSAGES       __LC_MESSAGES
#define LC_ALL            __LC_ALL
#define LC_PAPER          __LC_PAPER
#define LC_NAME           __LC_NAME
#define LC_ADDRESS        __LC_ADDRESS
#define LC_TELEPHONE      __LC_TELEPHONE
#define LC_MEASUREMENT    __LC_MEASUREMENT
#define LC_IDENTIFICATION __LC_IDENTIFICATION

and bits/locale.h contains:

enum
{
  __LC_CTYPE = 0,
  __LC_NUMERIC = 1,
  __LC_TIME = 2,
  __LC_COLLATE = 3,
  __LC_MONETARY = 4,
  __LC_MESSAGES = 5,
  __LC_ALL = 6,
  __LC_PAPER = 7,
  __LC_NAME = 8,
  __LC_ADDRESS = 9,
  __LC_TELEPHONE = 10,
  __LC_MEASUREMENT = 11,
  __LC_IDENTIFICATION = 12
};

You could just compile a C program that prints them. This is what the groveller does.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号