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

📄 dcigettext.c

📁 磁盘管理工具,主要管理光盘信息和内容希望大家喜欢
💻 C
📖 第 1 页 / 共 4 页
字号:
	      else		{		  /* We can update the existing entry.  */		  (*foundp)->counter = _nl_msg_cat_cntr;		  (*foundp)->domain = domain;		  (*foundp)->translation = retval;		  (*foundp)->translation_length = retlen;		}#endif	      __set_errno (saved_errno);	      /* Now deal with plural.  */	      if (plural)		retval = plural_lookup (domain, n, retval, retlen);	      gl_rwlock_unlock (_nl_state_lock);	      return retval;	    }	}    } return_untranslated:  /* Return the untranslated MSGID.  */  FREE_BLOCKS (block_list);  gl_rwlock_unlock (_nl_state_lock);#ifndef _LIBC  if (!ENABLE_SECURE)    {      extern void _nl_log_untranslated (const char *logfilename,					const char *domainname,					const char *msgid1, const char *msgid2,					int plural);      const char *logfilename = getenv ("GETTEXT_LOG_UNTRANSLATED");      if (logfilename != NULL && logfilename[0] != '\0')	_nl_log_untranslated (logfilename, domainname, msgid1, msgid2, plural);    }#endif  __set_errno (saved_errno);  return (plural == 0	  ? (char *) msgid1	  /* Use the Germanic plural rule.  */	  : n == 1 ? (char *) msgid1 : (char *) msgid2);}/* Look up the translation of msgid within DOMAIN_FILE and DOMAINBINDING.   Return it if found.  Return NULL if not found or in case of a conversion   failure (problem in the particular message catalog).  Return (char *) -1   in case of a memory allocation failure during conversion (only if   ENCODING != NULL resp. CONVERT == true).  */char *internal_function#ifdef IN_LIBGLOCALE_nl_find_msg (struct loaded_l10nfile *domain_file,	      struct binding *domainbinding, const char *encoding,	      const char *msgid,	      size_t *lengthp)#else_nl_find_msg (struct loaded_l10nfile *domain_file,	      struct binding *domainbinding,	      const char *msgid, int convert,	      size_t *lengthp)#endif{  struct loaded_domain *domain;  nls_uint32 nstrings;  size_t act;  char *result;  size_t resultlen;  if (domain_file->decided <= 0)    _nl_load_domain (domain_file, domainbinding);  if (domain_file->data == NULL)    return NULL;  domain = (struct loaded_domain *) domain_file->data;  nstrings = domain->nstrings;  /* Locate the MSGID and its translation.  */  if (domain->hash_tab != NULL)    {      /* Use the hashing table.  */      nls_uint32 len = strlen (msgid);      nls_uint32 hash_val = __hash_string (msgid);      nls_uint32 idx = hash_val % domain->hash_size;      nls_uint32 incr = 1 + (hash_val % (domain->hash_size - 2));      while (1)	{	  nls_uint32 nstr =	    W (domain->must_swap_hash_tab, domain->hash_tab[idx]);	  if (nstr == 0)	    /* Hash table entry is empty.  */	    return NULL;	  nstr--;	  /* Compare msgid with the original string at index nstr.	     We compare the lengths with >=, not ==, because plural entries	     are represented by strings with an embedded NUL.  */	  if (nstr < nstrings	      ? W (domain->must_swap, domain->orig_tab[nstr].length) >= len		&& (strcmp (msgid,			    domain->data + W (domain->must_swap,					      domain->orig_tab[nstr].offset))		    == 0)	      : domain->orig_sysdep_tab[nstr - nstrings].length > len		&& (strcmp (msgid,			    domain->orig_sysdep_tab[nstr - nstrings].pointer)		    == 0))	    {	      act = nstr;	      goto found;	    }	  if (idx >= domain->hash_size - incr)	    idx -= domain->hash_size - incr;	  else	    idx += incr;	}      /* NOTREACHED */    }  else    {      /* Try the default method:  binary search in the sorted array of	 messages.  */      size_t top, bottom;      bottom = 0;      top = nstrings;      while (bottom < top)	{	  int cmp_val;	  act = (bottom + top) / 2;	  cmp_val = strcmp (msgid, (domain->data				    + W (domain->must_swap,					 domain->orig_tab[act].offset)));	  if (cmp_val < 0)	    top = act;	  else if (cmp_val > 0)	    bottom = act + 1;	  else	    goto found;	}      /* No translation was found.  */      return NULL;    } found:  /* The translation was found at index ACT.  If we have to convert the     string to use a different character set, this is the time.  */  if (act < nstrings)    {      result = (char *)	(domain->data + W (domain->must_swap, domain->trans_tab[act].offset));      resultlen = W (domain->must_swap, domain->trans_tab[act].length) + 1;    }  else    {      result = (char *) domain->trans_sysdep_tab[act - nstrings].pointer;      resultlen = domain->trans_sysdep_tab[act - nstrings].length;    }#if defined _LIBC || HAVE_ICONV# ifdef IN_LIBGLOCALE  if (encoding != NULL)# else  if (convert)# endif    {      /* We are supposed to do a conversion.  */# ifndef IN_LIBGLOCALE      const char *encoding = get_output_charset (domainbinding);# endif      /* Search whether a table with converted translations for this	 encoding has already been allocated.  */      size_t nconversions = domain->nconversions;      struct converted_domain *convd = NULL;      size_t i;      for (i = nconversions; i > 0; )	{	  i--;	  if (strcmp (domain->conversions[i].encoding, encoding) == 0)	    {	      convd = &domain->conversions[i];	      break;	    }	}      if (convd == NULL)	{	  /* Allocate a table for the converted translations for this	     encoding.  */	  struct converted_domain *new_conversions =	    (struct converted_domain *)	    (domain->conversions != NULL	     ? realloc (domain->conversions,			(nconversions + 1) * sizeof (struct converted_domain))	     : malloc ((nconversions + 1) * sizeof (struct converted_domain)));	  if (__builtin_expect (new_conversions == NULL, 0))	    /* Nothing we can do, no more memory.  We cannot use the	       translation because it might be encoded incorrectly.  */	    return (char *) -1;	  domain->conversions = new_conversions;	  /* Copy the 'encoding' string to permanent storage.  */	  encoding = strdup (encoding);	  if (__builtin_expect (encoding == NULL, 0))	    /* Nothing we can do, no more memory.  We cannot use the	       translation because it might be encoded incorrectly.  */	    return (char *) -1;	  convd = &new_conversions[nconversions];	  convd->encoding = encoding;	  /* Find out about the character set the file is encoded with.	     This can be found (in textual form) in the entry "".  If this	     entry does not exist or if this does not contain the 'charset='	     information, we will assume the charset matches the one the	     current locale and we don't have to perform any conversion.  */# ifdef _LIBC	  convd->conv = (__gconv_t) -1;# else#  if HAVE_ICONV	  convd->conv = (iconv_t) -1;#  endif# endif	  {	    char *nullentry;	    size_t nullentrylen;	    /* Get the header entry.  This is a recursion, but it doesn't	       reallocate domain->conversions because we pass	       encoding = NULL or convert = 0, respectively.  */	    nullentry =# ifdef IN_LIBGLOCALE	      _nl_find_msg (domain_file, domainbinding, NULL, "",			    &nullentrylen);# else	      _nl_find_msg (domain_file, domainbinding, "", 0, &nullentrylen);# endif	    if (nullentry != NULL)	      {		const char *charsetstr;		charsetstr = strstr (nullentry, "charset=");		if (charsetstr != NULL)		  {		    size_t len;		    char *charset;		    const char *outcharset;		    charsetstr += strlen ("charset=");		    len = strcspn (charsetstr, " \t\n");		    charset = (char *) alloca (len + 1);# if defined _LIBC || HAVE_MEMPCPY		    *((char *) mempcpy (charset, charsetstr, len)) = '\0';# else		    memcpy (charset, charsetstr, len);		    charset[len] = '\0';# endif		    outcharset = encoding;# ifdef _LIBC		    /* We always want to use transliteration.  */		    outcharset = norm_add_slashes (outcharset, "TRANSLIT");		    charset = norm_add_slashes (charset, "");		    int r = __gconv_open (outcharset, charset, &convd->conv,					  GCONV_AVOID_NOCONV);		    if (__builtin_expect (r != __GCONV_OK, 0))		      {			/* If the output encoding is the same there is			   nothing to do.  Otherwise do not use the			   translation at all.  */			if (__builtin_expect (r != __GCONV_NOCONV, 1))			  return NULL;			convd->conv = (__gconv_t) -1;		      }# else#  if HAVE_ICONV		    /* When using GNU libc >= 2.2 or GNU libiconv >= 1.5,		       we want to use transliteration.  */#   if (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 2) || __GLIBC__ > 2 \       || _LIBICONV_VERSION >= 0x0105		    if (strchr (outcharset, '/') == NULL)		      {			char *tmp;			len = strlen (outcharset);			tmp = (char *) alloca (len + 10 + 1);			memcpy (tmp, outcharset, len);			memcpy (tmp + len, "//TRANSLIT", 10 + 1);			outcharset = tmp;			convd->conv = iconv_open (outcharset, charset);			freea (outcharset);		      }		    else#   endif		      convd->conv = iconv_open (outcharset, charset);#  endif# endif		    freea (charset);		  }	      }	  }	  convd->conv_tab = NULL;	  /* Here domain->conversions is still == new_conversions.  */	  domain->nconversions++;	}      if (# ifdef _LIBC	  convd->conv != (__gconv_t) -1# else#  if HAVE_ICONV	  convd->conv != (iconv_t) -1#  endif# endif	  )	{	  /* We are supposed to do a conversion.  First allocate an	     appropriate table with the same structure as the table	     of translations in the file, where we can put the pointers	     to the converted strings in.	     There is a slight complication with plural entries.  They	     are represented by consecutive NUL terminated strings.  We	     handle this case by converting RESULTLEN bytes, including	     NULs.  */	  if (convd->conv_tab == NULL	      && ((convd->conv_tab =		    (char **) calloc (nstrings + domain->n_sysdep_strings,				      sizeof (char *)))		  == NULL))	    /* Mark that we didn't succeed allocating a table.  */	    convd->conv_tab = (char **) -1;	  if (__builtin_expect (convd->conv_tab == (char **) -1, 0))	    /* Nothing we can do, no more memory.  We cannot use the	       translation because it might be encoded incorrectly.  */	    return (char *) -1;	  if (convd->conv_tab[act] == NULL)	    {	      /* We haven't used this string so far, so it is not		 translated yet.  Do this now.  */	      /* We use a bit more efficient memory handling.		 We allocate always larger blocks which get used over		 time.  This is faster than many small allocations.   */	      __libc_lock_define_initialized (static, lock)# define INITIAL_BLOCK_SIZE	4080	      static unsigned char *freemem;	      static size_t freemem_size;	      const unsigned char *inbuf;	      unsigned char *outbuf;	      int malloc_count;# ifndef _LIBC	      transmem_block_t *transmem_list = NULL;# endif	      __libc_lock_lock (lock);	      inbuf = (const unsigned char *) result;	      outbuf = freemem + sizeof (size_t);	      malloc_count = 0;	      while (1)		{		  transmem_block_t *newmem;# ifdef _LIBC		  size_t non_reversible;		  int res;		  if (freemem_size < sizeof (size_t))		    goto resize_freemem;		  res = __gconv (convd->conv,				 &inbuf, inbuf + resultlen,				 &outbuf,				 outbuf + freemem_size - sizeof (size_t),				 &non_reversible);		  if (res == __GCONV_OK || res == __GCONV_EMPTY_INPUT)		    break;		  if (res != __GCONV_FULL_OUTPUT)		    {		      /* We should not use the translation at all, it			 is incorrectly encoded.  */		      __libc_lock_unlock (lock);		      return NULL;		    }		  inbuf = (const unsigned char *) result;# else#  if HAVE_ICONV		  const char *inptr = (const char *) inbuf;

⌨️ 快捷键说明

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