OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [newlib-1.18.0/] [newlib/] [libc/] [locale/] [nl_langinfo.c] - Blame information for rev 207

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 207 jeremybenn
/*-
2
 * Copyright (c) 2001 Alexey Zelkin <phantom@FreeBSD.org>
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
 
27
#include <sys/cdefs.h>
28
 
29
#include <locale.h>
30
#include <langinfo.h>
31
#include <limits.h>
32
#include <stdlib.h>
33
#include <string.h>
34
 
35
#include "timelocal.h"
36
#include "lnumeric.h"
37
#include "lmonetary.h"
38
#include "lmessages.h"
39
 
40
#ifndef __CYGWIN__
41
#define TRANSITION_PERIOD_HACK
42
#endif
43
 
44
#define _REL(BASE) ((int)item-BASE)
45
 
46
extern char *__locale_charset ();
47
 
48
char *
49
_DEFUN(nl_langinfo, (item),
50
       nl_item item) {
51
 
52
   char *ret, *s, *cs;
53
   static char *csym = NULL;
54
#ifdef TRANSITION_PERIOD_HACK
55
   static char *cset = NULL;
56
#endif /* TRANSITION_PERIOD_HACK */
57
   char *nptr;
58
 
59
   switch (item) {
60
        case CODESET:
61
#ifdef __CYGWIN__
62
                ret = __locale_charset ();
63
                /* Temporary exception for KOI8 charsets which are
64
                   incorrectly treated by calling applications otherwise. */
65
                if (strcmp (ret, "CP20866") == 0)
66
                  ret = "KOI8-R";
67
                else if (strcmp (ret, "CP21866") == 0)
68
                  ret = "KOI8-U";
69
#else
70
                ret = "";
71
                if ((s = setlocale(LC_CTYPE, NULL)) != NULL) {
72
                        if ((cs = strchr(s, '.')) != NULL) {
73
                                ret = cs + 1;
74
#ifdef TRANSITION_PERIOD_HACK
75
                                if (strncmp(ret, "ISO_", 4) == 0) {
76
                                        int slen = strlen(ret);
77
 
78
                                        nptr = realloc(cset, slen);
79
 
80
                                        if (!nptr && cset)
81
                                          free (cset);
82
 
83
                                        cset = nptr;
84
                                        if (cset != NULL) {
85
                                                strcpy(cset, "ISO");
86
                                                strcat(cset, ret + 4);
87
                                                ret = cset;
88
                                        } else
89
                                                ret = "";
90
                                } else if (strcmp(ret, "EUC") == 0) {
91
                                        if (strncmp(s, "ja_JP", 5) == 0)
92
                                                ret = "eucJP";
93
                                        else if (strncmp(s, "ko_KR", 5) == 0)
94
                                                ret = "eucKR";
95
                                        else if (strncmp(s, "zh_CN", 5) == 0)
96
                                                ret = "eucCN";
97
                                } else if (strcmp(ret, "ASCII") == 0)
98
                                        ret = "US-ASCII";
99
#endif /* TRANSITION_PERIOD_HACK */
100
                        } else if (strcmp(s, "C") == 0 ||
101
                                   strcmp(s, "POSIX") == 0
102
#ifdef TRANSITION_PERIOD_HACK
103
                                   || strstr(s, "ASCII") != NULL
104
#endif /* TRANSITION_PERIOD_HACK */
105
                                  )
106
                                ret = "US-ASCII";
107
                }
108
#endif /* __CYGWIN__ */
109
                break;
110
        case D_T_FMT:
111
                ret = (char *) __get_current_time_locale()->c_fmt;
112
                break;
113
        case D_FMT:
114
                ret = (char *) __get_current_time_locale()->x_fmt;
115
                break;
116
        case T_FMT:
117
                ret = (char *) __get_current_time_locale()->X_fmt;
118
                break;
119
        case T_FMT_AMPM:
120
                ret = (char *) __get_current_time_locale()->ampm_fmt;
121
                break;
122
        case AM_STR:
123
                ret = (char *) __get_current_time_locale()->am;
124
                break;
125
        case PM_STR:
126
                ret = (char *) __get_current_time_locale()->pm;
127
                break;
128
        case DAY_1: case DAY_2: case DAY_3:
129
        case DAY_4: case DAY_5: case DAY_6: case DAY_7:
130
                ret = (char*) __get_current_time_locale()->weekday[_REL(DAY_1)];
131
                break;
132
        case ABDAY_1: case ABDAY_2: case ABDAY_3:
133
        case ABDAY_4: case ABDAY_5: case ABDAY_6: case ABDAY_7:
134
                ret = (char*) __get_current_time_locale()->wday[_REL(ABDAY_1)];
135
                break;
136
        case MON_1: case MON_2: case MON_3: case MON_4:
137
        case MON_5: case MON_6: case MON_7: case MON_8:
138
        case MON_9: case MON_10: case MON_11: case MON_12:
139
                ret = (char*) __get_current_time_locale()->month[_REL(MON_1)];
140
                break;
141
        case ABMON_1: case ABMON_2: case ABMON_3: case ABMON_4:
142
        case ABMON_5: case ABMON_6: case ABMON_7: case ABMON_8:
143
        case ABMON_9: case ABMON_10: case ABMON_11: case ABMON_12:
144
                ret = (char*) __get_current_time_locale()->mon[_REL(ABMON_1)];
145
                break;
146
        case ERA:
147
                /* XXX: need to be implemented  */
148
                ret = "";
149
                break;
150
        case ERA_D_FMT:
151
                /* XXX: need to be implemented  */
152
                ret = "";
153
                break;
154
        case ERA_D_T_FMT:
155
                /* XXX: need to be implemented  */
156
                ret = "";
157
                break;
158
        case ERA_T_FMT:
159
                /* XXX: need to be implemented  */
160
                ret = "";
161
                break;
162
        case ALT_DIGITS:
163
                /* XXX: need to be implemented  */
164
                ret = "";
165
                break;
166
        case RADIXCHAR:
167
                ret = (char*) __get_current_numeric_locale()->decimal_point;
168
                break;
169
        case THOUSEP:
170
                ret = (char*) __get_current_numeric_locale()->thousands_sep;
171
                break;
172
        case YESEXPR:
173
                ret = (char*) __get_current_messages_locale()->yesexpr;
174
                break;
175
        case NOEXPR:
176
                ret = (char*) __get_current_messages_locale()->noexpr;
177
                break;
178
        /*
179
         * All items marked with LEGACY are available, but not recomended
180
         * by SUSv2 to be used in portable applications since they're subject
181
         * to remove in future specification editions
182
         */
183
        case YESSTR:            /* LEGACY  */
184
                ret = (char*) __get_current_messages_locale()->yesstr;
185
                break;
186
        case NOSTR:             /* LEGACY  */
187
                ret = (char*) __get_current_messages_locale()->nostr;
188
                break;
189
        case CRNCYSTR:
190
                ret = "";
191
                cs = (char*) __get_current_monetary_locale()->currency_symbol;
192
                if (*cs != '\0') {
193
                        char pos = localeconv()->p_cs_precedes;
194
 
195
                        if (pos == localeconv()->n_cs_precedes) {
196
                                char psn = '\0';
197
 
198
                                if (pos == CHAR_MAX) {
199
                                        if (strcmp(cs, __get_current_monetary_locale()->mon_decimal_point) == 0)
200
                                                psn = '.';
201
                                } else
202
                                        psn = pos ? '-' : '+';
203
                                if (psn != '\0') {
204
                                        int clen = strlen(cs);
205
 
206
                                        nptr = realloc(csym, clen + 2);
207
                                        if (!nptr && csym)
208
                                          free (csym);
209
 
210
                                        csym = nptr;
211
 
212
                                        if (csym != NULL) {
213
                                                *csym = psn;
214
                                                strcpy(csym + 1, cs);
215
                                                ret = csym;
216
                                        }
217
                                }
218
                        }
219
                }
220
                break;
221
        case D_MD_ORDER:        /* local extension */
222
                ret = (char *) __get_current_time_locale()->md_order;
223
                break;
224
        default:
225
                ret = "";
226
   }
227
   return (ret);
228
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.