⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 libintl.cpp

📁 PIXIL is a small footprint operating environment, complete with PDA PIM applications, a browser and
💻 CPP
📖 第 1 页 / 共 4 页
字号:
      if (cp[0] == '_')	{ 	  /* Next is revision (CEN syntax).  */	  cp[0] = '\0';	  *revision = ++cp;	  mask |= CEN_REVISION;	}    }  /* For CEN syntax values it might be important to have the     separator character in the file name, not for XPG syntax.  */  if (syntax == xpg)    {      if (*territory != NULL && (*territory)[0] == '\0')	mask &= ~TERRITORY;      if (*codeset != NULL && (*codeset)[0] == '\0')	mask &= ~XPG_CODESET;      if (*modifier != NULL && (*modifier)[0] == '\0')	mask &= ~XPG_MODIFIER;    }  return mask;}static struct loaded_l10nfile *_nl_loaded_domains;/* Return a data structure describing the message catalog described by   the DOMAINNAME and CATEGORY parameters with respect to the currently   established bindings.  */struct loaded_l10nfile *_nl_find_domain (const char *dirname, char *locale, 		 const char *domainname){  struct loaded_l10nfile *retval;  const char *language;  const char *modifier;  const char *territory;  const char *codeset;  const char *normalized_codeset;  const char *special;  const char *sponsor;  const char *revision;  const char *alias_value;  int mask;  /* LOCALE can consist of up to four recognized parts for the XPG syntax:		language[_territory[.codeset]][@modifier]     and six parts for the CEN syntax:	language[_territory][+audience][+special][,[sponsor][_revision]]     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 of according to     the following order:		(1) revision		(2) sponsor		(3) special		(4) codeset		(5) normalized codeset		(6) territory		(7) audience/modifier   */  /* If we have already tested for this locale entry there has to     be one data set in the list of loaded domains.  */  retval = _nl_make_l10nflist (&_nl_loaded_domains, dirname,			       strlen (dirname) + 1, 0, locale, NULL, NULL,			       NULL, NULL, NULL, NULL, NULL, domainname, 0);  if (retval != NULL)    {      /* We know something about this locale.  */      int cnt;      if (retval->decided == 0)	k_nl_load_domain (retval);      if (retval->data != NULL)	return retval;      for (cnt = 0; retval->successor[cnt] != NULL; ++cnt)	{	  if (retval->successor[cnt]->decided == 0)	    k_nl_load_domain (retval->successor[cnt]);	  if (retval->successor[cnt]->data != NULL)	    break;	}      return cnt >= 0 ? retval : NULL;      /* NOTREACHED */    }  /* See whether the locale value is an alias.  If yes its value     *overwrites* the alias name.  No test for the original value is     done.  */  alias_value = _nl_expand_alias (locale);  if (alias_value != NULL)    {      size_t len = strlen (alias_value) + 1;      locale = (char *) malloc (len);      if (locale == NULL)	return NULL;      memcpy (locale, alias_value, len);    }  /* Now we determine the single parts of the locale name.  First     look for the language.  Termination symbols are `_' and `@' if     we use XPG4 style, and `_', `+', and `,' if we use CEN syntax.  */  mask = _nl_explode_name (locale, &language, &modifier, &territory,			   &codeset, &normalized_codeset, &special,			   &sponsor, &revision);  /* Create all possible locale entries which might be interested in     generalization.  */  retval = _nl_make_l10nflist (&_nl_loaded_domains, dirname,			       strlen (dirname) + 1, mask, language, territory,			       codeset, normalized_codeset, modifier, special,			       sponsor, revision, domainname, 1);  if (retval == NULL)    /* This means we are out of core.  */    return NULL;  if (retval->decided == 0)    k_nl_load_domain (retval);  if (retval->data == NULL)    {      int cnt;      for (cnt = 0; retval->successor[cnt] != NULL; ++cnt)	{	  if (retval->successor[cnt]->decided == 0)	    k_nl_load_domain (retval->successor[cnt]);	  if (retval->successor[cnt]->data != NULL)	    break;	}    }  /* The room for an alias was dynamically allocated.  Free it now.  */  if (alias_value != NULL)    free (locale);  return retval;}/* We assume to have `unsigned long int' value with at least 32 bits.  */#define HASHWORDBITS 32static inline unsigned longhash_string (const char *str_param){  unsigned long int hval, g;  const char *str = str_param;  /* Compute the hash value for the given string.  */  hval = 0;  while (*str != '\0')    {      hval <<= 4;      hval += (unsigned long) *str++;      g = hval & ((unsigned long) 0xf << (HASHWORDBITS - 4));      if (g != 0)	{	  hval ^= g >> (HASHWORDBITS - 8);	  hval ^= g;	}    }  return hval;}/* Define function which are usually not available.  */#if !defined HAVE___ARGZ_COUNT/* Returns the number of strings in ARGZ.  */static size_targz_count__ (const char *argz, size_t len){  size_t count = 0;  while (len > 0)    {      size_t part_len = strlen (argz);      argz += part_len + 1;      len -= part_len + 1;      count++;    }  return count;}# undef __argz_count# define __argz_count(argz, len) argz_count__ (argz, len)#endif	/* !HAVE___ARGZ_COUNT */#if !defined HAVE___ARGZ_STRINGIFY/* Make '\0' separated arg vector ARGZ printable by converting all the '\0's   except the last into the character SEP.  */static void argz_stringify__  (char *argz, size_t len, int sep);static voidargz_stringify__ (char *argz,size_t  len, int sep){  while (len > 0)    {      size_t part_len = strlen (argz);      argz += part_len;      len -= part_len + 1;      if (len > 0)	*argz++ = sep;    }}# undef __argz_stringify# define __argz_stringify(argz, len, sep) argz_stringify__ (argz, len, sep)#endif	/* !HAVE___ARGZ_STRINGIFY */#if !defined HAVE___ARGZ_NEXTstatic char *argz_next__ ( char *argz,size_t  argz_len, const char *entry){  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;}# undef __argz_next# define __argz_next(argz, len, entry) argz_next__ (argz, len, entry)#endif	/* !HAVE___ARGZ_NEXT */static inline int pop (int x){  /* 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;}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 *special,		    const char *sponsor, const char *revision, 		    const char *filename, int do_allocate){  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 & 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				      || (mask & CEN_AUDIENCE) != 0)				     ? strlen (modifier) + 1 : 0)				  + ((mask & CEN_SPECIAL) != 0				     ? strlen (special) + 1 : 0)				  + (((mask & CEN_SPONSOR) != 0				      || (mask & CEN_REVISION) != 0)				     ? (1 + ((mask & CEN_SPONSOR) != 0					     ? strlen (sponsor) + 1 : 0)					+ ((mask & CEN_REVISION) != 0					   ? strlen (revision) + 1 : 0)) : 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 = (char*)stpcpy (cp, language);  if ((mask & 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 | CEN_AUDIENCE)) != 0)    {      /* This component can be part of both syntaces but has different	 leading characters.  For CEN we use `+', else `@'.  */      *cp++ = (mask & CEN_AUDIENCE) != 0 ? '+' : '@';      cp = stpcpy (cp, modifier);    }  if ((mask & CEN_SPECIAL) != 0)    {      *cp++ = '+';      cp = stpcpy (cp, special);    }  if ((mask & (CEN_SPONSOR | CEN_REVISION)) != 0)    {      *cp++ = ',';      if ((mask & CEN_SPONSOR) != 0)	cp = stpcpy (cp, sponsor);      if ((mask & CEN_REVISION) != 0)	{	  *cp++ = '_';	  cp = stpcpy (cp, revision);	}    }  *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)    return NULL;  retval->filename = abs_filename;  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	&& ((cnt & CEN_SPECIFIC) == 0 || (cnt & XPG_SPECIFIC) == 0)	&& ((cnt & XPG_CODESET) == 0 || (cnt & XPG_NORM_CODESET) == 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, special,				  sponsor, revision, filename, 1);      }  retval->successor[entries] = NULL;  return retval;}/* Normalize codeset name.  There is no standard for the codeset   names.  Normalization allows the user to use any of the common   names.  */const char *_nl_normalize_codeset (const char *codeset, size_t name_len){  int len = 0;  int only_digit = 1;  char *retval;  char *wp;  size_t cnt;  for (cnt = 0; cnt < name_len; ++cnt)    if (isalnum (codeset[cnt]))      {	++len;	if (isalpha (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)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -