lmessages.c revision 6b5e5868e7ebf1aff3a5abd7d0c4ef0e5fbf3648
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore/*
6b5e5868e7ebf1aff3a5abd7d0c4ef0e5fbf3648Garrett D'Amore * Copyright 2010 Nexenta Systems, Inc. All rights reserved.
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * Copyright (c) 2001 Alexey Zelkin <phantom@FreeBSD.org>
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * All rights reserved.
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore *
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * Redistribution and use in source and binary forms, with or without
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * modification, are permitted provided that the following conditions
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * are met:
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * 1. Redistributions of source code must retain the above copyright
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * notice, this list of conditions and the following disclaimer.
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * 2. Redistributions in binary form must reproduce the above copyright
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * notice, this list of conditions and the following disclaimer in the
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * documentation and/or other materials provided with the distribution.
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore *
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * SUCH DAMAGE.
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore#include "lint.h"
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore#include <stddef.h>
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore#include "ldpart.h"
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore#include "lmessages.h"
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore#define LCMESSAGES_SIZE_FULL (sizeof (struct lc_messages_T) / sizeof (char *))
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore#define LCMESSAGES_SIZE_MIN \
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore (offsetof(struct lc_messages_T, yesstr) / sizeof (char *))
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amorestatic char empty[] = "";
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amorestatic const struct lc_messages_T _C_messages_locale = {
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore "^[yY]", /* yesexpr */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore "^[nN]", /* noexpr */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore "yes", /* yesstr */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore "no" /* nostr */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore};
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amorestatic struct lc_messages_T _messages_locale;
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amorestatic int _messages_using_locale;
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amorestatic char *_messages_locale_buf;
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amoreint
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore__messages_load_locale(const char *name)
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore{
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore int ret;
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore ret = __part_load_locale(name, &_messages_using_locale,
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore &_messages_locale_buf, "LC_MESSAGES",
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore LCMESSAGES_SIZE_FULL, LCMESSAGES_SIZE_MIN,
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore (const char **)&_messages_locale);
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore if (ret == _LDP_LOADED) {
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore if (_messages_locale.yesstr == NULL)
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore _messages_locale.yesstr = empty;
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore if (_messages_locale.nostr == NULL)
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore _messages_locale.nostr = empty;
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore }
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore return (ret);
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore}
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amorestruct lc_messages_T *
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore__get_current_messages_locale(void)
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore{
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore return (_messages_using_locale ? &_messages_locale :
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore (struct lc_messages_T *)&_C_messages_locale);
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore}