2002-08-23 09:56:05 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2001 Alexey Zelkin <phantom@FreeBSD.org>
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
|
|
|
|
#include <stddef.h>
|
2016-07-13 22:51:33 +08:00
|
|
|
#include "setlocale.h"
|
2002-08-23 09:56:05 +08:00
|
|
|
|
|
|
|
#define LCMESSAGES_SIZE_FULL (sizeof(struct lc_messages_T) / sizeof(char *))
|
|
|
|
#define LCMESSAGES_SIZE_MIN \
|
|
|
|
(offsetof(struct lc_messages_T, yesstr) / sizeof(char *))
|
|
|
|
|
2012-08-08 19:04:18 +08:00
|
|
|
#ifndef __CYGWIN__
|
2002-08-23 09:56:05 +08:00
|
|
|
static char empty[] = "";
|
2012-08-08 19:04:18 +08:00
|
|
|
#endif
|
2002-08-23 09:56:05 +08:00
|
|
|
|
2016-07-19 22:48:07 +08:00
|
|
|
const struct lc_messages_T _C_messages_locale = {
|
2002-08-23 09:56:05 +08:00
|
|
|
"^[yY]" , /* yesexpr */
|
|
|
|
"^[nN]" , /* noexpr */
|
|
|
|
"yes" , /* yesstr */
|
2011-07-20 03:24:45 +08:00
|
|
|
"no" /* nostr */
|
2010-04-28 17:59:37 +08:00
|
|
|
#ifdef __HAVE_LOCALE_INFO_EXTENDED__
|
2011-07-20 03:24:45 +08:00
|
|
|
, "ASCII" , /* codeset */
|
|
|
|
L"^[yY]" , /* wyesexpr */
|
2010-04-28 17:59:37 +08:00
|
|
|
L"^[nN]" , /* wnoexpr */
|
|
|
|
L"yes" , /* wyesstr */
|
|
|
|
L"no" /* wnostr */
|
|
|
|
#endif
|
2002-08-23 09:56:05 +08:00
|
|
|
};
|
|
|
|
|
2016-07-13 22:51:33 +08:00
|
|
|
#ifndef __CYGWIN__
|
2002-08-23 09:56:05 +08:00
|
|
|
static struct lc_messages_T _messages_locale;
|
|
|
|
static int _messages_using_locale;
|
|
|
|
static char *_messages_locale_buf;
|
2016-07-13 22:51:33 +08:00
|
|
|
#endif
|
2002-08-23 09:56:05 +08:00
|
|
|
|
|
|
|
int
|
2016-07-22 02:49:42 +08:00
|
|
|
__messages_load_locale (struct __locale_t *locale, const char *name,
|
2016-07-13 22:51:33 +08:00
|
|
|
void *f_wctomb, const char *charset)
|
2010-02-09 16:58:38 +08:00
|
|
|
{
|
2016-07-13 22:51:33 +08:00
|
|
|
int ret;
|
|
|
|
struct lc_messages_T me;
|
|
|
|
char *bufp = NULL;
|
|
|
|
|
2010-02-09 16:58:38 +08:00
|
|
|
#ifdef __CYGWIN__
|
2016-07-13 22:51:33 +08:00
|
|
|
extern int __set_lc_messages_from_win (const char *,
|
|
|
|
const struct lc_messages_T *,
|
|
|
|
struct lc_messages_T *, char **,
|
|
|
|
void *, const char *);
|
2002-08-23 09:56:05 +08:00
|
|
|
|
2016-07-13 22:51:33 +08:00
|
|
|
ret = __set_lc_messages_from_win (name, &_C_messages_locale, &me, &bufp,
|
|
|
|
f_wctomb, charset);
|
|
|
|
/* ret == -1: error, ret == 0: C/POSIX, ret > 0: valid */
|
|
|
|
if (ret >= 0)
|
|
|
|
{
|
|
|
|
struct lc_messages_T *mep = NULL;
|
|
|
|
|
|
|
|
if (ret > 0)
|
|
|
|
{
|
|
|
|
mep = (struct lc_messages_T *) calloc (1, sizeof *mep);
|
|
|
|
if (!mep)
|
2016-07-23 19:30:21 +08:00
|
|
|
{
|
|
|
|
free (bufp);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
*mep = me;
|
2016-07-13 22:51:33 +08:00
|
|
|
}
|
2016-07-23 19:30:21 +08:00
|
|
|
struct __lc_cats tmp = locale->lc_cat[LC_MESSAGES];
|
2016-07-23 01:57:56 +08:00
|
|
|
locale->lc_cat[LC_MESSAGES].ptr = ret == 0 ? &_C_messages_locale : mep;
|
|
|
|
locale->lc_cat[LC_MESSAGES].buf = bufp;
|
2016-07-23 19:30:21 +08:00
|
|
|
/* If buf is not NULL, both pointers have been alloc'ed */
|
|
|
|
if (tmp.buf)
|
|
|
|
{
|
|
|
|
free ((void *) tmp.ptr);
|
|
|
|
free (tmp.buf);
|
|
|
|
}
|
2016-07-13 22:51:33 +08:00
|
|
|
ret = 0;
|
|
|
|
}
|
2010-02-09 16:58:38 +08:00
|
|
|
#else
|
2016-07-23 20:19:25 +08:00
|
|
|
/* TODO */
|
2010-02-09 16:58:38 +08:00
|
|
|
#endif
|
2016-07-13 22:51:33 +08:00
|
|
|
return ret;
|
2002-08-23 09:56:05 +08:00
|
|
|
}
|