Back to index

glibc  2.9
Defines | Functions
l10nflist.c File Reference
#include <string.h>
#include <ctype.h>
#include <sys/types.h>
#include <stdlib.h>
#include "loadinfo.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define _GNU_SOURCE   1
#define NULL   0
#define __argz_count(argz, len)   argz_count__ (argz, len)
#define __argz_stringify(argz, len, sep)   argz_stringify__ (argz, len, sep)
#define __argz_next(argz, len, entry)   argz_next__ (argz, len, entry)

Functions

static char *stpcpy PARAMS ((char *dest, const char *src))
static size_t argz_count__ PARAMS ((const char *argz, size_t len))
static size_t argz_count__ (char *argz, size_t len) const
static void argz_stringify__ PARAMS ((char *argz, size_t len, int sep))
static void argz_stringify__ (char *argz, size_t len, int sep)
static char *argz_next__ PARAMS ((char *argz, size_t argz_len, const char *entry))
static char * argz_next__ (char *argz, size_t argz_len, const char *entry)
static int pop PARAMS ((int x))
static int pop (int x)
struct loaded_l10nfile_nl_make_l10nflist (struct loaded_l10nfile **l10nfile_list, const char *dirlist, size_t dirlist_len, int mask, const char *language, const char *territory, const char *codeset, const char *normalized_codeset, const char *modifier, const char *filename, int do_allocate)
const char * _nl_normalize_codeset (char *codeset, size_t name_len) const
static char * stpcpy (char *dest, const char *src)

Define Documentation

#define __argz_count (   argz,
  len 
)    argz_count__ (argz, len)

Definition at line 88 of file l10nflist.c.

#define __argz_next (   argz,
  len,
  entry 
)    argz_next__ (argz, len, entry)

Definition at line 148 of file l10nflist.c.

#define __argz_stringify (   argz,
  len,
  sep 
)    argz_stringify__ (argz, len, sep)

Definition at line 116 of file l10nflist.c.

#define _GNU_SOURCE   1

Definition at line 24 of file l10nflist.c.

#define NULL   0

Definition at line 47 of file l10nflist.c.


Function Documentation

struct loaded_l10nfile* _nl_make_l10nflist ( struct loaded_l10nfile **  l10nfile_list,
const char *  dirlist,
size_t  dirlist_len,
int  mask,
const char *  language,
const char *  territory,
const char *  codeset,
const char *  normalized_codeset,
const char *  modifier,
const char *  filename,
int  do_allocate 
) [read]

Definition at line 170 of file l10nflist.c.

{
  char *abs_filename;
  struct loaded_l10nfile *last = NULL;
  struct loaded_l10nfile *retval;
  char *cp;
  size_t entries;
  int cnt;

  /* Allocate room for the full file name.  */
  abs_filename = (char *) malloc (dirlist_len
                              + strlen (language)
                              + ((mask & XPG_TERRITORY) != 0
                                 ? strlen (territory) + 1 : 0)
                              + ((mask & XPG_CODESET) != 0
                                 ? strlen (codeset) + 1 : 0)
                              + ((mask & XPG_NORM_CODESET) != 0
                                 ? strlen (normalized_codeset) + 1 : 0)
                              + ((mask & XPG_MODIFIER) != 0
                                 ? strlen (modifier) + 1 : 0)
                              + 1 + strlen (filename) + 1);

  if (abs_filename == NULL)
    return NULL;

  retval = NULL;
  last = NULL;

  /* Construct file name.  */
  memcpy (abs_filename, dirlist, dirlist_len);
  __argz_stringify (abs_filename, dirlist_len, ':');
  cp = abs_filename + (dirlist_len - 1);
  *cp++ = '/';
  cp = stpcpy (cp, language);

  if ((mask & XPG_TERRITORY) != 0)
    {
      *cp++ = '_';
      cp = stpcpy (cp, territory);
    }
  if ((mask & XPG_CODESET) != 0)
    {
      *cp++ = '.';
      cp = stpcpy (cp, codeset);
    }
  if ((mask & XPG_NORM_CODESET) != 0)
    {
      *cp++ = '.';
      cp = stpcpy (cp, normalized_codeset);
    }
  if ((mask & XPG_MODIFIER) != 0)
    {
      *cp++ = '@';
      cp = stpcpy (cp, modifier);
    }

  *cp++ = '/';
  stpcpy (cp, filename);

  /* Look in list of already loaded domains whether it is already
     available.  */
  last = NULL;
  for (retval = *l10nfile_list; retval != NULL; retval = retval->next)
    if (retval->filename != NULL)
      {
       int compare = strcmp (retval->filename, abs_filename);
       if (compare == 0)
         /* We found it!  */
         break;
       if (compare < 0)
         {
           /* It's not in the list.  */
           retval = NULL;
           break;
         }

       last = retval;
      }

  if (retval != NULL || do_allocate == 0)
    {
      free (abs_filename);
      return retval;
    }

  retval = (struct loaded_l10nfile *)
    malloc (sizeof (*retval) + (__argz_count (dirlist, dirlist_len)
                            * (1 << pop (mask))
                            * sizeof (struct loaded_l10nfile *)));
  if (retval == NULL)
    {
      free (abs_filename);
      return NULL;
    }

  retval->filename = abs_filename;
  /* If more than one directory is in the list this is a pseudo-entry
     which just references others.  We do not try to load data for it,
     ever.  */
  retval->decided = (__argz_count (dirlist, dirlist_len) != 1
                   || ((mask & XPG_CODESET) != 0
                      && (mask & XPG_NORM_CODESET) != 0));
  retval->data = NULL;

  if (last == NULL)
    {
      retval->next = *l10nfile_list;
      *l10nfile_list = retval;
    }
  else
    {
      retval->next = last->next;
      last->next = retval;
    }

  entries = 0;
  /* If the DIRLIST is a real list the RETVAL entry corresponds not to
     a real file.  So we have to use the DIRLIST separation mechanism
     of the inner loop.  */
  cnt = __argz_count (dirlist, dirlist_len) == 1 ? mask - 1 : mask;
  for (; cnt >= 0; --cnt)
    if ((cnt & ~mask) == 0)
      {
       /* Iterate over all elements of the DIRLIST.  */
       char *dir = NULL;

       while ((dir = __argz_next ((char *) dirlist, dirlist_len, dir))
              != NULL)
         retval->successor[entries++]
           = _nl_make_l10nflist (l10nfile_list, dir, strlen (dir) + 1, cnt,
                              language, territory, codeset,
                              normalized_codeset, modifier, filename, 1);
      }
  retval->successor[entries] = NULL;

  return retval;
}

Here is the call graph for this function:

Here is the caller graph for this function:

const char* _nl_normalize_codeset ( char *  codeset,
size_t  name_len 
) const

Definition at line 326 of file l10nflist.c.

{
  int len = 0;
  int only_digit = 1;
  char *retval;
  char *wp;
  size_t cnt;

  for (cnt = 0; cnt < name_len; ++cnt)
    if (isalnum ((unsigned char) codeset[cnt]))
      {
       ++len;

       if (isalpha ((unsigned char) codeset[cnt]))
         only_digit = 0;
      }

  retval = (char *) malloc ((only_digit ? 3 : 0) + len + 1);

  if (retval != NULL)
    {
      if (only_digit)
       wp = stpcpy (retval, "iso");
      else
       wp = retval;

      for (cnt = 0; cnt < name_len; ++cnt)
       if (isalpha ((unsigned char) codeset[cnt]))
         *wp++ = tolower ((unsigned char) codeset[cnt]);
       else if (isdigit ((unsigned char) codeset[cnt]))
         *wp++ = codeset[cnt];

      *wp = '\0';
    }

  return (const char *) retval;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static size_t argz_count__ ( char *  argz,
size_t  len 
) const [static]

Definition at line 73 of file l10nflist.c.

{
  size_t count = 0;
  while (len > 0)
    {
      size_t part_len = strlen (argz);
      argz += part_len + 1;
      len -= part_len + 1;
      count++;
    }
  return count;
}

Here is the call graph for this function:

static char* argz_next__ ( char *  argz,
size_t  argz_len,
const char *  entry 
) [static]

Definition at line 129 of file l10nflist.c.

{
  if (entry)
    {
      if (entry < argz + argz_len)
        entry = strchr (entry, '\0') + 1;

      return entry >= argz + argz_len ? NULL : (char *) entry;
    }
  else
    if (argz_len > 0)
      return argz;
    else
      return 0;
}
static void argz_stringify__ ( char *  argz,
size_t  len,
int  sep 
) [static]

Definition at line 101 of file l10nflist.c.

{
  while (len > 0)
    {
      size_t part_len = strlen (argz);
      argz += part_len;
      len -= part_len + 1;
      if (len > 0)
       *argz++ = sep;
    }
}

Here is the call graph for this function:

static char* stpcpy PARAMS ( (char *dest, const char *src ) [static]
static size_t argz_count__ PARAMS ( (const char *argz, size_t len ) [static]
static void argz_stringify__ PARAMS ( (char *argz, size_t len, int sep)  ) [static]
static char* argz_next__ PARAMS ( (char *argz, size_t argz_len, const char *entry ) [static]
static int pop PARAMS ( (int x ) [static]
static int pop ( int  x) [inline, static]

Definition at line 156 of file l10nflist.c.

{
  /* We assume that no more than 16 bits are used.  */
  x = ((x & ~0x5555) >> 1) + (x & 0x5555);
  x = ((x & ~0x3333) >> 2) + (x & 0x3333);
  x = ((x >> 4) + x) & 0x0f0f;
  x = ((x >> 8) + x) & 0xff;

  return x;
}

Here is the caller graph for this function:

static char* stpcpy ( char *  dest,
const char *  src 
) [static]

Definition at line 375 of file l10nflist.c.

{
  while ((*dest++ = *src++) != '\0')
    /* Do nothing. */ ;
  return dest - 1;
}

Here is the caller graph for this function: