Date: Tue, 12 Aug 2014 23:29:29 GMT From: ghostmansd@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r272312 - in soc2014/ghostmansd/head/lib/libc: locale unicode Message-ID: <201408122329.s7CNTT46020047@socsvn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: ghostmansd Date: Tue Aug 12 23:29:29 2014 New Revision: 272312 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=272312 Log: various style(9) fixes as suggested by Pedro Modified: soc2014/ghostmansd/head/lib/libc/locale/collate.c soc2014/ghostmansd/head/lib/libc/unicode/uccclass.c soc2014/ghostmansd/head/lib/libc/unicode/ucscanon.c soc2014/ghostmansd/head/lib/libc/unicode/ucscoll.c soc2014/ghostmansd/head/lib/libc/unicode/ucsnorm.c soc2014/ghostmansd/head/lib/libc/unicode/ucsxfrm.c Modified: soc2014/ghostmansd/head/lib/libc/locale/collate.c ============================================================================== --- soc2014/ghostmansd/head/lib/libc/locale/collate.c Tue Aug 12 23:22:38 2014 (r272311) +++ soc2014/ghostmansd/head/lib/libc/locale/collate.c Tue Aug 12 23:29:29 2014 (r272312) @@ -95,14 +95,12 @@ int flags = (O_RDWR | O_CREAT | O_TRUNC); colldb = calloc(1, sizeof(struct __colldb)); - if (colldb == NULL) - { + if (colldb == NULL) { errno = ENOMEM; return (NULL); } db = dbopen(path, flags, mode, DB_HASH, NULL); - if (db == NULL) - { + if (db == NULL) { error = errno; free(colldb); errno = error; @@ -114,8 +112,7 @@ value.data = "COLLATION"; key.size = (strlen("TYPE") + 1); value.size = (strlen("COLLATION") + 1); - if (db->put(db, &key, &value, 0) == -1) - { + if (db->put(db, &key, &value, 0) == -1) { error = errno; goto failure; } @@ -125,8 +122,7 @@ value.data = &version; key.size = (strlen("VERSION") + 1); value.size = sizeof(((struct __colldb*)colldb)->version); - if (db->put(db, &key, &value, 0) == -1) - { + if (db->put(db, &key, &value, 0) == -1) { error = errno; goto failure; } @@ -154,14 +150,12 @@ int flags = O_RDONLY; colldb = calloc(1, sizeof(struct __colldb)); - if (colldb == NULL) - { + if (colldb == NULL) { errno = ENOMEM; return (NULL); } db = dbopen(path, flags, 0, DB_HASH, NULL); - if (db == NULL) - { + if (db == NULL) { error = errno; free(colldb); errno = error; @@ -171,16 +165,14 @@ key.data = "TYPE"; key.size = (strlen("TYPE") + 1); state = db->get(db, &key, &value, 0); - if (state != 0) - { + if (state != 0) { if (state < 0) error = errno; else error = EFTYPE; goto failure; } - if (strcmp(value.data, "COLLATION") != 0) - { + if (strcmp(value.data, "COLLATION") != 0) { error = EFTYPE; goto failure; } @@ -188,8 +180,7 @@ key.data = "VERSION"; key.size = (strlen("VERSION") + 1); state = db->get(db, &key, &value, 0); - if (state != 0) - { + if (state != 0) { if (state < 0) error = errno; else @@ -216,19 +207,16 @@ DB *db = NULL; int error = 0; - if (colldb == NULL) - { + if (colldb == NULL) { errno = EINVAL; return (-1); } db = ((struct __colldb*)colldb)->handle; - if (db == NULL) - { + if (db == NULL) { errno = EINVAL; return (-1); } - if (db->close(db) == -1) - { + if (db->close(db) == -1) { error = errno; free(colldb); errno = error; @@ -244,14 +232,12 @@ { DB *db = NULL; - if (colldb == NULL) - { + if (colldb == NULL) { errno = EINVAL; return (-1); } db = ((struct __colldb*)colldb)->handle; - if (db == NULL) - { + if (db == NULL) { errno = EINVAL; return (-1); } @@ -273,21 +259,18 @@ uint32_t *keybuf = NULL; struct __colldb_weight *weights = NULL; - if ((colldb == NULL) || (key == NULL) || (value == NULL)) - { + if ((colldb == NULL) || (key == NULL) || (value == NULL)) { errno = EINVAL; return (-1); } db = ((struct __colldb*)colldb)->handle; - if ((db == NULL) || (key->chars == NULL) || (key->count == 0)) - { + if ((db == NULL) || (key->chars == NULL) || (key->count == 0)) { errno = EINVAL; return (-1); } keybuf = malloc(key->count * sizeof(*key->chars)); - if (keybuf == NULL) - { + if (keybuf == NULL) { errno = ENOMEM; return (-1); } @@ -297,8 +280,7 @@ dbkey.data = keybuf; dbkey.size = (key->count * sizeof(*key->chars)); state = db->get(db, &dbkey, &dbvalue, 0); - if (state != 0) - { + if (state != 0) { error = errno; free(keybuf); errno = error; @@ -306,15 +288,13 @@ } weights = dbvalue.data; - if ((dbvalue.size / sizeof(*weights)) > value->count) - { + if ((dbvalue.size / sizeof(*weights)) > value->count) { free(keybuf); errno = ERANGE; return (-1); } value->count = (dbvalue.size / sizeof(*weights)); - for (i = 0; i < value->count; ++i) - { + for (i = 0; i < value->count; ++i) { value->weights[i].alternate = weights[i].alternate; value->weights[i].level1 = ntohl(weights[i].level1); value->weights[i].level2 = ntohl(weights[i].level2); @@ -340,14 +320,12 @@ uint32_t *keybuf = NULL; struct __colldb_weight *valuebuf = NULL; - if ((colldb == NULL) || (key == NULL) || (value == NULL)) - { + if ((colldb == NULL) || (key == NULL) || (value == NULL)) { errno = EINVAL; return (-1); } db = ((struct __colldb*)colldb)->handle; - if ((db == NULL) || (key->chars == NULL) || (key->count == 0)) - { + if ((db == NULL) || (key->chars == NULL) || (key->count == 0)) { errno = EINVAL; return (-1); } @@ -355,15 +333,13 @@ valuebuf = value->weights; keybuf = malloc(key->count * sizeof(*key->chars)); valuebuf = malloc(value->count * sizeof(*value->weights)); - if ((keybuf == NULL) || (valuebuf == NULL)) - { + if ((keybuf == NULL) || (valuebuf == NULL)) { errno = ENOMEM; return (-1); } for (i = 0; i < key->count; ++i) keybuf[i] = htonl(key->chars[i]); - for (i = 0; i < value->count; ++i) - { + for (i = 0; i < value->count; ++i) { valuebuf[i].alternate = value->weights[i].alternate; valuebuf[i].level1 = htonl(value->weights[i].level1); valuebuf[i].level2 = htonl(value->weights[i].level2); @@ -376,8 +352,7 @@ dbkey.size = (key->count * sizeof(*key->chars)); dbvalue.size = (value->count * sizeof(*value->weights)); state = db->put(db, &dbkey, &dbvalue, 0); - if (state != 0) - { + if (state != 0) { error = errno; free(keybuf); free(valuebuf); Modified: soc2014/ghostmansd/head/lib/libc/unicode/uccclass.c ============================================================================== --- soc2014/ghostmansd/head/lib/libc/unicode/uccclass.c Tue Aug 12 23:22:38 2014 (r272311) +++ soc2014/ghostmansd/head/lib/libc/unicode/uccclass.c Tue Aug 12 23:29:29 2014 (r272312) @@ -37,9 +37,8 @@ high = COMBINING_CLASS_COUNT; if ((code <= COMBINING_CLASS_MIN) || (code >= COMBINING_CLASS_MAX)) - return 0; - while (low <= high) - { + return (0); + while (low <= high) { mid = (low + ((high - low) / 2)); if (code < combining_class[mid].code) high = (mid - 1); @@ -48,5 +47,5 @@ else return combining_class[mid].ccclass; } - return 0; + return (0); } Modified: soc2014/ghostmansd/head/lib/libc/unicode/ucscanon.c ============================================================================== --- soc2014/ghostmansd/head/lib/libc/unicode/ucscanon.c Tue Aug 12 23:22:38 2014 (r272311) +++ soc2014/ghostmansd/head/lib/libc/unicode/ucscanon.c Tue Aug 12 23:29:29 2014 (r272312) @@ -37,25 +37,22 @@ uint32_t cchr = 0; uint32_t lchr = 0; - if (!str) - { + if (!str) { errno = EINVAL; - return -1; + return (-1); } if ((str[0] == 0) || (str[1] == 0)) return 0; - for (++index; str[index] != 0; ++index) - { + for (++index; str[index] != 0; ++index) { cchr = str[index]; lchr = str[index - 1]; lcls = __uccclass(lchr); ccls = __uccclass(cchr); - if ((ccls != 0) && (lcls != 0) && (lcls > ccls)) - { + if ((ccls != 0) && (lcls != 0) && (lcls > ccls)) { str[index] = lchr; str[index - 1] = cchr; index -= ((index > 1) + 1); } } - return 0; + return (0); } Modified: soc2014/ghostmansd/head/lib/libc/unicode/ucscoll.c ============================================================================== --- soc2014/ghostmansd/head/lib/libc/unicode/ucscoll.c Tue Aug 12 23:22:38 2014 (r272311) +++ soc2014/ghostmansd/head/lib/libc/unicode/ucscoll.c Tue Aug 12 23:29:29 2014 (r272312) @@ -48,19 +48,16 @@ struct __colldb_weight weights[2][__COLLDB_WEIGHTS_MAX]; const int init_error = errno; - if ((lstr == NULL) || (rstr == NULL)) - { + if ((lstr == NULL) || (rstr == NULL)) { errno = EINVAL; return (0); } if (colldb == NULL) colldb = __colldb_root; - for (i = 0; i < 2; ++i) - { + for (i = 0; i < 2; ++i) { size[i] = __ucsnorm(NULL, str[i], 0, __UC_NFD); norm[i] = malloc(size[i] * sizeof(uint32_t)); - if (__ucsnorm(norm[i], str[i], size[i], __UC_NFD) > size[i]) - { + if (__ucsnorm(norm[i], str[i], size[i], __UC_NFD) > size[i]) { error = errno; free(norm[0]); free(norm[1]); @@ -72,22 +69,18 @@ if (colldb == NULL) colldb = __colldb_root; - while (*iter[0] != 0) - { - if (*iter[1] == 0) - { + while (*iter[0] != 0) { + if (*iter[1] == 0) { free(norm[0]); free(norm[1]); return (+1); } - for (i = 0; i < 2; ++i) - { + for (i = 0; i < 2; ++i) { val[i].weights = weights[i]; val[i].count = __COLLDB_WEIGHTS_MAX; shift[i] = __coll_iter(iter[0], colldb, &val[i], - default_weights[i]); - if (shift[i] == 0) - { + default_weights[i]); + if (shift[i] == 0) { error = errno; free(norm[0]); free(norm[1]); @@ -100,12 +93,10 @@ cmp = val[0].count; else cmp = val[1].count; - for (i = 0; i < cmp; ++i) - { + for (i = 0; i < cmp; ++i) { state = memcmp(&val[0].weights[i], &val[1].weights[i], - sizeof(struct __colldb_weight)); - if (state != 0) - { + sizeof(struct __colldb_weight)); + if (state != 0) { free(norm[0]); free(norm[1]); errno = init_error; Modified: soc2014/ghostmansd/head/lib/libc/unicode/ucsnorm.c ============================================================================== --- soc2014/ghostmansd/head/lib/libc/unicode/ucsnorm.c Tue Aug 12 23:22:38 2014 (r272311) +++ soc2014/ghostmansd/head/lib/libc/unicode/ucsnorm.c Tue Aug 12 23:29:29 2014 (r272312) @@ -42,17 +42,14 @@ *size = 1; high = NORMALIZATION_COUNT; - if (compat) - { - while (low <= high) - { + if (compat) { + while (low <= high) { mid = (low + ((high - low) / 2)); if (*code < normalization[mid].code) high = (mid - 1); else if (*code > normalization[mid].code) low = (mid + 1); - else - { + else { canonical = normalization[mid].canonical; compatible = normalization[mid].compatible; if ((canonical == -1) || (canonical == compatible)) @@ -61,18 +58,14 @@ return (decomposition + compatible); } } - } - else - { - while (low <= high) - { + } else { + while (low <= high) { mid = (low + ((high - low) / 2)); if (*code < normalization[mid].code) high = (mid - 1); else if (*code > normalization[mid].code) low = (mid + 1); - else - { + else { canonical = normalization[mid].canonical; if (canonical == -1) return (code); @@ -98,35 +91,27 @@ const uint32_t *iter = str; const uint32_t *segptr = segbuf; - for (; *iter != 0; ++iter) - { + for (; *iter != 0; ++iter) { code = *iter; segsize = 1; segptr = iter; - if ((HANGUL_SBASE <= code) && (code < (HANGUL_SBASE + HANGUL_SCOUNT))) - { + if ((HANGUL_SBASE <= code) && (code < (HANGUL_SBASE + HANGUL_SCOUNT))) { code -= HANGUL_SBASE; - if (code < HANGUL_SCOUNT) - { + if (code < HANGUL_SCOUNT) { segbuf[0] = (HANGUL_LBASE + (code / HANGUL_NCOUNT)); segbuf[1] = (HANGUL_VBASE + ((code % HANGUL_NCOUNT) / HANGUL_TCOUNT)); segbuf[2] = (HANGUL_TBASE + (code % HANGUL_TCOUNT)); segsize = ((segptr[2] == HANGUL_TBASE) ? 2 : 3); - } - else + } else segbuf[0] = *iter; - } - else if ((DECOMPOSITION_MIN <= code) && (code <= DECOMPOSITION_MAX)) - { + } else if ((DECOMPOSITION_MIN <= code) && (code <= DECOMPOSITION_MAX)) { segptr = decompose_base(&code, &segsize, compat); - if (segptr != &code) - { + if (segptr != &code) { segsize *= sizeof(uint32_t); memcpy(segbuf, segptr, segsize); segsize /= sizeof(uint32_t); segptr = segbuf; - while (tmpsize != segsize) - { + while (tmpsize != segsize) { tmpsize = segsize; tmpbuf[segsize] = 0; segsize *= sizeof(uint32_t); @@ -136,15 +121,13 @@ } } } - if (((reqsize + segsize + 1) > size) && (buffer != NULL)) - { + if (((reqsize + segsize + 1) > size) && (buffer != NULL)) { size = (size - reqsize - 1); memcpy(buffer, segptr, (size * sizeof(uint32_t))); *(buffer + size) = 0; return decompose(NULL, str, 0, compat); } - if (buffer != NULL) - { + if (buffer != NULL) { memcpy(buffer, segptr, (segsize * sizeof(uint32_t))); buffer += segsize; } @@ -170,19 +153,17 @@ /* Hangul L + V composition sequence. */ if (((HANGUL_LBASE <= lchr) && (lchr < (HANGUL_LBASE + HANGUL_LCOUNT))) - && ((HANGUL_VBASE <= cchr) && (cchr < (HANGUL_VBASE + HANGUL_VCOUNT)))) - { + && ((HANGUL_VBASE <= cchr) && (cchr < (HANGUL_VBASE + HANGUL_VCOUNT)))) { code += ((lchr - HANGUL_LBASE) * HANGUL_VCOUNT); code += (cchr - HANGUL_VBASE); code *= HANGUL_TCOUNT; code += HANGUL_SBASE; return (code); } - /* Hangul LV + T composition sequence. */ if ((((lchr - HANGUL_SBASE) % HANGUL_TCOUNT) == 0) - && ((HANGUL_SBASE <= lchr) && (lchr < (HANGUL_SBASE + HANGUL_SCOUNT))) - && ((HANGUL_TBASE <= cchr) && (cchr < (HANGUL_TBASE + HANGUL_TCOUNT)))) + && ((HANGUL_SBASE <= lchr) && (lchr < (HANGUL_SBASE + HANGUL_SCOUNT))) + && ((HANGUL_TBASE <= cchr) && (cchr < (HANGUL_TBASE + HANGUL_TCOUNT)))) return (lchr + (cchr - HANGUL_TBASE)); /* Generic composition sequence. */ @@ -190,15 +171,13 @@ pair = (((uint64_t)cchr << 32) | lchr); if ((pair < COMPOSITION_MIN) || (pair > COMPOSITION_MAX)) return (0); - while (low <= high) - { + while (low <= high) { mid = (low + ((high - low) / 2)); if (pair < composition[mid].pair) high = (mid - 1); else if (pair > composition[mid].pair) high = (mid + 1); - else - { + else { index = composition[mid].index; return (normalization[index].code); } @@ -224,40 +203,33 @@ xlen = decompose(NULL, str, 0, compat); data = malloc(xlen * sizeof(uint32_t)); - if (data == NULL) - { + if (data == NULL) { errno = ENOMEM; return (SIZE_MAX); } - (void) decompose(data, NULL, xlen, compat); - (void) __ucscanon(data); + (void)decompose(data, NULL, xlen, compat); + (void)__ucscanon(data); len = --xlen; lchr = data[0]; lcls = __uccclass(lchr); if (lcls != 0) lcls = 255; - for (; dpos < len; ++dpos) - { + for (; dpos < len; ++dpos) { cchr = data[dpos]; ccls = __uccclass(cchr); code = compose_base(lchr, cchr); - if ((code != 0) && ((lcls < ccls) || (lcls == 0))) - { + if ((code != 0) && ((lcls < ccls) || (lcls == 0))) { data[spos] = code; lchr = code; - } - else - { - if (ccls == 0) - { + } else { + if (ccls == 0) { spos = cpos; lchr = cchr; } lcls = ccls; data[cpos] = cchr; - if (len != xlen) - { + if (len != xlen) { dpos += (len - xlen); xlen = len; } @@ -268,8 +240,7 @@ xlen = ((size >= (len + 1)) ? len : size); if (buffer != NULL) memcpy(buffer, data, (xlen * sizeof(uint32_t))); - if ((buffer == NULL) || (size < (len + 1))) - { + if ((buffer == NULL) || (size < (len + 1))) { if (buffer != NULL) buffer[--xlen] = 0; errno = ERANGE; @@ -285,15 +256,12 @@ size_t __ucsnorm(uint32_t *buffer, const uint32_t *str, size_t size, int form) { - if (!str || (buffer && !size)) - { + if (!str || (buffer && !size)) { errno = EINVAL; return (SIZE_MAX); } - if (*str == 0) - { - if (size == 0) - { + if (*str == 0) { + if (size == 0) { errno = EINVAL; return (SIZE_MAX); } Modified: soc2014/ghostmansd/head/lib/libc/unicode/ucsxfrm.c ============================================================================== --- soc2014/ghostmansd/head/lib/libc/unicode/ucsxfrm.c Tue Aug 12 23:22:38 2014 (r272311) +++ soc2014/ghostmansd/head/lib/libc/unicode/ucsxfrm.c Tue Aug 12 23:29:29 2014 (r272312) @@ -31,7 +31,7 @@ size_t __ucsxfrm(uint32_t *buffer, const uint32_t *str, size_t size, - void *colldb) + void *colldb) { size_t i = 0; int error = 0; @@ -47,8 +47,7 @@ struct __colldb_weight weights[__COLLDB_WEIGHTS_MAX]; const int init_error = errno; - if ((str == NULL) || ((buffer != NULL) && (size == 0))) - { + if ((str == NULL) || ((buffer != NULL) && (size == 0))) { errno = EINVAL; return (SIZE_MAX); } @@ -56,48 +55,40 @@ colldb = __colldb_root; normsize = __ucsnorm(NULL, str, 0, __UC_NFD); norm = malloc(normsize * sizeof(uint32_t)); - if (norm == NULL) - { + if (norm == NULL) { errno = ENOMEM; return (SIZE_MAX); } - if (__ucsnorm(norm, str, normsize, __UC_NFD) > normsize) - { + if (__ucsnorm(norm, str, normsize, __UC_NFD) > normsize) { error = errno; free(norm); errno = error; return (SIZE_MAX); } - iter = norm; if (colldb == NULL) colldb = __colldb_root; - while (*iter != 0) - { + while (*iter != 0) { value.weights = weights; value.count = __COLLDB_WEIGHTS_MAX; shift = __coll_iter(iter, colldb, &value, default_weights); - if (shift == 0) - { + if (shift == 0) { error = errno; free(elements); free(norm); errno = error; return (SIZE_MAX); } - free(elements); count = (value.count * 4); elements = malloc(count * sizeof(uint32_t)); - if (elements == NULL) - { + if (elements == NULL) { free(elements); free(norm); errno = ENOMEM; return (SIZE_MAX); } - for (i = 0; i < value.count; ++i) - { + for (i = 0; i < value.count; ++i) { elements[(count * 0) + i] = value.weights[i].level1; elements[(count * 1) + i] = value.weights[i].level2; elements[(count * 2) + i] = value.weights[i].level3; @@ -106,8 +97,7 @@ for (i = 0; i < count; ++i) elements[i] = (elements[i] ? elements[i] : 1); - if (((reqsize + count) > size) && (buffer != NULL)) - { + if (((reqsize + count) > size) && (buffer != NULL)) { count = (size - reqsize - 1); memcpy(buffer, elements, (count * sizeof(uint32_t))); *(buffer + count) = 0; @@ -115,8 +105,7 @@ free(norm); return __ucsxfrm(NULL, str, 0, colldb); } - if (buffer != NULL) - { + if (buffer != NULL) { memcpy(buffer, elements, (count * sizeof(uint32_t))); buffer += count; }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201408122329.s7CNTT46020047>