source: trunk/libc/include/klibc/locale.h@ 3056

Last change on this file since 3056 was 3056, checked in by bird, 19 years ago

Added a fixed default (C/POSIX) collate locale to avoid unilib strangeness. Made an attempt at adjusting for this strangeness for the non-default locales...

  • Property cvs2svn:cvs-rev set to 1.5
  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 13.5 KB
Line 
1/* $Id: locale.h 3056 2007-04-08 17:12:27Z bird $ */
2/** @file
3 *
4 * kLIBC - Internal locale header.
5 *
6 * Copyright (c) 2003 InnoTek Systemberatung GmbH
7 * Copyright (c) 2003-2006 knut st. osmundsen <[email protected]>
8 *
9 *
10 * This file is part of kLIBC.
11 *
12 * kLIBC is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License as published
14 * by the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * kLIBC is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU Lesser General Public License for more details.
21 *
22 * You should have received a copy of the GNU Lesser General Public License
23 * along with kLIBC; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 *
26 */
27
28#ifndef __klibc_locale_h__
29#define __klibc_locale_h__
30
31#include <sys/cdefs.h>
32#include <sys/types.h>
33#include <locale.h>
34#ifdef __OS2__
35# include <uconv.h>
36#endif
37#ifdef __CTYPE_H_
38# error "klibc/locale.h must be included *before* ctype.h!"
39#endif
40
41__BEGIN_DECLS
42
43/**
44 * LC_COLLATE information.
45 */
46typedef struct __libc_LocaleCollate
47{
48 /** Character weight for SBCS codepages. */
49 unsigned char auchWeight[256];
50 /** MBCS prefixes. Two bits per character. */
51 unsigned char au2MBCSPrefixs[256/4];
52#ifdef __OS2__
53 /** The converter object to convert to and from selected codepage
54 (used with MBCS codepages only). */
55 UconvObject uobj;
56 /** The locale object. */
57 LocaleObject lobj;
58#endif
59 /** Non-zero if there are any MBCS prefix characters in codepage. */
60 char mbcs;
61} __LIBC_LOCALECOLLATE;
62/** Pointer to locale collate structure. */
63typedef __LIBC_LOCALECOLLATE *__LIBC_PLOCALECOLLATE;
64
65/**
66 * Multibyte to/from wide character conversion functions.
67 */
68typedef struct __libc_localeCTypeFuncs
69{
70 int (*pfnmbsinit)(const __mbstate_t *);
71 size_t (*pfnmbrtowc)(__wchar_t * __restrict, const char * __restrict, size_t, __mbstate_t * __restrict);
72 size_t (*pfnmbsnrtowcs)(__wchar_t * __restrict, const char ** __restrict, size_t, size_t, __mbstate_t * __restrict);
73 size_t (*pfnwcrtomb)(char * __restrict, __wchar_t, __mbstate_t * __restrict);
74 size_t (*pfnwcsnrtombs)(char * __restrict, const __wchar_t ** __restrict, size_t, size_t, __mbstate_t * __restrict);
75} __LIBC_LOCALECTYPEFUNCS;
76/** Pointer to multibyte/wide character conversion functions. */
77typedef __LIBC_LOCALECTYPEFUNCS *__LIBC_PLOCALECTYPEFUNCS;
78/** Pointer to const multibyte/wide character conversion functions. */
79typedef const __LIBC_LOCALECTYPEFUNCS *__LIBC_PCLOCALECTYPEFUNCS;
80
81/**
82 * This structure contains the flags and uppercase/lowercase tables.
83 */
84typedef struct __libc_LocaleCtype
85{
86 /** All uppercased characters. */
87 unsigned char auchUpper[256];
88 /** All lowercased characters. */
89 unsigned char auchLower[256];
90 /** Bit flags for every character (for isXXX() function series). */
91 unsigned aufType[256];
92
93/* part which we don't 'expose': */
94 /** MBCS prefixes. Two bits per character. */
95 unsigned char au2MBCSPrefixs[256/4];
96 /** Unicode translation. (0xffff means no translation.) */
97 unsigned short aucUnicode[256];
98 /** Unicode -> SBCS conversion: 0..128. */
99 unsigned char auchToSBCS0To128[128];
100 /** Unicode -> SBCS conversion: Custom regions. */
101 struct
102 {
103 /** First unicode code point. */
104 unsigned short usStart;
105 /** Number of entries used. */
106 unsigned short cChars;
107 /** Array SBCS chars corresponding to (wc - usStart). 0 means no conversion. */
108 unsigned char auch[28];
109 } aSBCSs[8];
110 /** Number of aSBCS regions in use. */
111 unsigned cSBCSs;
112 /** Conversion functions. */
113 __LIBC_LOCALECTYPEFUNCS CtypeFuncs;
114#ifdef __OS2__
115 /** The converter object to convert to and from selected codepage
116 (used with MBCS codepages only). */
117 UconvObject uobj;
118 /** The locale object. */
119 LocaleObject lobj;
120#endif
121 /** Non-zero if there are any MBCS prefix characters in codepage. */
122 char mbcs;
123 /** Codeset name. */
124 char szCodeSet[32];
125} __LIBC_LOCALECTYPE;
126/** Pointer to the Ctype locale struct. */
127typedef __LIBC_LOCALECTYPE *__LIBC_PLOCALECTYPE;
128
129
130/**
131 * Unicode CType data.
132 * The structure contains information for the first 256 unicode chars.
133 */
134typedef struct __libc_localeWCType
135{
136 /** All uppercased characters. */
137 __wchar_t awcUpper[256];
138 /** All lowercased characters. */
139 __wchar_t awcLower[256];
140 /** Bit flags for every character (for iswXXX() function series). */
141 unsigned aufType[256];
142 /** Mask used to check if an index is within the above arrays.
143 * This is required because 'C' doesn't do more than 0-127. So,
144 * the mask is either ~0xff or ~0x7f. */
145 unsigned uMask;
146} __LIBC_LOCALEWCTYPE;
147/** Pointer to the Ctype unicode struct. */
148typedef __LIBC_LOCALEWCTYPE *__LIBC_PLOCALEWCTYPE;
149
150/**
151 * This structure keeps the time formatting rules.
152 * The fConsts flag indicates what kind of memory is backing the strings.
153 */
154typedef struct __libc_LocaleTime
155{
156 /** Short month names. */
157 char *smonths[12];
158 /** Long month names. */
159 char *lmonths[12];
160 /** Short weekday names. */
161 char *swdays[7];
162 /** Long weekday names. */
163 char *lwdays[7];