lmessages.c revision 72443
1139749Simp/* 291355Simp * Copyright (c) 2001 Alexey Zelkin 391355Simp * All rights reserved. 491355Simp * 591355Simp * Redistribution and use in source and binary forms, with or without 691355Simp * modification, are permitted provided that the following conditions 791355Simp * are met: 891355Simp * 1. Redistributions of source code must retain the above copyright 991355Simp * notice, this list of conditions and the following disclaimer. 1091355Simp * 2. Redistributions in binary form must reproduce the above copyright 1191355Simp * notice, this list of conditions and the following disclaimer in the 1291355Simp * documentation and/or other materials provided with the distribution. 1391355Simp * 1491355Simp * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1591355Simp * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1691355Simp * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1791355Simp * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1891355Simp * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1991355Simp * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2091355Simp * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2191355Simp * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2291355Simp * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2391355Simp * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2491355Simp * SUCH DAMAGE. 2591355Simp * 2691355Simp * $FreeBSD: head/lib/libc/locale/lmessages.c 72443 2001-02-13 15:32:21Z phantom $ 2791355Simp */ 2891355Simp 2991355Simp#include <stddef.h> 3091355Simp 3191355Simp#include "lmessages.h" 3291355Simp#include "ldpart.h" 33165217Sjhb 3491355Simp#define LCMESSAGES_SIZE_FULL (sizeof(struct lc_messages_T) / sizeof(char *)) 3591355Simp#define LCMESSAGES_SIZE_MIN \ 3691355Simp (offsetof(struct lc_messages_T, yesstr) / sizeof(char *)) 37154599Sjhb 3891355Simpchar empty[] = ""; 39154599Sjhb 40102440Sjhbstatic const struct lc_messages_T _C_messages_locale = { 41232403Sjhb "^[yY]" , /* yesexpr */ 42232403Sjhb "^[nN]" , /* noexpr */ 43232403Sjhb "yes" , /* yesstr */ 44232403Sjhb "no" /* nostr */ 45211430Sjhb}; 46214110Sjkim 47211430Sjhbstatic struct lc_messages_T _messages_locale; 48172394Smariusstatic int _messages_using_locale; 49172394Smariusstatic char * messages_locale_buf; 50102440Sjhb 51153898Simpint 52153898Simp__messages_load_locale(const char *name) { 53232403Sjhb 54201609Sjhb /* Propose that we can have incomplete locale file (w/o "{yes,no}str"). 55128058Simp Initialize them before loading. In case of complete locale, they'll 5691355Simp be initialized to loaded value, otherwise they'll not be touched. */ 5791355Simp _messages_locale.yesstr = empty; 5891355Simp _messages_locale.nostr = empty; 5991355Simp 6091355Simp return __part_load_locale(name, &_messages_using_locale, 6191355Simp messages_locale_buf, "LC_MESSAGES", 62169221Sjhb LCMESSAGES_SIZE_FULL, LCMESSAGES_SIZE_MIN, 63169221Sjhb (const char **)&_messages_locale); 64169221Sjhb} 65169221Sjhb 66169221Sjhbstruct lc_messages_T * 67163163Sjmg__get_current_messages_locale(void) { 68163163Sjmg 69163163Sjmg return (_messages_using_locale 70163163Sjmg ? &_messages_locale 7191355Simp : (struct lc_messages_T *)&_C_messages_locale); 7291355Simp} 7391355Simp 74119266Simp#ifdef LOCALE_DEBUG 7591355Simpvoid 7691355Simpmsgdebug() { 77119266Simpprintf( "yesexpr = %s\n" 78113544Smdodd "noexpr = %s\n" 79113544Smdodd "yesstr = %s\n" 80113544Smdodd "nostr = %s\n", 81113544Smdodd _messages_locale.yesexpr, 82232472Sjhb _messages_locale.noexpr, 83232472Sjhb _messages_locale.yesstr, 84153560Sjhb _messages_locale.nostr 85153560Sjhb); 86232472Sjhb} 87232472Sjhb#endif /* LOCALE_DEBUG */ 88164264Sjhb