1/* Declarations for internal libc locale interfaces 2 Copyright (C) 1995, 96, 97, 98, 99,2000,2001 Free Software Foundation, Inc. 3 This file is part of the GNU C Library. 4 5 The GNU C Library is free software; you can redistribute it and/or 6 modify it under the terms of the GNU Lesser General Public 7 License as published by the Free Software Foundation; either 8 version 2.1 of the License, or (at your option) any later version. 9 10 The GNU C Library is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 Lesser General Public License for more details. 14 15 You should have received a copy of the GNU Lesser General Public 16 License along with the GNU C Library; if not, write to the Free 17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 18 02111-1307 USA. */ 19 20#ifndef _LOCALEINFO_H 21#define _LOCALEINFO_H 1 22 23#include <stddef.h> 24#include <langinfo.h> 25#include <limits.h> 26#include <time.h> 27#include <stdint.h> 28#include <sys/types.h> 29 30// __locale_struct 31#include <xlocale.h> 32// LC_* values 33#include <locale.h> 34 35/* This has to be changed whenever a new locale is defined. */ 36#define __LC_LAST 7 37 38#include <intl/loadinfo.h> /* For loaded_l10nfile definition. */ 39 40/* Magic number at the beginning of a locale data file for CATEGORY. */ 41#define LIMAGIC(category) ((unsigned int) (0x20000828 ^ (category))) 42 43/* Two special weight constants for the collation data. */ 44#define IGNORE_CHAR 2 45 46/* We use a special value for the usage counter in `locale_data' to 47 signal that this data must never be removed anymore. */ 48#define MAX_USAGE_COUNT (UINT_MAX - 1) 49#define UNDELETABLE UINT_MAX 50 51/* Structure describing locale data in core for a category. */ 52struct locale_data 53{ 54 const char *name; 55 const char *filedata; /* Region mapping the file data. */ 56 off_t filesize; /* Size of the file (and the region). */ 57 int mmaped; /* If nonzero the data is mmaped. */ 58 59 unsigned int usage_count; /* Counter for users. */ 60 61 int use_translit; /* Nonzero if the mb*towv*() and wc*tomb() 62 functions should use transliteration. */ 63 const char *options; /* Extra options from the locale name, 64 not used in the path to the locale data. */ 65 66 unsigned int nstrings; /* Number of strings below. */ 67 union locale_data_value 68 { 69 const uint32_t *wstr; 70 const char *string; 71 unsigned int word; 72 } 73 values __flexarr; /* Items, usually pointers into `filedata'. */ 74}; 75 76/* We know three kinds of collation sorting rules. */ 77enum coll_sort_rule 78{ 79 illegal_0__, 80 sort_forward, 81 sort_backward, 82 illegal_3__, 83 sort_position, 84 sort_forward_position, 85 sort_backward_position, 86 sort_mask 87}; 88 89/* We can map the types of the entries into a few categories. */ 90enum value_type 91{ 92 none, 93 string, 94 stringarray, 95 byte, 96 bytearray, 97 word, 98 stringlist, 99 wordarray, 100 wstring, 101 wstringarray, 102 wstringlist 103}; 104 105 106/* Definitions for `era' information from LC_TIME. */ 107#define ERA_NAME_FORMAT_MEMBERS 4 108#define ERA_M_NAME 0 109#define ERA_M_FORMAT 1 110#define ERA_W_NAME 2 111#define ERA_W_FORMAT 3 112 113 114/* Structure to access `era' information from LC_TIME. */ 115struct era_entry 116{ 117 uint32_t direction; /* Contains '+' or '-'. */ 118 int32_t offset; 119 int32_t start_date[3]; 120 int32_t stop_date[3]; 121 const char *era_name; 122 const char *era_format; 123 const wchar_t *era_wname; 124 const wchar_t *era_wformat; 125 int absolute_direction; 126 /* absolute direction: 127 +1 indicates that year number is higher in the future. (like A.D.) 128 -1 indicates that year number is higher in the past. (like B.C.) */ 129}; 130 131 132/* LC_CTYPE specific: 133 Hardwired indices for standard wide character translation mappings. */ 134enum 135{ 136 __TOW_toupper = 0, 137 __TOW_tolower = 1 138}; 139 140 141/* LC_CTYPE specific: 142 Access a wide character class with a single character index. 143 _ISCTYPE (c, desc) = iswctype (btowc (c), desc). 144 c must be an `unsigned char'. desc must be a nonzero wctype_t. */ 145#define _ISCTYPE(c, desc) \ 146 (((((const uint32_t *) (desc)) - 8)[(c) >> 5] >> ((c) & 0x1f)) & 1) 147 148 149extern const char *const _nl_category_names[__LC_LAST]; 150extern const size_t _nl_category_name_sizes[__LC_LAST]; 151extern struct locale_data * *const _nl_current[__LC_LAST]; 152 153/* Name of the standard locales. */ 154extern const char _nl_C_name[]; 155extern const char _nl_POSIX_name[]; 156 157/* The standard codeset. */ 158extern const char _nl_C_codeset[]; 159 160/* This is the internal locale_t object that holds the global locale 161 controlled by calls to setlocale. A thread's TSD locale pointer 162 points to this when `uselocale (LC_GLOBAL_LOCALE)' is in effect. */ 163extern struct __locale_struct _nl_global_locale; 164 165extern struct __locale_struct* _nl_current_locale(); 166#define _NL_CURRENT_LOCALE (_nl_current_locale()) 167 168/* Return a pointer to the current `struct __locale_data' for CATEGORY. */ 169#define _NL_CURRENT_DATA(category) \ 170 (_NL_CURRENT_LOCALE->__locales[category]) 171 172/* Extract the current CATEGORY locale's string for ITEM. */ 173#define _NL_CURRENT(category, item) \ 174 (_NL_CURRENT_DATA (category)->values[_NL_ITEM_INDEX (item)].string) 175 176/* Extract the current CATEGORY locale's string for ITEM. */ 177#define _NL_CURRENT_WSTR(category, item) \ 178 ((wchar_t *) _NL_CURRENT_DATA (category)->values[_NL_ITEM_INDEX (item)].wstr) 179 180/* Extract the current CATEGORY locale's word for ITEM. */ 181#define _NL_CURRENT_WORD(category, item) \ 182 ((uint32_t) _NL_CURRENT_DATA (category)->values[_NL_ITEM_INDEX (item)].word) 183 184/* This is used in lc-CATEGORY.c to define _nl_current_CATEGORY. */ 185#define _NL_CURRENT_DEFINE(category) \ 186 /* No per-category variable here. */ 187 188/* Load the locale data for CATEGORY from the file specified by *NAME. 189 If *NAME is "", use environment variables as specified by POSIX, 190 and fill in *NAME with the actual name used. The directories 191 listed in LOCALE_PATH are searched for the locale files. */ 192extern struct locale_data *_nl_find_locale (const char *locale_path, 193 size_t locale_path_len, 194 int category, const char **name); 195 196/* Try to load the file described by FILE. */ 197extern void _nl_load_locale (struct loaded_l10nfile *file, int category); 198 199/* Free all resource. */ 200extern void _nl_unload_locale (struct locale_data *locale); 201 202/* Free the locale and give back all memory if the usage count is one. */ 203extern void _nl_remove_locale (int locale, struct locale_data *data); 204 205 206/* Return `era' entry which corresponds to TP. Used in strftime. */ 207extern struct era_entry *_nl_get_era_entry (const struct tm *tp); 208 209/* Return `era' cnt'th entry . Used in strptime. */ 210extern struct era_entry *_nl_select_era_entry (int cnt); 211 212/* Return `alt_digit' which corresponds to NUMBER. Used in strftime. */ 213extern const char *_nl_get_alt_digit (unsigned int number); 214 215/* Similar, but now for wide characters. */ 216extern const wchar_t *_nl_get_walt_digit (unsigned int number); 217 218/* Parse string as alternative digit and return numeric value. */ 219extern int _nl_parse_alt_digit (const char **strp); 220 221/* Postload processing. */ 222extern void _nl_postload_ctype (void); 223extern void _nl_postload_time (void); 224 225 226#endif /* localeinfo.h */ 227