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

📄 table.c

📁 KPIT GNU Tools is a set of GNU development tools for Renesas microcontrollers.
💻 C
📖 第 1 页 / 共 2 页
字号:
 *     ucs2_t code - code whose mapping to find. *     _CONST __uint16_t *tblp - table pointer. * * RETURN: *     Code that corresponds to 'code'. */static __inline ucs2_t_DEFUN(find_code_speed, (code, tblp),                        ucs2_t code _AND                        _CONST __uint16_t *tblp){  int idx = tblp[code >> 8];  if (idx == INVBLK)    return (ucs2_t)INVALC;  return (ucs2_t)tblp[(code & 0x00FF) + idx];}/* * find_code_speed_8bit - find code in 8 bit speed-optimized table. * * PARAMETERS: *     ucs2_t code - code whose mapping to find. *     _CONST __uint16_t *tblp - table pointer. * * RETURN: *     Code that corresponds to 'code'. */static __inline ucs2_t_DEFUN(find_code_speed_8bit, (code, tblp),                             ucs2_t code _AND                             _CONST unsigned char *tblp){  int idx;  unsigned char ccs;  if (code == ((ucs2_t *)tblp)[0])    return (ucs2_t)0xFF;   idx = ((ucs2_t *)tblp)[1 + (code >> 8)];    if (idx == INVBLK)    return (ucs2_t)INVALC;  ccs = tblp[(code & 0x00FF) + idx];  return ccs == 0xFF ? (ucs2_t)INVALC : (ucs2_t)ccs;}/* Left range boundary */#define RANGE_LEFT(n)     (tblp[FIRST_RANGE_INDEX + (n)*3 + 0])/* Right range boundary */#define RANGE_RIGHT(n)    (tblp[FIRST_RANGE_INDEX + (n)*3 + 1])/* Range offset */#define RANGE_INDEX(n)    (tblp[FIRST_RANGE_INDEX + (n)*3 + 2])/* Un-ranged offset */#define UNRANGED_INDEX(n) (tblp[FIRST_UNRANGED_INDEX_INDEX] + (n)*2)/* * find_code_size - find code in 16 bit size-optimized table. * * PARAMETERS: *     ucs2_t code - code whose mapping to find. *     _CONST __uint16_t *tblp - table pointer. * * RETURN: *     Code that corresponds to 'code'. */static ucs2_t_DEFUN(find_code_size, (code, tblp),                       ucs2_t code _AND                       _CONST __uint16_t *tblp){  int first, last, cur, center;  if (tblp[RANGES_NUM_INDEX] > 0)    {      first = 0;      last = tblp[RANGES_NUM_INDEX] - 1;       do        {          center = (last - first)/2;          cur = center + first;                    if (code > RANGE_RIGHT (cur))            first = cur;          else if (code < RANGE_LEFT (cur))            last = cur;          else            return (ucs2_t)tblp[RANGE_INDEX (cur) + code - RANGE_LEFT (cur)];        } while (center > 0);        if (last - first == 1)          {            if (code >= RANGE_LEFT (first) && code <= RANGE_RIGHT (first))              return (ucs2_t)tblp[RANGE_INDEX (first)                                  + code - RANGE_LEFT (first)];            if (code >= RANGE_LEFT (last) && code <= RANGE_RIGHT (last))              return (ucs2_t)tblp[RANGE_INDEX (last)                                  + code - RANGE_LEFT (last)];          }    }    if (tblp[UNRANGED_NUM_INDEX] > 0)    {      first = 0;      last = tblp[UNRANGED_NUM_INDEX] - 1;       do        {          int c;          center = (last - first)/2;          cur = center + first;          c = tblp[UNRANGED_INDEX (cur)];           if (code > c)            first = cur;          else if (code < c)            last = cur;          else            return (ucs2_t)tblp[UNRANGED_INDEX (cur) + 1];        } while (center > 0);        if (last - first == 1)          {            if (code == tblp[UNRANGED_INDEX (first)])              return (ucs2_t)tblp[UNRANGED_INDEX (first) + 1];            if (code == tblp[UNRANGED_INDEX (last)])              return (ucs2_t)tblp[UNRANGED_INDEX (last) + 1];          }    }  return (ucs2_t)INVALC;}#ifdef _ICONV_ENABLE_EXTERNAL_CCS#define _16BIT_ELT(offset) \    ICONV_BETOHS(*((__uint16_t *)(buf + (offset))))#define _32BIT_ELT(offset) \    ICONV_BETOHL(*((__uint32_t *)(buf + (offset))))/* * load_file - load conversion table from external file and initialize *             iconv_ccs_desc_t object. * * PARAMETERS: *    struct _reent *rptr - reent structure of current thread/process. *    _CONST char *name - encoding name. *    int direction - conversion direction. * * DESCRIPTION: *    Loads conversion table of appropriate endianess from external file *    and initializes 'iconv_ccs_desc_t' table description structure. *    If 'direction' is 0 - load "To UCS" table, else load "From UCS" *    table. * * RETURN: *    iconv_ccs_desc_t * pointer is success, NULL if failure. */static _CONST iconv_ccs_desc_t *_DEFUN(load_file, (rptr, name, direction),                   struct _reent *rptr _AND                  _CONST char *name   _AND                  int direction){  int fd;  _CONST unsigned char *buf;  int tbllen, hdrlen;  off_t off;  _CONST char *fname;  iconv_ccs_desc_t *ccsp = NULL;  int nmlen = strlen(name);  /* Since CCS table name length can vary - it is aligned (by adding extra   * bytes to it's end) to 4-byte boundary. */  int alignment = nmlen & 3 ? 4 - (nmlen & 3) : 0;    nmlen = strlen(name);    hdrlen = nmlen + EXTTABLE_HEADER_LEN + alignment;  if ((fname = _iconv_nls_construct_filename (rptr, name, ICONV_SUBDIR,                                              ICONV_DATA_EXT)) == NULL)    return NULL;    if ((fd = _open_r (rptr, fname, O_RDONLY, S_IRUSR)) == -1)    goto error1;    if ((buf = (_CONST unsigned char *)_malloc_r (rptr, hdrlen)) == NULL)    goto error2;  if (_read_r (rptr, fd, (_VOID_PTR)buf, hdrlen) != hdrlen)    goto error3;  if (_16BIT_ELT (EXTTABLE_VERSION_OFF) != TABLE_VERSION_1      || _32BIT_ELT (EXTTABLE_CCSNAME_LEN_OFF) != nmlen      || strncmp (buf + EXTTABLE_CCSNAME_OFF, name, nmlen) != 0)    goto error3; /* Bad file */  if ((ccsp = (iconv_ccs_desc_t *)           _calloc_r (rptr, 1, sizeof (iconv_ccs_desc_t))) == NULL)    goto error3;    ccsp->bits = _16BIT_ELT (EXTTABLE_BITS_OFF);  ccsp->type = TABLE_EXTERNAL;  /* Add 4-byte alignment to name length */  nmlen += alignment;  if (ccsp->bits == TABLE_8BIT)    {      if (direction == 0) /* Load "To UCS" table */        {          off = (off_t)_32BIT_ELT (nmlen + EXTTABLE_TO_SPEED_OFF);          tbllen = _32BIT_ELT (nmlen + EXTTABLE_TO_SPEED_LEN_OFF);        }      else /* Load "From UCS" table */        {          off = (off_t)_32BIT_ELT (nmlen + EXTTABLE_FROM_SPEED_OFF);          tbllen = _32BIT_ELT (nmlen + EXTTABLE_FROM_SPEED_LEN_OFF);        }    }  else if (ccsp->bits == TABLE_16BIT)    {      if (direction == 0) /* Load "To UCS" table */        {#ifdef TABLE_USE_SIZE_OPTIMIZATION          off = (off_t)_32BIT_ELT (nmlen + EXTTABLE_TO_SIZE_OFF);          tbllen = _32BIT_ELT (nmlen + EXTTABLE_TO_SIZE_LEN_OFF);#else          off = (off_t)_32BIT_ELT (nmlen + EXTTABLE_TO_SPEED_OFF);          tbllen = _32BIT_ELT (nmlen + EXTTABLE_TO_SPEED_LEN_OFF);#endif        }      else /* Load "From UCS" table */        {#ifdef TABLE_USE_SIZE_OPTIMIZATION          off = (off_t)_32BIT_ELT (nmlen + EXTTABLE_FROM_SIZE_OFF);          tbllen = _32BIT_ELT (nmlen + EXTTABLE_FROM_SIZE_LEN_OFF);#else          off = (off_t)_32BIT_ELT (nmlen + EXTTABLE_FROM_SPEED_OFF);          tbllen = _32BIT_ELT (nmlen + EXTTABLE_FROM_SPEED_LEN_OFF);#endif        }#ifdef TABLE_USE_SIZE_OPTIMIZATION      ccsp->optimization = TABLE_SIZE_OPTIMIZED; #else      ccsp->optimization = TABLE_SPEED_OPTIMIZED;#endif    }  else    goto error4; /* Bad file */  if (off == EXTTABLE_NO_TABLE)    goto error4; /* No correspondent table in file */  if ((ccsp->tbl = (ucs2_t *)_malloc_r (rptr, tbllen)) == NULL)    goto error4;  if (_lseek_r (rptr, fd, off, SEEK_SET) == (off_t)-1      || _read_r (rptr, fd, (_VOID_PTR)ccsp->tbl, tbllen) != tbllen)    goto error5;  goto normal_exit;error5:  _free_r (rptr, (_VOID_PTR)ccsp->tbl);  ccsp->tbl = NULL;error4:  _free_r (rptr, (_VOID_PTR)ccsp);  ccsp = NULL;error3:normal_exit:  _free_r (rptr, (_VOID_PTR)buf);error2:  if (_close_r (rptr, fd) == -1)    {      if (ccsp != NULL)        {          if (ccsp->tbl != NULL)            _free_r (rptr, (_VOID_PTR)ccsp->tbl);          _free_r (rptr, (_VOID_PTR)ccsp);        }      ccsp = NULL;    }error1:  _free_r (rptr, (_VOID_PTR)fname);  return ccsp;}#endif#endif /* ICONV_TO_UCS_CES_TABLE || ICONV_FROM_UCS_CES_TABLE */

⌨️ 快捷键说明

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