Changeset View
Changeset View
Standalone View
Standalone View
lib/libc/iconv/citrus_prop.c
Show First 20 Lines • Show All 73 Lines • ▼ Show 20 Lines | if (obj->type == _CITRUS_PROP_STR) | ||||
free(__DECONST(void *, obj->u.str)); | free(__DECONST(void *, obj->u.str)); | ||||
} | } | ||||
static const char *xdigit = "0123456789ABCDEF"; | static const char *xdigit = "0123456789ABCDEF"; | ||||
#define _CITRUS_PROP_READ_UINT_COMMON(_func_, _type_, _max_) \ | #define _CITRUS_PROP_READ_UINT_COMMON(_func_, _type_, _max_) \ | ||||
static int \ | static int \ | ||||
_citrus_prop_read_##_func_##_common(struct _memstream * __restrict ms, \ | _citrus_prop_read_##_func_##_common(struct _memstream * __restrict ms, \ | ||||
_type_ * __restrict result, int base) \ | _type_ * __restrict result, int base, int neg) \ | ||||
{ \ | { \ | ||||
_type_ acc, cutoff; \ | _type_ acc, cutoff; \ | ||||
int ch, cutlim, n; \ | int ch, cutlim, n; \ | ||||
char *p; \ | char *p; \ | ||||
\ | \ | ||||
acc = (_type_)0; \ | acc = (_type_)0; \ | ||||
cutoff = _max_ / base; \ | cutoff = _max_ / base; \ | ||||
cutlim = _max_ % base; \ | cutlim = _max_ % base; \ | ||||
for (;;) { \ | for (;;) { \ | ||||
ch = _memstream_getc(ms); \ | ch = _memstream_getc(ms); \ | ||||
p = strchr(xdigit, _bcs_toupper(ch)); \ | p = strchr(xdigit, _bcs_toupper(ch)); \ | ||||
if (p == NULL || (n = (p - xdigit)) >= base) \ | if (p == NULL || (n = (p - xdigit)) >= base) \ | ||||
break; \ | break; \ | ||||
if (acc > cutoff || (acc == cutoff && n > cutlim)) \ | if (acc > cutoff || (acc == cutoff && n > cutlim)) \ | ||||
break; \ | break; \ | ||||
acc *= base; \ | acc *= base; \ | ||||
acc += n; \ | acc += n; \ | ||||
} \ | } \ | ||||
_memstream_ungetc(ms, ch); \ | _memstream_ungetc(ms, ch); \ | ||||
*result = acc; \ | *result = neg ? -acc : acc; \ | ||||
return (0); \ | return (0); \ | ||||
} | } | ||||
_CITRUS_PROP_READ_UINT_COMMON(chr, int, UCHAR_MAX) | _CITRUS_PROP_READ_UINT_COMMON(chr, int, UCHAR_MAX) | ||||
_CITRUS_PROP_READ_UINT_COMMON(num, uint64_t, UINT64_MAX) | _CITRUS_PROP_READ_UINT_COMMON(num, uint64_t, UINT64_MAX) | ||||
#undef _CITRUS_PROP_READ_UINT_COMMON | #undef _CITRUS_PROP_READ_UINT_COMMON | ||||
#define _CITRUS_PROP_READ_INT(_func_, _type_) \ | #define _CITRUS_PROP_READ_INT(_func_, _type_) \ | ||||
static int \ | static int \ | ||||
Show All 23 Lines | if (ch == 'x' || ch == 'X') { \ | ||||
return (0); \ | return (0); \ | ||||
} \ | } \ | ||||
base += 8; \ | base += 8; \ | ||||
} \ | } \ | ||||
} else if (_bcs_isdigit(ch) == 0) \ | } else if (_bcs_isdigit(ch) == 0) \ | ||||
return (EINVAL); \ | return (EINVAL); \ | ||||
_memstream_ungetc(ms, ch); \ | _memstream_ungetc(ms, ch); \ | ||||
return (_citrus_prop_read_##_func_##_common \ | return (_citrus_prop_read_##_func_##_common \ | ||||
(ms, &obj->u._func_, base)); \ | (ms, &obj->u._func_, base, neg)); \ | ||||
} | } | ||||
_CITRUS_PROP_READ_INT(chr, int) | _CITRUS_PROP_READ_INT(chr, int) | ||||
_CITRUS_PROP_READ_INT(num, uint64_t) | _CITRUS_PROP_READ_INT(num, uint64_t) | ||||
#undef _CITRUS_PROP_READ_INT | #undef _CITRUS_PROP_READ_INT | ||||
static int | static int | ||||
_citrus_prop_read_character_common(struct _memstream * __restrict ms, | _citrus_prop_read_character_common(struct _memstream * __restrict ms, | ||||
int * __restrict result) | int * __restrict result) | ||||
Show All 29 Lines | case 'v': | ||||
*result = '\v'; | *result = '\v'; | ||||
break; | break; | ||||
case '0': case '1': case '2': case '3': | case '0': case '1': case '2': case '3': | ||||
case '4': case '5': case '6': case '7': | case '4': case '5': case '6': case '7': | ||||
_memstream_ungetc(ms, ch); | _memstream_ungetc(ms, ch); | ||||
base -= 8; | base -= 8; | ||||
/*FALLTHROUGH*/ | /*FALLTHROUGH*/ | ||||
case 'x': | case 'x': | ||||
return (_citrus_prop_read_chr_common(ms, result, base)); | return (_citrus_prop_read_chr_common(ms, result, | ||||
base, 0)); | |||||
/*NOTREACHED*/ | /*NOTREACHED*/ | ||||
default: | default: | ||||
/* unknown escape */ | /* unknown escape */ | ||||
*result = ch; | *result = ch; | ||||
} | } | ||||
} | } | ||||
return (0); | return (0); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 251 Lines • Show Last 20 Lines |