lmessages.c revision 92986
158310Sache/*
258310Sache * Copyright (c) 2001 Alexey Zelkin <phantom@FreeBSD.org>
358310Sache * All rights reserved.
458310Sache *
558310Sache * Redistribution and use in source and binary forms, with or without
658310Sache * modification, are permitted provided that the following conditions
758310Sache * are met:
858310Sache * 1. Redistributions of source code must retain the above copyright
958310Sache *    notice, this list of conditions and the following disclaimer.
1058310Sache * 2. Redistributions in binary form must reproduce the above copyright
1158310Sache *    notice, this list of conditions and the following disclaimer in the
1258310Sache *    documentation and/or other materials provided with the distribution.
1358310Sache *
1458310Sache * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1558310Sache * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1658310Sache * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1758310Sache * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1858310Sache * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1958310Sache * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2058310Sache * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2158310Sache * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2258310Sache * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2358310Sache * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2458310Sache * SUCH DAMAGE.
2558310Sache */
2658310Sache
2758310Sache#include <sys/cdefs.h>
2858310Sache__FBSDID("$FreeBSD: head/lib/libc/locale/lmessages.c 92986 2002-03-22 21:53:29Z obrien $");
2958310Sache
3058310Sache#include <stddef.h>
3158310Sache
3258310Sache#include "lmessages.h"
3358310Sache#include "ldpart.h"
3458310Sache
35165670Sache#define LCMESSAGES_SIZE_FULL (sizeof(struct lc_messages_T) / sizeof(char *))
36165670Sache#define LCMESSAGES_SIZE_MIN \
37165670Sache		(offsetof(struct lc_messages_T, yesstr) / sizeof(char *))
3858310Sache
3958310Sachestatic char empty[] = "";
4058310Sache
4158310Sachestatic const struct lc_messages_T _C_messages_locale = {
4258310Sache	"^[yY]" ,	/* yesexpr */
4358310Sache	"^[nN]" ,	/* noexpr */
4458310Sache	"yes" , 	/* yesstr */
4558310Sache	"no"		/* nostr */
4658310Sache};
4758310Sache
4858310Sachestatic struct lc_messages_T _messages_locale;
4958310Sachestatic int	_messages_using_locale;
5058310Sachestatic char	*_messages_locale_buf;
5158310Sache
5258310Sacheint
5358310Sache__messages_load_locale(const char *name) {
5458310Sache
5558310Sache	/*
5658310Sache	 * Propose that we can have incomplete locale file (w/o "{yes,no}str").
5758310Sache	 * Initialize them before loading.  In case of complete locale, they'll
5858310Sache	 * be initialized to loaded value, otherwise they'll not be touched.
5958310Sache	 */
6058310Sache	_messages_locale.yesstr = empty;
6158310Sache	_messages_locale.nostr = empty;
6258310Sache
6358310Sache	return __part_load_locale(name, &_messages_using_locale,
6458310Sache		_messages_locale_buf, "LC_MESSAGES",
6558310Sache		LCMESSAGES_SIZE_FULL, LCMESSAGES_SIZE_MIN,
6658310Sache		(const char **)&_messages_locale);
6758310Sache}
6858310Sache
6958310Sachestruct lc_messages_T *
7058310Sache__get_current_messages_locale(void) {
7158310Sache
7258310Sache	return (_messages_using_locale
7358310Sache		? &_messages_locale
7458310Sache		: (struct lc_messages_T *)&_C_messages_locale);
7558310Sache}
7658310Sache
7758310Sache#ifdef LOCALE_DEBUG
7858310Sachevoid
7958310Sachemsgdebug() {
8058310Sacheprintf(	"yesexpr = %s\n"
8158310Sache	"noexpr = %s\n"
8258310Sache	"yesstr = %s\n"
8358310Sache	"nostr = %s\n",
8458310Sache	_messages_locale.yesexpr,
8558310Sache	_messages_locale.noexpr,
8658310Sache	_messages_locale.yesstr,
8758310Sache	_messages_locale.nostr
8858310Sache);
8958310Sache}
9058310Sache#endif /* LOCALE_DEBUG */
9158310Sache