| /* Declarations for internal libc locale interfaces |
| Copyright (C) 1995-2014 Free Software Foundation, Inc. |
| This file is part of the GNU C Library. |
| |
| The GNU C Library is free software; you can redistribute it and/or |
| modify it under the terms of the GNU Lesser General Public |
| License as published by the Free Software Foundation; either |
| version 2.1 of the License, or (at your option) any later version. |
| |
| The GNU C Library is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| Lesser General Public License for more details. |
| |
| You should have received a copy of the GNU Lesser General Public |
| License along with the GNU C Library; if not, see |
| <http://www.gnu.org/licenses/>. */ |
| |
| #ifndef THIRD_PARTY_GLIBC_LOCALES_COMMON_LOCALEINFO_H |
| #define THIRD_PARTY_GLIBC_LOCALES_COMMON_LOCALEINFO_H |
| |
| #define __need_NULL |
| #include <limits.h> |
| #include <stddef.h> |
| #include <stdint.h> |
| #include <sys/types.h> |
| #include <time.h> |
| |
| #include "third_party/glibc_locales/glibc_locales.h" |
| |
| /* Definition of category symbol values, from glibc's bits/locale.h. */ |
| #define GOOGLE_LC_CTYPE 0 |
| #define GOOGLE_LC_COLLATE 1 |
| #define GOOGLE_LC_LAST 2 |
| |
| /* Structure for storing locales, from glibc's locale/xlocale.h. */ |
| struct google_locale_struct { |
| /* Per-category data for this locale. */ |
| struct google_locale_data *category_data[GOOGLE_LC_LAST]; |
| |
| /* To increase the speed of this solution we add some special members. */ |
| const unsigned short int *ctype_b; |
| const int *ctype_tolower; |
| const int *ctype_toupper; |
| |
| /* A pointer to an accompanying glibc locale, if we have one. We store |
| this as an opaque pointer to avoid needing to pull locale.h into |
| everything that uses this header. */ |
| void *glibc_locale; |
| }; |
| |
| /* Magic number at the beginning of a locale data file for CATEGORY. */ |
| #define LIMAGIC(category) \ |
| (category == LC_COLLATE ? ((unsigned int)(0x20051014 ^ (category))) \ |
| : category == LC_CTYPE ? ((unsigned int)(0x20090720 ^ (category))) \ |
| : ((unsigned int)(0x20031115 ^ (category)))) |
| |
| /* Two special weight constants for the collation data. */ |
| #define IGNORE_CHAR 2 |
| |
| /* Structure describing locale data in core for a category. */ |
| struct google_locale_data { |
| char *name; /* The locale name that this struct represents. */ |
| unsigned int nstrings; /* Number of values below. */ |
| union locale_data_value { |
| const uint32_t *wstr; |
| const char *string; |
| unsigned int word; /* Note endian issues vs 64-bit pointers. */ |
| } values[]; /* Items, usually pointers into `filedata'. */ |
| }; |
| |
| /* This alignment is used for 32-bit integers in locale files, both |
| those that are explicitly int32_t or uint32_t and those that are |
| wchar_t, regardless of the (possibly smaller) alignment required |
| for such integers on a particular host. */ |
| #define LOCFILE_ALIGN sizeof(int32_t) |
| #define LOCFILE_ALIGN_MASK (LOCFILE_ALIGN - 1) |
| #define LOCFILE_ALIGN_UP(x) (((x) + LOCFILE_ALIGN - 1) & ~LOCFILE_ALIGN_MASK) |
| #define LOCFILE_ALIGNED_P(x) (((x) & LOCFILE_ALIGN_MASK) == 0) |
| |
| /* We know three kinds of collation sorting rules. */ |
| enum coll_sort_rule { |
| illegal_0__, |
| sort_forward, |
| sort_backward, |
| illegal_3__, |
| sort_position, |
| sort_forward_position, |
| sort_backward_position, |
| sort_mask |
| }; |
| |
| /* We can map the types of the entries into a few categories. */ |
| enum value_type { |
| none, |
| string, |
| stringarray, |
| byte, |
| bytearray, |
| word, |
| stringlist, |
| wordarray, |
| wstring, |
| wstringarray, |
| wstringlist |
| }; |
| |
| /* LC_CTYPE specific: |
| Hardwired indices for standard wide character translation mappings. */ |
| enum { GOOGLE_TOW_toupper = 0, GOOGLE_TOW_tolower = 1 }; |
| |
| /* LC_CTYPE specific: |
| Access a wide character class with a single character index. |
| _ISCTYPE (c, desc) = iswctype (btowc (c), desc). |
| c must be an `unsigned char'. desc must be a nonzero wctype_t. */ |
| #define _ISCTYPE(c, desc) \ |
| (((((const uint32_t *)(desc)) - 8)[(c) >> 5] >> ((c) & 0x1f)) & 1) |
| |
| /* In-archive data structure containing all information for a locale. */ |
| struct locrecent { |
| uint32_t refs; /* # of namehashent records that point here */ |
| struct { |
| uint32_t offset; |
| uint32_t len; |
| } record[GOOGLE_LC_LAST]; |
| }; |
| |
| /* Locate the archived locale data for a given name. Returns NULL |
| if the data cannot be found. */ |
| struct locrecent *google_find_locale_data(const char *archive_data, |
| const char *name); |
| |
| /* Validate the contents of a locale file and set up the in-core |
| data structure to point into the data. */ |
| extern struct google_locale_data *google_load_locale_data(const char *name, |
| int category, |
| const void *data, |
| size_t datasize); |
| |
| /* Add the codeset into a locale name, if it does not already contain one, |
| to ensure that glibc loads the same locale that we do. */ |
| char *google_add_codeset_to_locale_name(const char *archive_data, |
| const char *name); |
| |
| #endif /* THIRD_PARTY_GLIBC_LOCALES_SRC_LOCALE_LOCALEINFO_H */ |