nl_langinfo.c revision 72263
1/*- 2 * Copyright (c) 2001 Alexey Zelkin 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * 26 * $FreeBSD: head/lib/libc/locale/nl_langinfo.c 72263 2001-02-09 22:43:39Z ache $ 27 */ 28 29#include <locale.h> 30#include <langinfo.h> 31#include <string.h> 32#include "../stdtime/timelocal.h" 33#include "lnumeric.h" 34#include "lmonetary.h" 35#include "lmessages.h" 36 37#define _REL(BASE) ((int)item-BASE) 38 39char * 40nl_langinfo(nl_item item) { 41 42 char *ret, *s, *cs; 43 44 switch (item) { 45 case CODESET: 46 ret = ""; 47 if ((s = setlocale(LC_CTYPE, NULL)) != NULL) { 48 if ((cs = strchr(s, '.')) != NULL) 49 ret = cs + 1; 50 else if (strcmp(s, "C") == 0 || 51 strcmp(s, "POSIX") == 0) 52 ret = "US-ASCII"; 53 } 54 break; 55 case D_T_FMT: 56 ret = (char *) __get_current_time_locale()->c_fmt; 57 break; 58 case D_FMT: 59 ret = (char *) __get_current_time_locale()->x_fmt; 60 break; 61 case T_FMT: 62 ret = (char *) __get_current_time_locale()->X_fmt; 63 break; 64 case T_FMT_AMPM: 65 ret = "%r"; 66 break; 67 case AM_STR: 68 ret = (char *) __get_current_time_locale()->am; 69 break; 70 case PM_STR: 71 ret = (char *) __get_current_time_locale()->pm; 72 break; 73 case DAY_1: case DAY_2: case DAY_3: 74 case DAY_4: case DAY_5: case DAY_6: case DAY_7: 75 ret = (char*) __get_current_time_locale()->weekday[_REL(DAY_1)]; 76 break; 77 case ABDAY_1: case ABDAY_2: case ABDAY_3: 78 case ABDAY_4: case ABDAY_5: case ABDAY_6: case ABDAY_7: 79 ret = (char*) __get_current_time_locale()->wday[_REL(ABDAY_1)]; 80 break; 81 case MON_1: case MON_2: case MON_3: case MON_4: 82 case MON_5: case MON_6: case MON_7: case MON_8: 83 case MON_9: case MON_10: case MON_11: case MON_12: 84 ret = (char*) __get_current_time_locale()->month[_REL(MON_1)]; 85 break; 86 case ABMON_1: case ABMON_2: case ABMON_3: case ABMON_4: 87 case ABMON_5: case ABMON_6: case ABMON_7: case ABMON_8: 88 case ABMON_9: case ABMON_10: case ABMON_11: case ABMON_12: 89 ret = (char*) __get_current_time_locale()->mon[_REL(ABMON_1)]; 90 break; 91 case ERA: 92 /* XXX: ??? */ 93 ret = ""; 94 break; 95 case ERA_D_FMT: 96 /* XXX: ??? */ 97 ret = ""; 98 break; 99 case ERA_D_T_FMT: 100 /* XXX: ??? */ 101 ret = ""; 102 break; 103 case ERA_T_FMT: 104 /* XXX: ??? */ 105 ret = ""; 106 break; 107 case ALT_DIGITS: 108 /* XXX: ??? */ 109 ret = ""; 110 break; 111 case RADIXCHAR: /* deprecated */ 112 ret = (char*) __get_current_numeric_locale()->decimal_point; 113 break; 114 case THOUSEP: /* deprecated */ 115 ret = (char*) __get_current_numeric_locale()->thousands_sep; 116 break; 117 case YESEXPR: 118 ret = (char*) __get_current_messages_locale()->yesexpr; 119 break; 120 case NOEXPR: 121 ret = (char*) __get_current_messages_locale()->noexpr; 122 break; 123 case YESSTR: /* deprecated */ 124 ret = ""; 125 break; 126 case NOSTR: /* deprecated */ 127 ret = ""; 128 break; 129 case CRNCYSTR: /* deprecated */ 130 /* XXX: need to be implemented */ 131 /* __get_current_monetary_locale()->currency_symbol */ 132 /* but requare special +-. prefixes according to SUSV2 */ 133 ret = ""; 134 break; 135 default: 136 ret = ""; 137 } 138 return (ret); 139} 140