如何找到 LC_XXX 区域设置整数常量的值,以便我可以将它们与 cffi 一起使用

发布于 2024-11-14 06:47:27 字数 361 浏览 7 评论 0原文

我有这段代码:

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

并且我想做:

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

如何找到各种 LC_xxx 常量的整数值,以便我可以将它们传递给上面的调用?有更好的方法来实现这一目标吗?

I have this code:

(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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

初心 2024-11-21 06:47:27

您应该在 Lisp 代码中重新声明常量。事实上,CFFI 可以为您做到这一点

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

苦妄 2024-11-21 06:47:27

我在 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

并且 bits/locale.h 包含:

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
};

您可以编译一个打印它们的 C 程序。
这就是格罗勒所做的。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文