lmessages.c revision 88348
1115013Smarcel/*
2160157Smarcel * Copyright (c) 2001 Alexey Zelkin <phantom@FreeBSD.org>
3121642Smarcel * All rights reserved.
4121642Smarcel *
5121642Smarcel * Redistribution and use in source and binary forms, with or without
6121642Smarcel * modification, are permitted provided that the following conditions
7121642Smarcel * are met:
8121642Smarcel * 1. Redistributions of source code must retain the above copyright
9121642Smarcel *    notice, this list of conditions and the following disclaimer.
10121642Smarcel * 2. Redistributions in binary form must reproduce the above copyright
11115013Smarcel *    notice, this list of conditions and the following disclaimer in the
12121642Smarcel *    documentation and/or other materials provided with the distribution.
13121642Smarcel *
14121642Smarcel * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15121642Smarcel * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16121642Smarcel * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17121642Smarcel * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18121642Smarcel * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19121642Smarcel * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20121642Smarcel * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21121642Smarcel * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22121642Smarcel * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23121642Smarcel * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24121642Smarcel * SUCH DAMAGE.
25115013Smarcel *
26115013Smarcel * $FreeBSD: head/lib/libc/locale/lmessages.c 88348 2001-12-21 13:14:02Z phantom $
27115013Smarcel */
28115013Smarcel
29115013Smarcel#include <stddef.h>
30115013Smarcel
31115013Smarcel#include "lmessages.h"
32115013Smarcel#include "ldpart.h"
33115013Smarcel
34115013Smarcel#define LCMESSAGES_SIZE_FULL (sizeof(struct lc_messages_T) / sizeof(char *))
35115013Smarcel#define LCMESSAGES_SIZE_MIN \
36115013Smarcel		(offsetof(struct lc_messages_T, yesstr) / sizeof(char *))
37115013Smarcel
38115013Smarcelstatic char empty[] = "";
39115013Smarcel
40115013Smarcelstatic const struct lc_messages_T _C_messages_locale = {
41115013Smarcel	"^[yY]" ,	/* yesexpr */
42115013Smarcel	"^[nN]" ,	/* noexpr */
43115013Smarcel	"yes" , 	/* yesstr */
44120925Smarcel	"no"		/* nostr */
45115013Smarcel};
46115013Smarcel
47115013Smarcelstatic struct lc_messages_T _messages_locale;
48115013Smarcelstatic int	_messages_using_locale;
49115013Smarcelstatic char	*_messages_locale_buf;
50115013Smarcel
51115013Smarcelint
52115013Smarcel__messages_load_locale(const char *name) {
53115013Smarcel
54115013Smarcel	/*
55115013Smarcel	 * Propose that we can have incomplete locale file (w/o "{yes,no}str").
56115013Smarcel	 * Initialize them before loading.  In case of complete locale, they'll
57115013Smarcel	 * be initialized to loaded value, otherwise they'll not be touched.
58115013Smarcel	 */
59115013Smarcel	_messages_locale.yesstr = empty;
60115013Smarcel	_messages_locale.nostr = empty;
61115013Smarcel
62115013Smarcel	return __part_load_locale(name, &_messages_using_locale,
63115013Smarcel		_messages_locale_buf, "LC_MESSAGES/SYS_LC_MESSAGES",
64115013Smarcel		LCMESSAGES_SIZE_FULL, LCMESSAGES_SIZE_MIN,
65115013Smarcel		(const char **)&_messages_locale);
66120925Smarcel}
67120925Smarcel
68115013Smarcelstruct lc_messages_T *
69115013Smarcel__get_current_messages_locale(void) {
70115013Smarcel
71115013Smarcel	return (_messages_using_locale
72115013Smarcel		? &_messages_locale
73115013Smarcel		: (struct lc_messages_T *)&_C_messages_locale);
74115013Smarcel}
75115013Smarcel
76115013Smarcel#ifdef LOCALE_DEBUG
77115013Smarcelvoid
78115013Smarcelmsgdebug() {
79115013Smarcelprintf(	"yesexpr = %s\n"
80115013Smarcel	"noexpr = %s\n"
81129059Smarcel	"yesstr = %s\n"
82115013Smarcel	"nostr = %s\n",
83160157Smarcel	_messages_locale.yesexpr,
84160157Smarcel	_messages_locale.noexpr,
85160157Smarcel	_messages_locale.yesstr,
86160157Smarcel	_messages_locale.nostr
87160157Smarcel);
88115013Smarcel}
89115013Smarcel#endif /* LOCALE_DEBUG */
90115013Smarcel