X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=libatalk%2Funicode%2Futil_unistr.c;h=5108a4c8e86f0ef8d73d97f7300f025eeae84b92;hb=22a32e7449133013789f3fc7ff6b32772b0c76cc;hp=f878c8c08015e685974b081d4b199e84e3a73d71;hpb=3ef26e02a9c60c1d85f79f34c0b2342dd905e74b;p=netatalk.git diff --git a/libatalk/unicode/util_unistr.c b/libatalk/unicode/util_unistr.c index f878c8c0..5108a4c8 100644 --- a/libatalk/unicode/util_unistr.c +++ b/libatalk/unicode/util_unistr.c @@ -19,12 +19,12 @@ #include #include #include - -#include +#include #include +#include + #include "precompose.h" -#include "byteorder.h" /******************************************************************* Convert a string to lower case. @@ -39,8 +39,8 @@ int strlower_w(ucs2_t *s) while (*s) { if ((0xD800 <= *s) && (*s < 0xDC00)) { if ((0xDC00 <= s[1]) && (s[1] < 0xE000)) { - u_int32_t s_sp = (u_int32_t)*s << 16 | (u_int32_t)s[1]; - u_int32_t v_sp = tolower_sp(s_sp); + uint32_t s_sp = (uint32_t)*s << 16 | (uint32_t)s[1]; + uint32_t v_sp = tolower_sp(s_sp); if (v_sp != s_sp) { *s = v_sp >> 16; s++; @@ -73,8 +73,8 @@ int strupper_w(ucs2_t *s) while (*s) { if ((0xD800 <= *s) && (*s < 0xDC00)) { if ((0xDC00 <= s[1]) && (s[1] < 0xE000)) { - u_int32_t s_sp = (u_int32_t)*s << 16 | (u_int32_t)s[1]; - u_int32_t v_sp = toupper_sp(s_sp); + uint32_t s_sp = (uint32_t)*s << 16 | (uint32_t)s[1]; + uint32_t v_sp = toupper_sp(s_sp); if (v_sp != s_sp) { *s = v_sp >> 16; s++; @@ -105,7 +105,7 @@ int islower_w(ucs2_t c) return ( c == tolower_w(c)); } -int islower_sp(u_int32_t c_sp) +int islower_sp(uint32_t c_sp) { return ( c_sp == tolower_sp(c_sp)); } @@ -121,7 +121,7 @@ int isupper_w(ucs2_t c) return ( c == toupper_w(c)); } -int isupper_sp(u_int32_t c_sp) +int isupper_sp(uint32_t c_sp) { return ( c_sp == toupper_sp(c_sp)); } @@ -180,8 +180,7 @@ wide & sp strcasechr() ucs2_t *strcasechr_w(const ucs2_t *s, ucs2_t c) { while (*s != 0) { -/* LOG(log_debug, logtype_default, "Comparing %X to %X (%X - %X)", c, *s, toupper_w(c), toupper_w(*s));*/ - if (toupper_w(c) == toupper_w(*s)) return (ucs2_t *)s; + if (tolower_w(c) == tolower_w(*s)) return (ucs2_t *)s; s++; } if (c == *s) return (ucs2_t *)s; @@ -189,11 +188,11 @@ ucs2_t *strcasechr_w(const ucs2_t *s, ucs2_t c) return NULL; } -ucs2_t *strcasechr_sp(const ucs2_t *s, u_int32_t c_sp) +ucs2_t *strcasechr_sp(const ucs2_t *s, uint32_t c_sp) { if (*s == 0) return NULL; while (s[1] != 0) { - if (toupper_sp(c_sp) == toupper_sp((u_int32_t)*s << 16 | (u_int32_t)s[1])) return (ucs2_t *)s; + if (tolower_sp(c_sp) == tolower_sp((uint32_t)*s << 16 | (uint32_t)s[1])) return (ucs2_t *)s; s++; } @@ -264,7 +263,7 @@ ucs2_t *strcasestr_w(const ucs2_t *s, const ucs2_t *ins) if ((0xD800 <= *ins) && (*ins < 0xDC00)) { if ((0xDC00 <= ins[1]) && (ins[1] < 0xE000)) { - u_int32_t ins_sp = (u_int32_t)*ins << 16 | (u_int32_t)ins[1]; + uint32_t ins_sp = (uint32_t)*ins << 16 | (uint32_t)ins[1]; while ((r = strcasechr_sp(r, ins_sp))) { if (strncasecmp_w(r, ins, inslen) == 0) return r; r++; @@ -293,12 +292,12 @@ int strcasecmp_w(const ucs2_t *a, const ucs2_t *b) while (*a && *b) { if ((0xD800 <= *a) && (*a < 0xDC00)) { - if (ret = tolower_sp((u_int32_t)*a << 16 | (u_int32_t)a[1]) - tolower_sp((u_int32_t)*b << 16 | (u_int32_t)b[1])) return ret; + if ((ret = tolower_sp((uint32_t)*a << 16 | (uint32_t)a[1]) - tolower_sp((uint32_t)*b << 16 | (uint32_t)b[1]))) return ret; a++; b++; if (!(*a && *b)) return (tolower_w(*a) - tolower_w(*b)); /* avoid buffer over run */ } else { - if (ret = tolower_w(*a) - tolower_w(*b)) return ret; + if ((ret = tolower_w(*a) - tolower_w(*b))) return ret; } a++; b++; @@ -319,13 +318,13 @@ int strncasecmp_w(const ucs2_t *a, const ucs2_t *b, size_t len) while ((n < len) && *a && *b) { if ((0xD800 <= *a) && (*a < 0xDC00)) { - if (ret = tolower_sp((u_int32_t)*a << 16 | (u_int32_t)a[1]) - tolower_sp((u_int32_t)*b << 16 | (u_int32_t)b[1])) return ret; + if ((ret = tolower_sp((uint32_t)*a << 16 | (uint32_t)a[1]) - tolower_sp((uint32_t)*b << 16 | (uint32_t)b[1]))) return ret; a++; b++; n++; if (!((n < len) && *a && *b)) return (tolower_w(*a) - tolower_w(*b)); } else { - if (ret = tolower_w(*a) - tolower_w(*b)) return ret; + if ((ret = tolower_w(*a) - tolower_w(*b))) return ret; } a++; b++; @@ -439,7 +438,7 @@ static ucs2_t do_precomposition(unsigned int base, unsigned int comb) int min = 0; int max = PRECOMP_COUNT - 1; int mid; - u_int32_t sought = (base << 16) | comb, that; + uint32_t sought = (base << 16) | comb, that; /* binary search */ while (max >= min) { @@ -458,17 +457,17 @@ static ucs2_t do_precomposition(unsigned int base, unsigned int comb) } /* ------------------------ */ -static u_int32_t do_precomposition_sp(unsigned int base_sp, unsigned int comb_sp) +static uint32_t do_precomposition_sp(unsigned int base_sp, unsigned int comb_sp) { int min = 0; int max = PRECOMP_SP_COUNT - 1; int mid; - u_int64_t sought_sp = ((u_int64_t)base_sp << 32) | (u_int64_t)comb_sp, that_sp; + uint64_t sought_sp = ((uint64_t)base_sp << 32) | (uint64_t)comb_sp, that_sp; /* binary search */ while (max >= min) { mid = (min + max) / 2; - that_sp = ((u_int64_t)precompositions_sp[mid].base_sp << 32) | ((u_int64_t)precompositions_sp[mid].comb_sp); + that_sp = ((uint64_t)precompositions_sp[mid].base_sp << 32) | ((uint64_t)precompositions_sp[mid].comb_sp); if (that_sp < sought_sp) { min = mid + 1; } else if (that_sp > sought_sp) { @@ -482,13 +481,13 @@ static u_int32_t do_precomposition_sp(unsigned int base_sp, unsigned int comb_sp } /* -------------------------- */ -static u_int32_t do_decomposition(ucs2_t base) +static uint32_t do_decomposition(ucs2_t base) { int min = 0; int max = DECOMP_COUNT - 1; int mid; - u_int32_t sought = base; - u_int32_t result, that; + uint32_t sought = base; + uint32_t result, that; /* binary search */ while (max >= min) { @@ -508,14 +507,14 @@ static u_int32_t do_decomposition(ucs2_t base) } /* -------------------------- */ -static u_int64_t do_decomposition_sp(unsigned int base_sp) +static uint64_t do_decomposition_sp(unsigned int base_sp) { int min = 0; int max = DECOMP_SP_COUNT - 1; int mid; - u_int32_t sought_sp = base_sp; - u_int32_t that_sp; - u_int64_t result_sp; + uint32_t sought_sp = base_sp; + uint32_t that_sp; + uint64_t result_sp; /* binary search */ while (max >= min) { @@ -526,7 +525,7 @@ static u_int64_t do_decomposition_sp(unsigned int base_sp) } else if (that_sp > sought_sp) { max = mid - 1; } else { - result_sp = ((u_int64_t)decompositions_sp[mid].base_sp << 32) | ((u_int64_t)decompositions_sp[mid].comb_sp); + result_sp = ((uint64_t)decompositions_sp[mid].base_sp << 32) | ((uint64_t)decompositions_sp[mid].comb_sp); return result_sp; } } @@ -553,11 +552,11 @@ size_t precompose_w (ucs2_t *name, size_t inplen, ucs2_t *comp, size_t *outlen) { size_t i; ucs2_t base, comb; - u_int32_t base_sp, comb_sp; + uint32_t base_sp, comb_sp; ucs2_t *in, *out; ucs2_t lindex, vindex; ucs2_t result; - u_int32_t result_sp; + uint32_t result_sp; size_t o_len = *outlen; if (!inplen || (inplen & 1) || inplen > o_len) @@ -606,10 +605,10 @@ size_t precompose_w (ucs2_t *name, size_t inplen, ucs2_t *comp, size_t *outlen) /* Binary Search for Surrogate Pair */ else if ((0xD800 <= base) && (base < 0xDC00)) { if ((0xDC00 <= comb) && (comb < 0xE000) && (i + 6 <= inplen)) { - base_sp = ((u_int32_t)base << 16) | (u_int32_t)comb; + base_sp = ((uint32_t)base << 16) | (uint32_t)comb; do { - comb_sp = ((u_int32_t)in[1] << 16) | (u_int32_t)in[2]; - if (result_sp = do_precomposition_sp(base_sp, comb_sp)) { + comb_sp = ((uint32_t)in[1] << 16) | (uint32_t)in[2]; + if ((result_sp = do_precomposition_sp(base_sp, comb_sp))) { base_sp = result_sp; i += 4; in +=2; @@ -643,7 +642,7 @@ size_t precompose_w (ucs2_t *name, size_t inplen, ucs2_t *comp, size_t *outlen) } /* Binary Search for BMP */ - else if (result = do_precomposition(base, comb)) { + else if ((result = do_precomposition(base, comb))) { base = result; } @@ -665,11 +664,11 @@ size_t decompose_w (ucs2_t *name, size_t inplen, ucs2_t *comp, size_t *outlen) size_t i; size_t comblen; ucs2_t base, comb[COMBBUFLEN]; - u_int32_t base_sp; + uint32_t base_sp; ucs2_t sindex, tjamo; ucs2_t *in, *out; unsigned int result; - u_int64_t result_sp; + uint64_t result_sp; size_t o_len = *outlen; if (!inplen || (inplen & 1)) @@ -707,7 +706,7 @@ size_t decompose_w (ucs2_t *name, size_t inplen, ucs2_t *comp, size_t *outlen) /* Binary Search for Surrogate Pair */ else if ((0xD800 <= base) && (base < 0xDC00)) { if (i + 2 < inplen) { - base_sp = ((u_int32_t)base << 16) | (u_int32_t)in[1]; + base_sp = ((uint32_t)base << 16) | (uint32_t)in[1]; do { if ( !(result_sp = do_decomposition_sp(base_sp))) break; comblen += 2;