示例#1
0
static size_t
cname_lookup (wint_t wc, const struct locale_data* loc)
{
#ifdef _STLP_GLIBC_LOCALE_2
  printf( "******** Fix me: %s:%d", __FILE__, __LINE__ );
  return ~((size_t) 0);
#else
  unsigned int *__nl_ctype_names;
  unsigned int hash_size, hash_layers;
  size_t result, cnt;

# if BYTE_ORDER == BIG_ENDIAN
  __nl_ctype_names = (unsigned int*)loc->values[_NL_ITEM_INDEX(_NL_CTYPE_NAMES_EB)].string;
# elif BYTE_ORDER == LITTLE_ENDIAN
  __nl_ctype_names = (unsigned int*)loc->values[_NL_ITEM_INDEX(_NL_CTYPE_NAMES_EL)].string;
# else
#  error bizarre byte order
# endif

  hash_size = loc->values[_NL_ITEM_INDEX(_NL_CTYPE_HASH_SIZE)].word;
  hash_layers = loc->values[_NL_ITEM_INDEX(_NL_CTYPE_HASH_LAYERS)].word;

  result = wc % hash_size;
  for (cnt = 0; cnt < hash_layers; ++cnt) {
    if (__nl_ctype_names[result] == wc)
      break;
    result += hash_size;
  }
  return cnt < hash_layers ? result : ~((size_t) 0);
#endif
}
struct _Locale_ctype* _Locale_ctype_create(const char * name) {
  const union locale_data_value *ctypes;
  L_ctype_t* lctype;

  lctype = (L_ctype_t*)malloc(sizeof(L_ctype_t));
  lctype->gcc_data = _Category_create(name, LC_CTYPE);
  ctypes = lctype->gcc_data->values;

  lctype->__class = (_Locale_mask_t *)
    (ctypes[_NL_ITEM_INDEX (_NL_CTYPE_CLASS)] .string) + 128;
#if BYTE_ORDER == BIG_ENDIAN
  lctype->__tolower = (const int *)
    (ctypes[_NL_ITEM_INDEX (_NL_CTYPE_TOLOWER_EB)].string) + 128;
  lctype->__toupper = (const int *)
    (ctypes[_NL_ITEM_INDEX (_NL_CTYPE_TOUPPER_EB)].string) + 128;
#elif BYTE_ORDER == LITTLE_ENDIAN
  lctype->__tolower = (const int *)
    (ctypes[_NL_ITEM_INDEX (_NL_CTYPE_TOLOWER_EL)].string) + 128;
  lctype->__toupper = (const int *)
    (ctypes[_NL_ITEM_INDEX (_NL_CTYPE_TOUPPER_EL)].string) + 128;
#else
#error bizarre byte order
#endif
  return lctype;
}
示例#3
0
wint_t
(__towupper_l) (wint_t wc, __locale_t locale)
{
  size_t i = locale->__locales[LC_CTYPE]->values[_NL_ITEM_INDEX (_NL_CTYPE_MAP_OFFSET)].word + __TOW_toupper;
  const char *desc = locale->__locales[LC_CTYPE]->values[i].string;
  return wctrans_table_lookup (desc, wc);
}
示例#4
0
void
_nl_postload_ctype (void)
{
#define current(type,x,offset) \
  ((const type *) _NL_CURRENT (LC_CTYPE, _NL_CTYPE_##x) + offset)

  const union locale_data_value *const ctypes
    = _nl_global_locale.__locales[LC_CTYPE]->values;

/* These thread-local variables are defined in ctype-info.c.
   The declarations here must match those in localeinfo.h.

   These point into arrays of 384, so they can be indexed by any `unsigned
   char' value [0,255]; by EOF (-1); or by any `signed char' value
   [-128,-1).  ISO C requires that the ctype functions work for `unsigned
   char' values and for EOF; we also support negative `signed char' values
   for broken old programs.  The case conversion arrays are of `int's
   rather than `unsigned char's because tolower (EOF) must be EOF, which
   doesn't fit into an `unsigned char'.  But today more important is that
   the arrays are also used for multi-byte character sets.

   First we update the special members of _nl_global_locale as newlocale
   would.  This is necessary for uselocale (LC_GLOBAL_LOCALE) to find these
   values properly.  */

  _nl_global_locale.__ctype_b = (const unsigned short int *)
    ctypes[_NL_ITEM_INDEX (_NL_CTYPE_CLASS)].string + 128;
  _nl_global_locale.__ctype_tolower = (const int *)
    ctypes[_NL_ITEM_INDEX (_NL_CTYPE_TOLOWER)].string + 128;
  _nl_global_locale.__ctype_toupper = (const int *)
    ctypes[_NL_ITEM_INDEX (_NL_CTYPE_TOUPPER)].string + 128;

  /* Next we must set the thread-local caches if and only if this thread is
     in fact using the global locale.  */
  if (_NL_CURRENT_LOCALE == &_nl_global_locale)
    {
      __libc_tsd_set (const uint16_t *, CTYPE_B,
		      (void *) _nl_global_locale.__ctype_b);
      __libc_tsd_set (const int32_t *, CTYPE_TOUPPER,
		      (void *) _nl_global_locale.__ctype_toupper);
      __libc_tsd_set (const int32_t *, CTYPE_TOLOWER,
		      (void *) _nl_global_locale.__ctype_tolower);
    }
_Locale_mask_t _Locale_wchar_ctype(struct _Locale_ctype* loc, wint_t wc) {
  const struct locale_data* locale = loc->gcc_data;
  const unsigned int *class32_b;
  size_t idx;

  idx = cname_lookup (wc, locale);
  if (idx == ~((size_t) 0))
    return 0;

  class32_b = (u_int32_t *)
    locale->values[_NL_ITEM_INDEX (_NL_CTYPE_CLASS32)].string;

  return _Map_wchar_mask_to_char_mask( class32_b[idx] );
}
wctype_t
__wctype_l (const char *property, __locale_t locale)
{
  const char *names;
  unsigned int result;
  size_t proplen = strlen (property);
  size_t i;

  names = locale->__locales[LC_CTYPE]->values[_NL_ITEM_INDEX (_NL_CTYPE_CLASS_NAMES)].string;
  for (result = 0; ; result++)
    {
      size_t nameslen = strlen (names);

      if (proplen == nameslen && memcmp (property, names, proplen) == 0)
	break;

      names += nameslen + 1;
      if (names[0] == '\0')
	return 0;
    }

  i = locale->__locales[LC_CTYPE]->values[_NL_ITEM_INDEX (_NL_CTYPE_CLASS_OFFSET)].word + result;
  return (wctype_t) locale->__locales[LC_CTYPE]->values[i].string;
}
示例#7
0
wctrans_t
__wctrans_l (const char *property, __locale_t locale)
{
  const char *names;
  size_t cnt;
  size_t i;

  names = locale->__locales[LC_CTYPE]->values[_NL_ITEM_INDEX (_NL_CTYPE_MAP_NAMES)].string;
  cnt = 0;
  while (names[0] != '\0')
    {
      if (strcmp (property, names) == 0)
	break;

      names = strchr (names, '\0') + 1;
      ++cnt;
    }

  if (names[0] == '\0')
    return 0;

  i = locale->__locales[LC_CTYPE]->values[_NL_ITEM_INDEX (_NL_CTYPE_MAP_OFFSET)].word + cnt;
  return (wctrans_t) locale->__locales[LC_CTYPE]->values[i].string;
}
示例#8
0
static char *get_language(void *mapped, size_t size) {
  char *str = NULL;

  /* Read the information from the file.  */
  struct {
    unsigned int magic;
    unsigned int nstrings;
    unsigned int strindex[0];
  } *filedata = mapped;

  if (filedata->magic == LIMAGIC(LC_IDENTIFICATION)
          && (sizeof *filedata
          + (filedata->nstrings
          * sizeof (unsigned int))
          <= size))
    str = ((char *) mapped
          + filedata->strindex[_NL_ITEM_INDEX(_NL_IDENTIFICATION_LANGUAGE)]);
  return str;
}
示例#9
0
const char* _Locale_t_fmt_ampm(struct _Locale_time* ltime)
{
  return ltime->gcc_data->values[_NL_ITEM_INDEX(T_FMT_AMPM)].string;
}
示例#10
0
const char* _Locale_pm_str(struct _Locale_time* ltime) {
  return ltime->gcc_data->values[_NL_ITEM_INDEX(PM_STR)].string;
}
示例#11
0
const char* _Locale_long_d_fmt(struct _Locale_time* ltime)
{
  return ltime->gcc_data->values[_NL_ITEM_INDEX(D_FMT)].string;
}
示例#12
0
const char * _Locale_abbrev_dayofweek(struct _Locale_time *ltime, int day) {
  const char **names = (const char **)&(ltime->gcc_data->values[_NL_ITEM_INDEX(ABDAY_1)]);
  return names[day];
}
示例#13
0
const char* _Locale_int_curr_symbol(struct _Locale_monetary* lmon) {
  return lmon->gcc_data->values[_NL_ITEM_INDEX(INT_CURR_SYMBOL)].string;
}
示例#14
0
    internal_function
_nl_find_locale (const char *locale_path, size_t locale_path_len,
                 int category, const char **name)
{
    int mask;
    /* Name of the locale for this category.  */
    char *loc_name;
    const char *language;
    const char *modifier;
    const char *territory;
    const char *codeset;
    const char *normalized_codeset;
    struct loaded_l10nfile *locale_file;

    if ((*name)[0] == '\0')
    {
        /* The user decides which locale to use by setting environment
        variables.  */
        *name = getenv ("LC_ALL");
        if (*name == NULL || (*name)[0] == '\0')
            *name = getenv (_nl_category_names.str
                            + _nl_category_name_idxs[category]);
        if (*name == NULL || (*name)[0] == '\0')
            *name = getenv ("LANG");
    }

    if (*name == NULL || (*name)[0] == '\0'
            || (__builtin_expect (__libc_enable_secure, 0)
                && strchr (*name, '/') != NULL))
        *name = (char *) _nl_C_name;

    if (__builtin_expect (strcmp (*name, _nl_C_name), 1) == 0
            || __builtin_expect (strcmp (*name, _nl_POSIX_name), 1) == 0)
    {
        /* We need not load anything.  The needed data is contained in
        the library itself.  */
        *name = (char *) _nl_C_name;
        return _nl_C[category];
    }

    /* We really have to load some data.  First we try the archive,
       but only if there was no LOCPATH environment variable specified.  */
    if (__builtin_expect (locale_path == NULL, 1))
    {
        struct __locale_data *data
            = _nl_load_locale_from_archive (category, name);
        if (__builtin_expect (data != NULL, 1))
            return data;

        /* Nothing in the archive.  Set the default path to search below.  */
        locale_path = _nl_default_locale_path;
        locale_path_len = sizeof _nl_default_locale_path;
    }

    /* We really have to load some data.  First see whether the name is
       an alias.  Please note that this makes it impossible to have "C"
       or "POSIX" as aliases.  */
    loc_name = (char *) _nl_expand_alias (*name);
    if (loc_name == NULL)
        /* It is no alias.  */
        loc_name = (char *) *name;

    /* Make a writable copy of the locale name.  */
    loc_name = strdupa (loc_name);

    /* LOCALE can consist of up to four recognized parts for the XPG syntax:

    	language[_territory[.codeset]][@modifier]

       Beside the first all of them are allowed to be missing.  If the
       full specified locale is not found, the less specific one are
       looked for.  The various part will be stripped off according to
       the following order:
    	(1) codeset
    	(2) normalized codeset
    	(3) territory
    	(4) modifier
     */
    mask = _nl_explode_name (loc_name, &language, &modifier, &territory,
                             &codeset, &normalized_codeset);
    if (mask == -1)
        /* Memory allocate problem.  */
        return NULL;

    /* If exactly this locale was already asked for we have an entry with
       the complete name.  */
    locale_file = _nl_make_l10nflist (&_nl_locale_file_list[category],
                                      locale_path, locale_path_len, mask,
                                      language, territory, codeset,
                                      normalized_codeset, modifier,
                                      _nl_category_names.str
                                      + _nl_category_name_idxs[category], 0);

    if (locale_file == NULL)
    {
        /* Find status record for addressed locale file.  We have to search
        through all directories in the locale path.  */
        locale_file = _nl_make_l10nflist (&_nl_locale_file_list[category],
                                          locale_path, locale_path_len, mask,
                                          language, territory, codeset,
                                          normalized_codeset, modifier,
                                          _nl_category_names.str
                                          + _nl_category_name_idxs[category], 1);
        if (locale_file == NULL)
            /* This means we are out of core.  */
            return NULL;
    }

    /* The space for normalized_codeset is dynamically allocated.  Free it.  */
    if (mask & XPG_NORM_CODESET)
        free ((void *) normalized_codeset);

    if (locale_file->decided == 0)
        _nl_load_locale (locale_file, category);

    if (locale_file->data == NULL)
    {
        int cnt;
        for (cnt = 0; locale_file->successor[cnt] != NULL; ++cnt)
        {
            if (locale_file->successor[cnt]->decided == 0)
                _nl_load_locale (locale_file->successor[cnt], category);
            if (locale_file->successor[cnt]->data != NULL)
                break;
        }
        /* Move the entry we found (or NULL) to the first place of
        successors.  */
        locale_file->successor[0] = locale_file->successor[cnt];
        locale_file = locale_file->successor[cnt];

        if (locale_file == NULL)
            return NULL;
    }

    /* The LC_CTYPE category allows to check whether a locale is really
       usable.  If the locale name contains a charset name and the
       charset name used in the locale (present in the LC_CTYPE data) is
       not the same (after resolving aliases etc) we reject the locale
       since using it would irritate users expecting the charset named
       in the locale name.  */
    if (codeset != NULL)
    {
        /* Get the codeset information from the locale file.  */
        static const int codeset_idx[] =
        {
            [__LC_CTYPE] = _NL_ITEM_INDEX (CODESET),
            [__LC_NUMERIC] = _NL_ITEM_INDEX (_NL_NUMERIC_CODESET),
            [__LC_TIME] = _NL_ITEM_INDEX (_NL_TIME_CODESET),
            [__LC_COLLATE] = _NL_ITEM_INDEX (_NL_COLLATE_CODESET),
            [__LC_MONETARY] = _NL_ITEM_INDEX (_NL_MONETARY_CODESET),
            [__LC_MESSAGES] = _NL_ITEM_INDEX (_NL_MESSAGES_CODESET),
            [__LC_PAPER] = _NL_ITEM_INDEX (_NL_PAPER_CODESET),
            [__LC_NAME] = _NL_ITEM_INDEX (_NL_NAME_CODESET),
            [__LC_ADDRESS] = _NL_ITEM_INDEX (_NL_ADDRESS_CODESET),
            [__LC_TELEPHONE] = _NL_ITEM_INDEX (_NL_TELEPHONE_CODESET),
            [__LC_MEASUREMENT] = _NL_ITEM_INDEX (_NL_MEASUREMENT_CODESET),
            [__LC_IDENTIFICATION] = _NL_ITEM_INDEX (_NL_IDENTIFICATION_CODESET)
        };
        const struct __locale_data *data;
        const char *locale_codeset;
        char *clocale_codeset;
        char *ccodeset;

        data = (const struct __locale_data *) locale_file->data;
        locale_codeset =
            (const char *) data->values[codeset_idx[category]].string;
        assert (locale_codeset != NULL);
        /* Note the length of the allocated memory: +3 for up to two slashes
        and the NUL byte.  */
        clocale_codeset = (char *) alloca (strlen (locale_codeset) + 3);
        strip (clocale_codeset, locale_codeset);

        ccodeset = (char *) alloca (strlen (codeset) + 3);
        strip (ccodeset, codeset);

        if (__gconv_compare_alias (upstr (ccodeset, ccodeset),
                                   upstr (clocale_codeset,
                                          clocale_codeset)) != 0)
            /* The codesets are not identical, don't use the locale.  */
            return NULL;
    }
示例#15
0
int
STRCOLL (const STRING_TYPE *s1, const STRING_TYPE *s2, locale_t l)
{
  struct __locale_data *current = l->__locales[LC_COLLATE];
  uint_fast32_t nrules = current->values[_NL_ITEM_INDEX (_NL_COLLATE_NRULES)].word;
  /* We don't assign the following values right away since it might be
     unnecessary in case there are no rules.  */
  const unsigned char *rulesets;
  const int32_t *table;
  const USTRING_TYPE *weights;
  const USTRING_TYPE *extra;
  const int32_t *indirect;

  if (nrules == 0)
    return STRCMP (s1, s2);

  /* Catch empty strings.  */
  if (__glibc_unlikely (*s1 == '\0') || __glibc_unlikely (*s2 == '\0'))
    return (*s1 != '\0') - (*s2 != '\0');

  rulesets = (const unsigned char *)
    current->values[_NL_ITEM_INDEX (_NL_COLLATE_RULESETS)].string;
  table = (const int32_t *)
    current->values[_NL_ITEM_INDEX (CONCAT(_NL_COLLATE_TABLE,SUFFIX))].string;
  weights = (const USTRING_TYPE *)
    current->values[_NL_ITEM_INDEX (CONCAT(_NL_COLLATE_WEIGHT,SUFFIX))].string;
  extra = (const USTRING_TYPE *)
    current->values[_NL_ITEM_INDEX (CONCAT(_NL_COLLATE_EXTRA,SUFFIX))].string;
  indirect = (const int32_t *)
    current->values[_NL_ITEM_INDEX (CONCAT(_NL_COLLATE_INDIRECT,SUFFIX))].string;

  assert (((uintptr_t) table) % __alignof__ (table[0]) == 0);
  assert (((uintptr_t) weights) % __alignof__ (weights[0]) == 0);
  assert (((uintptr_t) extra) % __alignof__ (extra[0]) == 0);
  assert (((uintptr_t) indirect) % __alignof__ (indirect[0]) == 0);

  int result = 0, rule = 0;

  coll_seq seq1, seq2;
  seq1.len = 0;
  seq1.idxmax = 0;
  seq1.rule = 0;
  seq2.len = 0;
  seq2.idxmax = 0;

  for (int pass = 0; pass < nrules; ++pass)
    {
      seq1.idxcnt = 0;
      seq1.idx = 0;
      seq2.idx = 0;
      seq1.backw_stop = ~0ul;
      seq1.backw = ~0ul;
      seq2.idxcnt = 0;
      seq2.backw_stop = ~0ul;
      seq2.backw = ~0ul;

      /* We need the elements of the strings as unsigned values since they
	 are used as indices.  */
      seq1.us = (const USTRING_TYPE *) s1;
      seq2.us = (const USTRING_TYPE *) s2;

      /* We assume that if a rule has defined `position' in one section
	 this is true for all of them.  Please note that the localedef programs
	 makes sure that `position' is not used at the first level.  */

      int position = rulesets[rule * nrules + pass] & sort_position;

      while (1)
	{
	  get_next_seq (&seq1, nrules, rulesets, weights, table,
				    extra, indirect, pass);
	  get_next_seq (&seq2, nrules, rulesets, weights, table,
				    extra, indirect, pass);
	  /* See whether any or both strings are empty.  */
	  if (seq1.len == 0 || seq2.len == 0)
	    {
	      if (seq1.len == seq2.len)
		{
		  /* Both strings ended and are equal at this level.  Do a
		     byte-level comparison to ensure that we don't waste time
		     going through multiple passes for totally equal strings
		     before proceeding to subsequent passes.  */
		  if (pass == 0 && STRCMP (s1, s2) == 0)
		    return result;
		  else
		    break;
	        }

	      /* This means one string is shorter than the other.  Find out
		 which one and return an appropriate value.  */
	      return seq1.len == 0 ? -1 : 1;
	    }

	  result = do_compare (&seq1, &seq2, position, weights);
	  if (result != 0)
	    return result;
	}

      rule = seq1.rule;
    }

  return result;
}
示例#16
0
char        _Locale_frac_digits(struct _Locale_monetary* lmon) {
  return lmon->gcc_data->values[_NL_ITEM_INDEX(FRAC_DIGITS)].string[0];
}
示例#17
0
const char* _Locale_negative_sign(struct _Locale_monetary* lmon) {
  return lmon->gcc_data->values[_NL_ITEM_INDEX(NEGATIVE_SIGN)].string;
}
示例#18
0
const char* _Locale_mon_grouping(struct _Locale_monetary* lmon) {
  return lmon->gcc_data->values[_NL_ITEM_INDEX(MON_GROUPING)].string;
}
示例#19
0
char        _Locale_mon_thousands_sep(struct _Locale_monetary* lmon) {
  return lmon->gcc_data->values[_NL_ITEM_INDEX(MON_THOUSANDS_SEP)].string[0];
}
示例#20
0
char        _Locale_mon_decimal_point(struct _Locale_monetary* lmon) {
  return lmon->gcc_data->values[_NL_ITEM_INDEX(MON_DECIMAL_POINT)].string[0];
}
示例#21
0
const char* _Locale_currency_symbol(struct _Locale_monetary* lmon) {
  return lmon->gcc_data->values[_NL_ITEM_INDEX(CURRENCY_SYMBOL)].string;
}
示例#22
0
char _Locale_decimal_point(struct _Locale_numeric* lnum)
{
  return lnum->gcc_data->values[_NL_ITEM_INDEX(DECIMAL_POINT)].string[0];
}
示例#23
0
int _Locale_mb_cur_max (struct _Locale_ctype *lctype) {
  return lctype->gcc_data->values[_NL_ITEM_INDEX(_NL_CTYPE_MB_CUR_MAX)].word;
}
示例#24
0
char _Locale_thousands_sep(struct _Locale_numeric* lnum)
{
  return lnum->gcc_data->values[_NL_ITEM_INDEX(THOUSANDS_SEP)].string[0];
}
示例#25
0
int          _Locale_n_sign_posn(struct _Locale_monetary* lmon) {
  return lmon->gcc_data->values[_NL_ITEM_INDEX(N_SIGN_POSN)].word;
}
示例#26
0
const char * _Locale_abbrev_monthname(struct _Locale_time *ltime, int month) {
  const char **names = (const char **)&(ltime->gcc_data->values[_NL_ITEM_INDEX(ABMON_1)]);
  return names[month];
}
示例#27
0
int         _Locale_n_cs_precedes(struct _Locale_monetary* lmon) {
  return lmon->gcc_data->values[_NL_ITEM_INDEX(N_CS_PRECEDES)].word;
}
示例#28
0
const char* _Locale_grouping(struct _Locale_numeric * lnum)
{
  return lnum->gcc_data->values[_NL_ITEM_INDEX(GROUPING)].string;
}
示例#29
0
__locale_t
__newlocale (int category_mask, const char *locale, __locale_t base)
{
  /* Intermediate memory for result.  */
  const char *newnames[__LC_LAST];
  struct __locale_struct result;
  __locale_t result_ptr;
  char *locale_path;
  size_t locale_path_len;
  const char *locpath_var;
  int cnt;
  size_t names_len;

  /* We treat LC_ALL in the same way as if all bits were set.  */
  if (category_mask == 1 << LC_ALL)
    category_mask = (1 << __LC_LAST) - 1 - (1 << LC_ALL);

  /* Sanity check for CATEGORY argument.  */
  if ((category_mask & ~((1 << __LC_LAST) - 1 - (1 << LC_ALL))) != 0)
    ERROR_RETURN;

  /* `newlocale' does not support asking for the locale name. */
  if (locale == NULL)
    ERROR_RETURN;

  if (base == _nl_C_locobj_ptr)
    /* We're to modify BASE, returned for a previous call with "C".
       We can't really modify the read-only structure, so instead
       start over by copying it.  */
    base = NULL;

  if ((base == NULL || category_mask == (1 << __LC_LAST) - 1 - (1 << LC_ALL))
      && (category_mask == 0 || !strcmp (locale, "C")))
    /* Asking for the "C" locale needn't allocate a new object.  */
    return _nl_C_locobj_ptr;

  /* Allocate memory for the result.  */
  if (base != NULL)
    result = *base;
  else
    /* Fill with pointers to C locale data.  */
    result = _nl_C_locobj;

  /* If no category is to be set we return BASE if available or a
     dataset using the C locale data.  */
  if (category_mask == 0)
    {
      result_ptr = (__locale_t) malloc (sizeof (struct __locale_struct));
      if (result_ptr == NULL)
	return NULL;
      *result_ptr = result;

      goto update;
    }

  /* We perhaps really have to load some data.  So we determine the
     path in which to look for the data now.  The environment variable
     `LOCPATH' must only be used when the binary has no SUID or SGID
     bit set.  If using the default path, we tell _nl_find_locale
     by passing null and it can check the canonical locale archive.  */
  locale_path = NULL;
  locale_path_len = 0;

  locpath_var = getenv ("LOCPATH");
  if (locpath_var != NULL && locpath_var[0] != '\0')
    {
      if (__argz_create_sep (locpath_var, ':',
			     &locale_path, &locale_path_len) != 0)
	return NULL;

      if (__argz_add_sep (&locale_path, &locale_path_len,
			  _nl_default_locale_path, ':') != 0)
	return NULL;
    }

  /* Get the names for the locales we are interested in.  We either
     allow a composite name or a single name.  */
  for (cnt = 0; cnt < __LC_LAST; ++cnt)
    if (cnt != LC_ALL)
      newnames[cnt] = locale;
  if (strchr (locale, ';') != NULL)
    {
      /* This is a composite name.  Make a copy and split it up.  */
      char *np = strdupa (locale);
      char *cp;
      int specified_mask = 0;

      while ((cp = strchr (np, '=')) != NULL)
	{
	  for (cnt = 0; cnt < __LC_LAST; ++cnt)
	    if (cnt != LC_ALL
		&& (size_t) (cp - np) == _nl_category_name_sizes[cnt]
		&& memcmp (np, (_nl_category_names.str
				+ _nl_category_name_idxs[cnt]), cp - np) == 0)
	      break;

	  if (cnt == __LC_LAST)
	    /* Bogus category name.  */
	    ERROR_RETURN;

	  /* Found the category this clause sets.  */
	  specified_mask |= 1 << cnt;
	  newnames[cnt] = ++cp;
	  cp = strchr (cp, ';');
	  if (cp != NULL)
	    {
	      /* Examine the next clause.  */
	      *cp = '\0';
	      np = cp + 1;
	    }
	  else
	    /* This was the last clause.  We are done.  */
	    break;
	}

      if (category_mask &~ specified_mask)
	/* The composite name did not specify all categories we need.  */
	ERROR_RETURN;
    }

  /* Protect global data.  */
  __libc_rwlock_wrlock (__libc_setlocale_lock);

  /* Now process all categories we are interested in.  */
  names_len = 0;
  for (cnt = 0; cnt < __LC_LAST; ++cnt)
    {
      if ((category_mask & 1 << cnt) != 0)
	{
	  result.__locales[cnt] = _nl_find_locale (locale_path,
						   locale_path_len,
						   cnt, &newnames[cnt]);
	  if (result.__locales[cnt] == NULL)
	    {
	    free_cnt_data_and_exit:
	      while (cnt-- > 0)
		if (((category_mask & 1 << cnt) != 0)
		    && result.__locales[cnt]->usage_count != UNDELETABLE)
		  /* We can remove the data.  */
		  _nl_remove_locale (cnt, result.__locales[cnt]);

              /* Critical section left.  */
              __libc_rwlock_unlock (__libc_setlocale_lock);
	      return NULL;
	    }

	  if (newnames[cnt] != _nl_C_name)
	    names_len += strlen (newnames[cnt]) + 1;
	}
      else if (cnt != LC_ALL && result.__names[cnt] != _nl_C_name)
	/* Tally up the unchanged names from BASE as well.  */
	names_len += strlen (result.__names[cnt]) + 1;
    }

  /* We successfully loaded all required data.  Allocate a new structure.
     We can't just reuse the BASE pointer, because the name strings are
     changing and we need the old name string area intact so we can copy
     out of it into the new one without overlap problems should some
     category's name be getting longer.  */
  result_ptr = malloc (sizeof (struct __locale_struct) + names_len);
  if (result_ptr == NULL)
    {
      cnt = __LC_LAST;
      goto free_cnt_data_and_exit;
    }

  if (base == NULL)
    {
      /* Fill in this new structure from scratch.  */

      char *namep = (char *) (result_ptr + 1);

      /* Install copied new names in the new structure's __names array.
	 If resolved to "C", that is already in RESULT.__names to start.  */
      for (cnt = 0; cnt < __LC_LAST; ++cnt)
	if ((category_mask & 1 << cnt) != 0 && newnames[cnt] != _nl_C_name)
	  {
	    result.__names[cnt] = namep;
	    namep = __stpcpy (namep, newnames[cnt]) + 1;
	  }

      *result_ptr = result;
    }
  else
    {
      /* We modify the base structure.  */

      char *namep = (char *) (result_ptr + 1);

      for (cnt = 0; cnt < __LC_LAST; ++cnt)
	if ((category_mask & 1 << cnt) != 0)
	  {
	    if (base->__locales[cnt]->usage_count != UNDELETABLE)
	      /* We can remove the old data.  */
	      _nl_remove_locale (cnt, base->__locales[cnt]);
	    result_ptr->__locales[cnt] = result.__locales[cnt];

	    if (newnames[cnt] == _nl_C_name)
	      result_ptr->__names[cnt] = _nl_C_name;
	    else
	      {
		result_ptr->__names[cnt] = namep;
		namep = __stpcpy (namep, newnames[cnt]) + 1;
	      }
	  }
	else if (cnt != LC_ALL)
	  {
	    /* The RESULT members point into the old BASE structure.  */
	    result_ptr->__locales[cnt] = result.__locales[cnt];
	    if (result.__names[cnt] == _nl_C_name)
	      result_ptr->__names[cnt] = _nl_C_name;
	    else
	      {
		result_ptr->__names[cnt] = namep;
		namep = __stpcpy (namep, result.__names[cnt]) + 1;
	      }
	  }

      free (base);
    }

  /* Critical section left.  */
  __libc_rwlock_unlock (__libc_setlocale_lock);

  /* Update the special members.  */
 update:
  {
    union locale_data_value *ctypes = result_ptr->__locales[LC_CTYPE]->values;
    result_ptr->__ctype_b = (const unsigned short int *)
      ctypes[_NL_ITEM_INDEX (_NL_CTYPE_CLASS)].string + 128;
    result_ptr->__ctype_tolower = (const int *)
      ctypes[_NL_ITEM_INDEX (_NL_CTYPE_TOLOWER)].string + 128;
    result_ptr->__ctype_toupper = (const int *)
      ctypes[_NL_ITEM_INDEX (_NL_CTYPE_TOUPPER)].string + 128;
  }

  return result_ptr;
}
示例#30
0
int          _Locale_n_sep_by_space(struct _Locale_monetary* lmon) {
  return lmon->gcc_data->values[_NL_ITEM_INDEX(N_SEP_BY_SPACE)].word;
}