如何在 gettext-runtime\intl\printf.c 中启用 HAVE_FWPRINTF?

问题描述

我正在尝试在 Windows 系统上返回区域设置名称。为此,我需要在代码中使用 swprintf(),如下所示。

#include <wchar.h>
#include <shlwapi.h>
#include <langinfo.h>
...


/* Construct the full name of the locale. E.g. "en-US" to
 * "English_United States".
 */
static char *
construct_full_locale_name(wchar_t *locale_name)
{
    char        result[FULL_LOCALE_NAME_LENGTH * 2];
    wchar_t     wc_full_locale_name[FULL_LOCALE_NAME_LENGTH];
    wchar_t     buffer[LOCALE_NAME_MAX_LENGTH];
    size_t      len;

    wmemset(wc_full_locale_name,LOCALE_NAME_MAX_LENGTH);

    /*
     * Construct the full name of the locale using GetLocaleInfoEx API by using
     * a few specific flags in the following order.  First,if the locale is
     * valid,we will get the language name in English by using
     * LOCALE_SENGLISHLANGUAGENAME flag. If the locale is invalid we can't get
     * anything so we are returning the locale name as it is. Once the locale
     * is verified,we can proceed to get region using
     * LOCALE_SENGLISHCOUNTRYNAME flag. In the same way,we will get code-page
     * using LOCALE_IDEFAULTANSICODEPAGE.
     */
    if (GetLocaleInfoEx(locale_name,LOCALE_SENGLISHLANGUAGENAME,(LPWSTR)&buffer,LOCALE_NAME_MAX_LENGTH))
    {
        int cp;

        len = swprintf(wc_full_locale_name,LOCALE_NAME_MAX_LENGTH,L"%ls",buffer);
        wmemset(buffer,LOCALE_NAME_MAX_LENGTH);
        GetLocaleInfoEx(locale_name,LOCALE_SENGLISHCOUNTRYNAME,LOCALE_NAME_MAX_LENGTH);
        len += swprintf(wc_full_locale_name + len,LOCALE_NAME_MAX_LENGTH - len,L"_%ls",buffer);

        GetLocaleInfoEx(locale_name,LOCALE_IDEFAULTANSICODEPAGE | LOCALE_RETURN_NUMBER,(LPWSTR)&cp,sizeof(cp) / sizeof(WCHAR));
        swprintf(wc_full_locale_name + len,FULL_LOCALE_NAME_LENGTH - len,L".%u",cp);
        /*wchar2char() is internally defined function to turn wide-char to char */

        wchar2char(result,wc_full_locale_name,sizeof(wc_full_locale_name),NULL);
    }
        sprintf(result,"%s",locale_messages);

    return result;
}

这里的问题是,当我在其他系统上构建此代码时,我在运行时遇到错误 libintl_swprintf 未找到。经过一番调查,我发现这个符号与 libintl.h 相关。

#undef swprintf
#define swprintf libintl_swprintf
extern LIBINTL_DLL_EXPORTED int swprintf (wchar_t *,size_t,const wchar_t *,...);

函数定义在 gettext-runtime\intl\printf.c

...
#if HAVE_FWPRINTF
...
DLL_EXPORTED
  int
  libintl_swprintf (wchar_t *resultbuf,size_t length,const wchar_t *format,...)
  {
    va_list args;
    int retval;
 
    va_start (args,format);
    retval = libintl_vswprintf (resultbuf,length,format,args);
   va_end (args);
    return retval;
  }
 
 #endif
 
 #endif

功能HAVE_FWPRINTF控制,我在gettext代码中找不到它的定义位置,有人可以帮助如何启用它吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)