summaryrefslogtreecommitdiff
path: root/extra/locale
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-12-22 14:51:20 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-12-22 14:51:20 +0000
commitef9bd8dd3a1a6922839db782157e3f40f3411f32 (patch)
tree1b497cb2fc7590d07d3ea9a9432f2eb84c21864a /extra/locale
parent1ad544a2ade2d8adcebc20de065bfafd7cd507a5 (diff)
extra/locale/gen_wctype.c: remove __CTYPE_isalnum and friends;
stop using macros with hidden parameter - that's evil; reformat broken indenting (it was not matching the number of {}s); fix format warnings (int vs size_t vs long) No code changes (verified with objdump)
Diffstat (limited to 'extra/locale')
-rw-r--r--extra/locale/gen_wctype.c733
1 files changed, 354 insertions, 379 deletions
diff --git a/extra/locale/gen_wctype.c b/extra/locale/gen_wctype.c
index 978dbe836..fde30a0a5 100644
--- a/extra/locale/gen_wctype.c
+++ b/extra/locale/gen_wctype.c
@@ -67,35 +67,20 @@
/* Some macros that test for various (w)ctype classes when passed one of the
* designator values enumerated above. */
-#define __CTYPE_isalnum(D) ((unsigned int)(D-1) <= (__CTYPE_digit-1))
-#define __CTYPE_isalpha(D) ((unsigned int)(D-1) <= (__CTYPE_alpha_upper-1))
-#define __CTYPE_isblank(D) \
- ((((unsigned int)(D - __CTYPE_print_space_nonblank)) <= 5) && (D & 1))
-#define __CTYPE_iscntrl(D) (((unsigned int)(D - __CTYPE_cntrl_space_nonblank)) <= 2)
-#define __CTYPE_isdigit(D) (D == __CTYPE_digit)
-#define __CTYPE_isgraph(D) ((unsigned int)(D-1) <= (__CTYPE_graph-1))
-#define __CTYPE_islower(D) (((unsigned int)(D - __CTYPE_alpha_lower)) <= 1)
-#define __CTYPE_isprint(D) ((unsigned int)(D-1) <= (__CTYPE_print_space_blank-1))
-#define __CTYPE_ispunct(D) (D == __CTYPE_punct)
-#define __CTYPE_isspace(D) (((unsigned int)(D - __CTYPE_print_space_nonblank)) <= 5)
-#define __CTYPE_isupper(D) (((unsigned int)(D - __CTYPE_alpha_upper_lower)) <= 1)
-/* #define __CTYPE_isxdigit(D) -- isxdigit is untestable this way.
- * But that's ok as isxdigit() (and isdigit() too) are locale-invariant. */
-#define __CTYPE_isxdigit(D,X) \
- (__CTYPE_isdigit(D) || (((unsigned int)(((X)|0x20) - 'a')) <= 5))
-
-#define mywalnum(x) __CTYPE_isalnum(d)
-#define mywalpha(x) __CTYPE_isalpha(d)
-#define mywblank(x) __CTYPE_isblank(d)
-#define mywcntrl(x) __CTYPE_iscntrl(d)
-#define mywdigit(x) __CTYPE_isdigit(d)
-#define mywgraph(x) __CTYPE_isgraph(d)
-#define mywlower(x) __CTYPE_islower(d)
-#define mywprint(x) __CTYPE_isprint(d)
-#define mywpunct(x) __CTYPE_ispunct(d)
-#define mywspace(x) __CTYPE_isspace(d)
-#define mywupper(x) __CTYPE_isupper(d)
-#define mywxdigit(x) __CTYPE_isxdigit(d,x)
+#define mywalnum(D,C) ((unsigned)(D - 1) <= (__CTYPE_digit - 1))
+#define mywalpha(D,C) ((unsigned)(D - 1) <= (__CTYPE_alpha_upper - 1))
+#define mywblank(D,C) ((unsigned)(D - __CTYPE_print_space_nonblank) <= 5 && (D & 1))
+#define mywcntrl(D,C) ((unsigned)(D - __CTYPE_cntrl_space_nonblank) <= 2)
+#define mywdigit(D,C) (D == __CTYPE_digit)
+#define mywgraph(D,C) ((unsigned)(D - 1) <= (__CTYPE_graph - 1))
+#define mywlower(D,C) ((unsigned)(D - __CTYPE_alpha_lower) <= 1)
+#define mywprint(D,C) ((unsigned)(D - 1) <= (__CTYPE_print_space_blank - 1))
+#define mywpunct(D,C) (D == __CTYPE_punct)
+#define mywspace(D,C) ((unsigned)(D - __CTYPE_print_space_nonblank) <= 5)
+#define mywupper(D,C) ((unsigned)(D - __CTYPE_alpha_upper_lower) <= 1)
+/* #define mywxdigit(D,C) -- isxdigit is untestable this way.
+ * But that's ok as isxdigit() (and isdigit() too) are locale-invariant. */
+#define mywxdigit(D,C) (mywdigit(D,C) || (unsigned)(((C) | 0x20) - 'a') <= 5)
typedef struct {
short l;
@@ -133,19 +118,19 @@ void output_table(FILE *fp, const char *name, table_data *tbl)
i = tbl->ii_len + tbl->ti_len + tbl->ut_len;
fprintf(fp, "\nstatic const unsigned char __LOCALE_DATA_WC%s_data[%zu] = {", name, i);
- for (i=0 ; i < tbl->ii_len ; i++) {
+ for (i = 0; i < tbl->ii_len; i++) {
if (i % 12 == 0) {
fprintf(fp, "\n");
}
fprintf(fp, " %#04x,", tbl->ii[i]);
}
- for (i=0 ; i < tbl->ti_len ; i++) {
+ for (i = 0; i < tbl->ti_len; i++) {
if (i % 12 == 0) {
fprintf(fp, "\n");
}
fprintf(fp, " %#04x,", tbl->ti[i]);
}
- for (i=0 ; i < tbl->ut_len ; i++) {
+ for (i = 0; i < tbl->ut_len; i++) {
if (i % 12 == 0) {
fprintf(fp, "\n");
}
@@ -208,7 +193,7 @@ int main(int argc, char **argv)
#define INIT_TYPENAME(X) typename[__CTYPE_##X] = "C_" #X
- for (i=0 ; i < 16 ; i++) {
+ for (i = 0; i < 16; i++) {
typename[i] = empty_slot;
}
@@ -231,8 +216,8 @@ int main(int argc, char **argv)
memset(&cttable, 0, sizeof(table_data));
memset(&ultable, 0, sizeof(table_data));
#if 0
- memset(combtable, 0, sizeof table_data);
- memset(widthtable, 0, sizeof table_data);
+ memset(combtable, 0, sizeof(table_data));
+ memset(widthtable, 0, sizeof(table_data));
#endif
setvbuf(stdout, NULL, _IONBF, 0);
@@ -241,7 +226,8 @@ int main(int argc, char **argv)
if (!strcmp(*argv, "-v")) {
++verbose;
continue;
- } else if (!setlocale(LC_CTYPE, *argv)) {
+ }
+ if (!setlocale(LC_CTYPE, *argv)) {
verbose_msg("setlocale(LC_CTYPE,%s) failed! Skipping this locale...\n", *argv);
continue;
}
@@ -257,324 +243,316 @@ int main(int argc, char **argv)
}
if (!built) {
- built = 1;
- ul_count = 1;
- uldiff[0].u = uldiff[0].l = 0;
+ built = 1;
+ ul_count = 1;
+ uldiff[0].u = uldiff[0].l = 0;
- memset(wct, 0, sizeof(wct));
- memset(combt, 0, sizeof(combt));
- memset(widtht, 0, sizeof(widtht));
+ memset(wct, 0, sizeof(wct));
+ memset(combt, 0, sizeof(combt));
+ memset(widtht, 0, sizeof(widtht));
- for (i = 0 ; i < 16 ; i++) {
- typecount[i] = 0;
- }
+ for (i = 0; i < 16; i++) {
+ typecount[i] = 0;
+ }
- for (c=0 ; c <= RANGE ; c++) {
- if (iswdigit(c)) {
- d = __CTYPE_digit;
- } else if (iswalpha(c)) {
- d = __CTYPE_alpha_nonupper_nonlower;
- if (iswlower(c)) {
- d = __CTYPE_alpha_lower;
- if (iswupper(c)) {
- d = __CTYPE_alpha_upper_lower;
+ for (c = 0; c <= RANGE; c++) {
+ if (iswdigit(c)) {
+ d = __CTYPE_digit;
+ } else if (iswalpha(c)) {
+ d = __CTYPE_alpha_nonupper_nonlower;
+ if (iswlower(c)) {
+ d = __CTYPE_alpha_lower;
+ if (iswupper(c)) {
+ d = __CTYPE_alpha_upper_lower;
+ }
+ } else if (iswupper(c)) {
+ d = __CTYPE_alpha_upper;
}
- } else if (iswupper(c)) {
- d = __CTYPE_alpha_upper;
- }
- } else if (iswpunct(c)) {
- d = __CTYPE_punct;
- } else if (iswgraph(c)) {
- d = __CTYPE_graph;
- } else if (iswprint(c)) {
- d = __CTYPE_print_space_nonblank;
- if (iswblank(c)) {
- d = __CTYPE_print_space_blank;
- }
- } else if (iswspace(c) && !iswcntrl(c)) {
- d = __CTYPE_space_nonblank_noncntrl;
- if (iswblank(c)) {
- d = __CTYPE_space_blank_noncntrl;
- }
- } else if (iswcntrl(c)) {
- d = __CTYPE_cntrl_nonspace;
- if (iswspace(c)) {
- d = __CTYPE_cntrl_space_nonblank;
+ } else if (iswpunct(c)) {
+ d = __CTYPE_punct;
+ } else if (iswgraph(c)) {
+ d = __CTYPE_graph;
+ } else if (iswprint(c)) {
+ d = __CTYPE_print_space_nonblank;
+ if (iswblank(c)) {
+ d = __CTYPE_print_space_blank;
+ }
+ } else if (iswspace(c) && !iswcntrl(c)) {
+ d = __CTYPE_space_nonblank_noncntrl;
if (iswblank(c)) {
- d = __CTYPE_cntrl_space_blank;
+ d = __CTYPE_space_blank_noncntrl;
}
+ } else if (iswcntrl(c)) {
+ d = __CTYPE_cntrl_nonspace;
+ if (iswspace(c)) {
+ d = __CTYPE_cntrl_space_nonblank;
+ if (iswblank(c)) {
+ d = __CTYPE_cntrl_space_blank;
+ }
+ }
+ } else {
+ d = __CTYPE_unclassified;
}
- } else {
- d = __CTYPE_unclassified;
- }
-
- ++typecount[d];
+ ++typecount[d];
#if 0
- if (iswspace(c)) {
- if (iswblank(c)) {
- verbose_msg("%#8x : space blank\n", c);
- } else {
- verbose_msg("%#8x : space\n", c);
+ if (iswspace(c)) {
+ if (iswblank(c)) {
+ verbose_msg("%#8x : space blank\n", c);
+ } else {
+ verbose_msg("%#8x : space\n", c);
+ }
}
- }
#endif
-
#if 0
- if (c < 256) {
- unsigned int glibc;
-
- glibc = 0;
- if (isalnum(c)) ++glibc; glibc <<= 1;
- if (isalpha(c)) ++glibc; glibc <<= 1;
- if (isblank(c)) ++glibc; glibc <<= 1;
- if (iscntrl(c)) ++glibc; glibc <<= 1;
- if (isdigit(c)) ++glibc; glibc <<= 1;
- if (isgraph(c)) ++glibc; glibc <<= 1;
- if (islower(c)) ++glibc; glibc <<= 1;
- if (isprint(c)) ++glibc; glibc <<= 1;
- if (ispunct(c)) ++glibc; glibc <<= 1;
- if (isspace(c)) ++glibc; glibc <<= 1;
- if (isupper(c)) ++glibc; glibc <<= 1;
- if (isxdigit(c)) ++glibc;
- verbose_msg("%#8x : ctype %#4x\n", c, glibc);
- }
+ if (c < 256) {
+ unsigned int glibc;
+
+ glibc = 0;
+ if (isalnum(c)) ++glibc; glibc <<= 1;
+ if (isalpha(c)) ++glibc; glibc <<= 1;
+ if (isblank(c)) ++glibc; glibc <<= 1;
+ if (iscntrl(c)) ++glibc; glibc <<= 1;
+ if (isdigit(c)) ++glibc; glibc <<= 1;
+ if (isgraph(c)) ++glibc; glibc <<= 1;
+ if (islower(c)) ++glibc; glibc <<= 1;
+ if (isprint(c)) ++glibc; glibc <<= 1;
+ if (ispunct(c)) ++glibc; glibc <<= 1;
+ if (isspace(c)) ++glibc; glibc <<= 1;
+ if (isupper(c)) ++glibc; glibc <<= 1;
+ if (isxdigit(c)) ++glibc;
+ verbose_msg("%#8x : ctype %#4x\n", c, glibc);
+ }
#endif
-
#if 1
- /* Paranoid checking... */
- {
- unsigned int glibc;
- unsigned int mine;
-
- glibc = 0;
- if (iswalnum(c)) ++glibc; glibc <<= 1;
- if (iswalpha(c)) ++glibc; glibc <<= 1;
- if (iswblank(c)) ++glibc; glibc <<= 1;
- if (iswcntrl(c)) ++glibc; glibc <<= 1;
- if (iswdigit(c)) ++glibc; glibc <<= 1;
- if (iswgraph(c)) ++glibc; glibc <<= 1;
- if (iswlower(c)) ++glibc; glibc <<= 1;
- if (iswprint(c)) ++glibc; glibc <<= 1;
- if (iswpunct(c)) ++glibc; glibc <<= 1;
- if (iswspace(c)) ++glibc; glibc <<= 1;
- if (iswupper(c)) ++glibc; glibc <<= 1;
- if (iswxdigit(c)) ++glibc;
-
- mine = 0;
- if (mywalnum(c)) ++mine; mine <<= 1;
- if (mywalpha(c)) ++mine; mine <<= 1;
- if (mywblank(c)) ++mine; mine <<= 1;
- if (mywcntrl(c)) ++mine; mine <<= 1;
- if (mywdigit(c)) ++mine; mine <<= 1;
- if (mywgraph(c)) ++mine; mine <<= 1;
- if (mywlower(c)) ++mine; mine <<= 1;
- if (mywprint(c)) ++mine; mine <<= 1;
- if (mywpunct(c)) ++mine; mine <<= 1;
- if (mywspace(c)) ++mine; mine <<= 1;
- if (mywupper(c)) ++mine; mine <<= 1;
- if (mywxdigit(c)) ++mine;
-
- if (glibc != mine) {
- verbose_msg("%#8x : glibc %#4x != %#4x mine %u\n", c, glibc, mine, d);
- return EXIT_FAILURE;
- }
-
+ /* Paranoid checking... */
+ {
+ unsigned int glibc;
+ unsigned int mine;
+
+ glibc = 0;
+ if (iswalnum(c)) ++glibc; glibc <<= 1;
+ if (iswalpha(c)) ++glibc; glibc <<= 1;
+ if (iswblank(c)) ++glibc; glibc <<= 1;
+ if (iswcntrl(c)) ++glibc; glibc <<= 1;
+ if (iswdigit(c)) ++glibc; glibc <<= 1;
+ if (iswgraph(c)) ++glibc; glibc <<= 1;
+ if (iswlower(c)) ++glibc; glibc <<= 1;
+ if (iswprint(c)) ++glibc; glibc <<= 1;
+ if (iswpunct(c)) ++glibc; glibc <<= 1;
+ if (iswspace(c)) ++glibc; glibc <<= 1;
+ if (iswupper(c)) ++glibc; glibc <<= 1;
+ if (iswxdigit(c)) ++glibc;
+
+ mine = 0;
+ if (mywalnum(d,c)) ++mine; mine <<= 1;
+ if (mywalpha(d,c)) ++mine; mine <<= 1;
+ if (mywblank(d,c)) ++mine; mine <<= 1;
+ if (mywcntrl(d,c)) ++mine; mine <<= 1;
+ if (mywdigit(d,c)) ++mine; mine <<= 1;
+ if (mywgraph(d,c)) ++mine; mine <<= 1;
+ if (mywlower(d,c)) ++mine; mine <<= 1;
+ if (mywprint(d,c)) ++mine; mine <<= 1;
+ if (mywpunct(d,c)) ++mine; mine <<= 1;
+ if (mywspace(d,c)) ++mine; mine <<= 1;
+ if (mywupper(d,c)) ++mine; mine <<= 1;
+ if (mywxdigit(d,c)) ++mine;
+
+ if (glibc != mine) {
+ verbose_msg("%#8x : glibc %#4x != %#4x mine %u\n", c, glibc, mine, d);
+ return EXIT_FAILURE;
+ }
#if 0
- if (iswctype(c,is_comb) || iswctype(c,is_comb3)) {
-/* if (!iswpunct(c)) { */
- verbose_msg("%#8x : %d %d %#4x\n",
- c, iswctype(c,is_comb),iswctype(c,is_comb3), glibc);
-/* } */
- }
+ if (iswctype(c,is_comb) || iswctype(c,is_comb3)) {
+/* if (!iswpunct(c)) { */
+ verbose_msg("%#8x : %d %d %#4x\n",
+ c, iswctype(c,is_comb),iswctype(c,is_comb3), glibc);
+/* } */
+ }
#endif
#if 0
- if (iswctype(c,is_comb) || iswctype(c,is_comb3)) {
- if (!last_comb) {
- verbose_msg("%#8x - ", c);
- last_comb = c;
- } else if (last_comb + 1 < c) {
- verbose_msg("%#8x\n%#8x - ", last_comb, c);
- last_comb = c;
- } else {
- last_comb = c;
+ if (iswctype(c,is_comb) || iswctype(c,is_comb3)) {
+ if (!last_comb) {
+ verbose_msg("%#8x - ", c);
+ last_comb = c;
+ } else if (last_comb + 1 < c) {
+ verbose_msg("%#8x\n%#8x - ", last_comb, c);
+ last_comb = c;
+ } else {
+ last_comb = c;
+ }
}
- }
#endif
- }
+ }
#endif
- combt[c/4] |= ((((!!iswctype(c,is_comb)) << 1) | !!iswctype(c,is_comb3))
+ combt[c/4] |= ((((!!iswctype(c,is_comb)) << 1) | !!iswctype(c,is_comb3))
<< ((c & 3) << 1));
-/* comb3t[c/8] |= ((!!iswctype(c,is_comb3)) << (c & 7)); */
+/* comb3t[c/8] |= ((!!iswctype(c,is_comb3)) << (c & 7)); */
-/* widtht[c/4] |= (wcwidth(c) << ((c & 3) << 1)); */
+/* widtht[c/4] |= (wcwidth(c) << ((c & 3) << 1)); */
- if (c & 1) { /* Use the high nibble for odd numbered wchars. */
- d <<= 4;
- }
- wct[c/2] |= d;
-
- l = (long)(int) towlower(c) - c;
- u = (long)(int) towupper(c) - c;
- ult[c] = 0;
- if (l || u) {
- if ((l != (short)l) || (u != (short)u)) {
- verbose_msg("range assumption error! %x %ld %ld\n", c, l, u);
- return EXIT_FAILURE;
+ if (c & 1) { /* Use the high nibble for odd numbered wchars. */
+ d <<= 4;
}
- for (i=0 ; i < ul_count ; i++) {
- if ((l == uldiff[i].l) && (u == uldiff[i].u)) {
- goto found;
+ wct[c/2] |= d;
+
+ l = (long)(int) towlower(c) - c;
+ u = (long)(int) towupper(c) - c;
+ ult[c] = 0;
+ if (l || u) {
+ if ((l != (short)l) || (u != (short)u)) {
+ verbose_msg("range assumption error! %x %ld %ld\n", c, l, u);
+ return EXIT_FAILURE;
}
+ for (i = 0; i < ul_count; i++) {
+ if ((l == uldiff[i].l) && (u == uldiff[i].u)) {
+ goto found;
+ }
+ }
+ uldiff[ul_count].l = l;
+ uldiff[ul_count].u = u;
+ ++ul_count;
+ if (ul_count > MAXTO) {
+ verbose_msg("too many touppers/tolowers!\n");
+ return EXIT_FAILURE;
+ }
+ found:
+ ult[c] = i;
}
- uldiff[ul_count].l = l;
- uldiff[ul_count].u = u;
- ++ul_count;
- if (ul_count > MAXTO) {
- verbose_msg("too many touppers/tolowers!\n");
- return EXIT_FAILURE;
- }
- found:
- ult[c] = i;
}
- }
-
- for (i = 0 ; i < 16 ; i++) {
- verbose_msg("typecount[%2d] = %8ld %s\n", i, typecount[i], typename[i]);
- }
- verbose_msg("optimizing is* table..\n");
- n = -1;
- smallest = SIZE_MAX;
- cttable.ii = NULL;
- for (i=0 ; i < 14 ; i++) {
- t = newopt(wct, (RANGE/2)+1, i, &cttable);
- if (smallest >= t) {
- n = i;
- smallest = t;
-/* } else { */
-/* break; */
+ for (i = 0; i < 16; i++) {
+ verbose_msg("typecount[%2d] = %8ld %s\n", i, typecount[i], typename[i]);
}
- }
- verbose_msg("smallest = %zu\n", smallest);
- if (!(cttable.ii = malloc(smallest))) {
- verbose_msg("couldn't allocate space!\n");
- return EXIT_FAILURE;
- }
- smallest = SIZE_MAX;
- newopt(wct, (RANGE/2)+1, n, &cttable);
- ++cttable.ti_shift; /* correct for nibble mode */
-
-
- verbose_msg("optimizing u/l-to table..\n");
- smallest = SIZE_MAX;
- ultable.ii = NULL;
- for (i=0 ; i < 14 ; i++) {
- t = newopt(ult, RANGE+1, i, &ultable);
- if (smallest >= t) {
- n = i;
- smallest = t;
-/* } else { */
-/* break; */
+ verbose_msg("optimizing is* table..\n");
+ n = -1;
+ smallest = SIZE_MAX;
+ cttable.ii = NULL;
+ for (i = 0; i < 14; i++) {
+ t = newopt(wct, (RANGE/2)+1, i, &cttable);
+ if (smallest >= t) {
+ n = i;
+ smallest = t;
+/* } else { */
+/* break; */
+ }
}
- }
- verbose_msg("%zu (smallest) + %zu (u/l diffs) = %zu\n",
- smallest, 4 * ul_count, smallest + 4 * ul_count);
- verbose_msg("smallest = %zu\n", smallest);
- if (!(ultable.ii = malloc(smallest))) {
- verbose_msg("couldn't allocate space!\n");
- return EXIT_FAILURE;
- }
- smallest = SIZE_MAX;
- newopt(ult, RANGE+1, n, &ultable);
-
-
+ verbose_msg("smallest = %zu\n", smallest);
+ if (!(cttable.ii = malloc(smallest))) {
+ verbose_msg("couldn't allocate space!\n");
+ return EXIT_FAILURE;
+ }
+ smallest = SIZE_MAX;
+ newopt(wct, (RANGE/2)+1, n, &cttable);
+ ++cttable.ti_shift; /* correct for nibble mode */
+
+ verbose_msg("optimizing u/l-to table..\n");
+ smallest = SIZE_MAX;
+ ultable.ii = NULL;
+ for (i = 0; i < 14; i++) {
+ t = newopt(ult, RANGE+1, i, &ultable);
+ if (smallest >= t) {
+ n = i;
+ smallest = t;
+/* } else { */
+/* break; */
+ }
+ }
+ verbose_msg("%lu (smallest) + %lu (u/l diffs) = %lu\n",
+ (unsigned long) smallest,
+ (unsigned long) (4 * ul_count),
+ (unsigned long) (smallest + 4 * ul_count)
+ );
+ verbose_msg("smallest = %zu\n", smallest);
+ if (!(ultable.ii = malloc(smallest))) {
+ verbose_msg("couldn't allocate space!\n");
+ return EXIT_FAILURE;
+ }
+ smallest = SIZE_MAX;
+ newopt(ult, RANGE+1, n, &ultable);
#if 0
- verbose_msg("optimizing comb table..\n");
- smallest = SIZE_MAX;
- combtable.ii = NULL;
- for (i=0 ; i < 14 ; i++) {
- t = newopt(combt, sizeof(combt), i, &combtable);
- if (smallest >= t) {
- n = i;
- smallest = t;
-/* } else { */
-/* break; */
+ verbose_msg("optimizing comb table..\n");
+ smallest = SIZE_MAX;
+ combtable.ii = NULL;
+ for (i = 0; i < 14; i++) {
+ t = newopt(combt, sizeof(combt), i, &combtable);
+ if (smallest >= t) {
+ n = i;
+ smallest = t;
+/* } else { */
+/* break; */
+ }
}
- }
- verbose_msg("smallest = %zu\n", smallest);
- if (!(combtable.ii = malloc(smallest))) {
- verbose_msg("couldn't allocate space!\n");
- return EXIT_FAILURE;
- }
- smallest = SIZE_MAX;
- newopt(combt, sizeof(combt), n, &combtable);
- combtable.ti_shift += 4; /* correct for 4 entries per */
+ verbose_msg("smallest = %zu\n", smallest);
+ if (!(combtable.ii = malloc(smallest))) {
+ verbose_msg("couldn't allocate space!\n");
+ return EXIT_FAILURE;
+ }
+ smallest = SIZE_MAX;
+ newopt(combt, sizeof(combt), n, &combtable);
+ combtable.ti_shift += 4; /* correct for 4 entries per */
#endif
-
-
#if 0
- verbose_msg("optimizing width table..\n");
- smallest = SIZE_MAX;
- widthtable.ii = NULL;
- for (i=0 ; i < 14 ; i++) {
- t = newopt(widtht, sizeof(widtht), i, &widthtable);
- if (smallest >= t) {
- n = i;
- smallest = t;
-/* } else { */
-/* break; */
+ verbose_msg("optimizing width table..\n");
+ smallest = SIZE_MAX;
+ widthtable.ii = NULL;
+ for (i = 0; i < 14; i++) {
+ t = newopt(widtht, sizeof(widtht), i, &widthtable);
+ if (smallest >= t) {
+ n = i;
+ smallest = t;
+/* } else { */
+/* break; */
+ }
}
- }
- verbose_msg("smallest = %zu\n", smallest);
- if (!(widthtable.ii = malloc(smallest))) {
- verbose_msg("couldn't allocate space!\n");
- return EXIT_FAILURE;
- }
- smallest = SIZE_MAX;
- newopt(widtht, sizeof(widtht), n, &widthtable);
- widthtable.ti_shift += 4; /* correct for 4 entries per */
+ verbose_msg("smallest = %zu\n", smallest);
+ if (!(widthtable.ii = malloc(smallest))) {
+ verbose_msg("couldn't allocate space!\n");
+ return EXIT_FAILURE;
+ }
+ smallest = SIZE_MAX;
+ newopt(widtht, sizeof(widtht), n, &widthtable);
+ widthtable.ti_shift += 4; /* correct for 4 entries per */
#endif
-
#if 0
- verbose_msg("optimizing comb3 table..\n");
- smallest = SIZE_MAX;
- comb3table.ii = NULL;
- for (i=0 ; i < 14 ; i++) {
- t = newopt(comb3t, sizeof(comb3t), i, &comb3table);
- if (smallest >= t) {
- n = i;
- smallest = t;
-/* } else { */
-/* break; */
+ verbose_msg("optimizing comb3 table..\n");
+ smallest = SIZE_MAX;
+ comb3table.ii = NULL;
+ for (i = 0; i < 14; i++) {
+ t = newopt(comb3t, sizeof(comb3t), i, &comb3table);
+ if (smallest >= t) {
+ n = i;
+ smallest = t;
+/* } else { */
+/* break; */
+ }
}
- }
- verbose_msg("smallest = %zu\n", smallest);
- if (!(comb3table.ii = malloc(smallest))) {
- verbose_msg("couldn't allocate space!\n");
- return EXIT_FAILURE;
- }
- smallest = SIZE_MAX;
- newopt(comb3t, sizeof(comb3t), n, &comb3table);
- comb3table.ti_shift += 8; /* correct for 4 entries per */
+ verbose_msg("smallest = %zu\n", smallest);
+ if (!(comb3table.ii = malloc(smallest))) {
+ verbose_msg("couldn't allocate space!\n");
+ return EXIT_FAILURE;
+ }
+ smallest = SIZE_MAX;
+ newopt(comb3t, sizeof(comb3t), n, &comb3table);
+ comb3table.ti_shift += 8; /* correct for 4 entries per */
#endif
- dump_table_data(&cttable);
- dump_table_data(&ultable);
+ dump_table_data(&cttable);
+ dump_table_data(&ultable);
#if 0
- dump_table_data(&combtable);
+ dump_table_data(&combtable);
#endif
}
verbose_msg("verifying for %s...\n", *argv);
#if RANGE == 0xffffU
- for (c=0 ; c <= 0xffffUL ; c++)
+ for (c = 0; c <= 0xffffUL; c++)
#else
- for (c=0 ; c <= 0x10ffffUL ; c++)
+ for (c = 0; c <= 0x10ffffUL; c++)
#endif
- {
+ {
unsigned int glibc;
unsigned int mine;
unsigned int upper, lower;
@@ -590,7 +568,6 @@ int main(int argc, char **argv)
}
#endif
#endif
-
glibc = 0;
if (iswalnum(c)) ++glibc; glibc <<= 1;
if (iswalpha(c)) ++glibc; glibc <<= 1;
@@ -607,8 +584,8 @@ int main(int argc, char **argv)
{
unsigned int u;
- int n, sc;
- int i0, i1;
+ int n = 0, sc = 0; /* = 0 for verbose_msg only */
+ int i0 = 0, i1 = 0;
u = c;
if (u <= RANGE) {
@@ -620,16 +597,16 @@ int main(int argc, char **argv)
i0 = cttable.ii[u];
i0 <<= cttable.ii_shift;
i1 = cttable.ti[i0 + n];
- i1 <<= (cttable.ti_shift-1);
+ i1 <<= (cttable.ti_shift - 1);
d = cttable.ut[i1 + (sc >> 1)];
if (sc & 1) {
d >>= 4;
}
d &= 0x0f;
- } else if ((((unsigned int)(c - 0xe0020UL)) <= 0x5f) || (c == 0xe0001UL)){
+ } else if (((unsigned)(c - 0xe0020UL) <= 0x5f) || (c == 0xe0001UL)) {
d = __CTYPE_punct;
- } else if (((unsigned int)(c - 0xf0000UL)) < 0x20000UL) {
+ } else if ((unsigned)(c - 0xf0000UL) < 0x20000UL) {
if ((c & 0xffffU) <= 0xfffdU) {
d = __CTYPE_punct;
} else {
@@ -639,26 +616,27 @@ int main(int argc, char **argv)
d = __CTYPE_unclassified;
}
- mine = 0;
- if (mywalnum(c)) ++mine; mine <<= 1;
- if (mywalpha(c)) ++mine; mine <<= 1;
- if (mywblank(c)) ++mine; mine <<= 1;
- if (mywcntrl(c)) ++mine; mine <<= 1;
- if (mywdigit(c)) ++mine; mine <<= 1;
- if (mywgraph(c)) ++mine; mine <<= 1;
- if (mywlower(c)) ++mine; mine <<= 1;
- if (mywprint(c)) ++mine; mine <<= 1;
- if (mywpunct(c)) ++mine; mine <<= 1;
- if (mywspace(c)) ++mine; mine <<= 1;
- if (mywupper(c)) ++mine; mine <<= 1;
- if (mywxdigit(c)) ++mine;
-
- if (glibc != mine) {
- verbose_msg("%#8x : glibc %#4x != %#4x mine %d\n", c, glibc, mine, d);
- if (c < 0x30000UL) {
- verbose_msg("sc=%#x u=%#x n=%#x i0=%#x i1=%#x\n", sc, u, n, i0, i1);
+ mine = 0;
+ if (mywalnum(d,c)) ++mine; mine <<= 1;
+ if (mywalpha(d,c)) ++mine; mine <<= 1;
+ if (mywblank(d,c)) ++mine; mine <<= 1;
+ if (mywcntrl(d,c)) ++mine; mine <<= 1;
+ if (mywdigit(d,c)) ++mine; mine <<= 1;
+ if (mywgraph(d,c)) ++mine; mine <<= 1;
+ if (mywlower(d,c)) ++mine; mine <<= 1;
+ if (mywprint(d,c)) ++mine; mine <<= 1;
+ if (mywpunct(d,c)) ++mine; mine <<= 1;
+ if (mywspace(d,c)) ++mine; mine <<= 1;
+ if (mywupper(d,c)) ++mine; mine <<= 1;
+ if (mywxdigit(d,c)) ++mine;
+
+ if (glibc != mine) {
+ verbose_msg("%#8x : glibc %#4x != %#4x mine %d\n", c, glibc, mine, d);
+ if (c < 0x30000UL) {
+ verbose_msg("sc=%#x u=%#x n=%#x i0=%#x i1=%#x\n", sc, u, n, i0, i1);
+ }
}
- }
+
upper = lower = u = c;
if (u <= RANGE) {
sc = u & ((1 << ultable.ti_shift) - 1);
@@ -676,23 +654,22 @@ int main(int argc, char **argv)
lower = c + uldiff[i0].l;
}
- if (towupper(c) != upper) {
- verbose_msg("%#8x : towupper glibc %#4x != %#4x mine\n",
- c, towupper(c), upper);
- }
+ if (towupper(c) != upper) {
+ verbose_msg("%#8x : towupper glibc %#4x != %#4x mine\n",
+ c, towupper(c), upper);
+ }
- if (towlower(c) != lower) {
- verbose_msg("%#8x : towlower glibc %#4x != %#4x mine i0 = %d\n",
- c, towlower(c), lower, i0);
- }
+ if (towlower(c) != lower) {
+ verbose_msg("%#8x : towlower glibc %#4x != %#4x mine i0 = %d\n",
+ c, towlower(c), lower, i0);
+ }
- if (totitle && ((tt = towctrans(c, totitle)) != upper)) {
- verbose_msg("%#8x : totitle glibc %#4lx != %#4x mine i0 = %d\n",
- c, tt, upper, i0);
- }
+ if (totitle && ((tt = towctrans(c, totitle)) != upper)) {
+ verbose_msg("%#8x : totitle glibc %#4lx != %#4x mine i0 = %d\n",
+ c, tt, upper, i0);
+ }
}
-
if ((c & 0xfff) == 0xfff) verbose_msg(".");
}
verbose_msg("done\n");
@@ -711,13 +688,12 @@ int main(int argc, char **argv)
output_table(fp, "ctype", &cttable);
output_table(fp, "uplow", &ultable);
-
#warning fix the upper bound on the upper/lower tables... save 200 bytes or so
fprintf(fp, "#define __LOCALE_DATA_WCuplow_diffs %7u\n", ul_count);
fprintf(fp, "\n#ifdef WANT_WCuplow_diff_data\n\n");
fprintf(fp, "\nstatic const short __LOCALE_DATA_WCuplow_diff_data[%zu] = {",
2 * (size_t) ul_count);
- for (i=0 ; i < ul_count ; i++) {
+ for (i = 0; i < ul_count; i++) {
if (i % 4 == 0) {
fprintf(fp, "\n");
}
@@ -726,7 +702,6 @@ int main(int argc, char **argv)
fprintf(fp, "\n};\n\n");
fprintf(fp, "#endif /* WANT_WCuplow_diff_data */\n\n");
-
/* output_table(fp, "comb", &combtable); */
/* output_table(fp, "width", &widthtable); */
@@ -757,7 +732,7 @@ size_t newopt(unsigned char *ut, size_t usize, int shift, table_data *tbl)
numblocks = usize >> shift;
/* init table index */
- for (i=j=0 ; i < numblocks ; i++) {
+ for (i=j = 0; i < numblocks; i++) {
ti[i] = ut + j;
j += blocksize;
}
@@ -768,7 +743,7 @@ size_t newopt(unsigned char *ut, size_t usize, int shift, table_data *tbl)
uniq = 1;
uit[(ti[0]-ut)/blocksize] = 0;
- for (i=1 ; i < numblocks ; i++) {
+ for (i=1; i < numblocks; i++) {
if (memcmp(ti[i-1], ti[i], blocksize) < 0) {
if (++uniq > 255) {
break;
@@ -777,7 +752,7 @@ size_t newopt(unsigned char *ut, size_t usize, int shift, table_data *tbl)
}
#if 1
else if (memcmp(ti[i-1], ti[i], blocksize) > 0) {
- verbose_msg("bad sort %i!\n", i);
+ verbose_msg("bad sort %li!\n", (long) i);
abort();
}
#endif
@@ -786,37 +761,37 @@ size_t newopt(unsigned char *ut, size_t usize, int shift, table_data *tbl)
smallest = SIZE_MAX;
shift2 = -1;
- if (uniq <= 255) {
- smallest = numblocks + uniq * blocksize;
- if (!recurse) {
- ++recurse;
- for (j=1 ; j < 14 ; j++) {
- if ((numblocks >> j) < 2) break;
- if (tbl) {
- ii_save = tbl->ii;
- tbl->ii = NULL;
- }
- if ((t = newopt(uit, numblocks, j, tbl)) < SIZE_MAX) {
- t += uniq * blocksize;
- }
- if (tbl) {
- tbl->ii = ii_save;
- }
- if (smallest >= t) {
- shift2 = j;
- smallest = t;
- if (!tbl->ii) {
- verbose_msg("ishift %zu tshift %zu size %zu\n",
- shift2, shift, t);
- }
-/* } else { */
-/* break; */
+
+ if (uniq > 255)
+ return SIZE_MAX;
+
+ smallest = numblocks + uniq * blocksize;
+ if (!recurse) {
+ ++recurse;
+ for (j=1; j < 14; j++) {
+ if ((numblocks >> j) < 2) break;
+ if (tbl) {
+ ii_save = tbl->ii;
+ tbl->ii = NULL;
+ }
+ if ((t = newopt(uit, numblocks, j, tbl)) < SIZE_MAX) {
+ t += uniq * blocksize;
+ }
+ if (tbl) {
+ tbl->ii = ii_save;
+ }
+ if (smallest >= t) {
+ shift2 = j;
+ smallest = t;
+ if (!tbl->ii) {
+ verbose_msg("ishift %u tshift %u size %lu\n",
+ shift2, shift, (unsigned long) t);
}
+/* } else { */
+/* break; */
}
- --recurse;
}
- } else {
- return SIZE_MAX;
+ --recurse;
}
if (tbl->ii) {
@@ -826,19 +801,19 @@ size_t newopt(unsigned char *ut, size_t usize, int shift, table_data *tbl)
memcpy(tbl->ii, uit, numblocks);
tbl->ti = tbl->ii + tbl->ii_len;
tbl->ti_len = uniq * blocksize;
- for (i=0 ; i < uniq ; i++) {
+ for (i = 0; i < uniq; i++) {
memcpy(tbl->ti + i * blocksize, ti[uniqblock[i]], blocksize);
}
} else {
++recurse;
- verbose_msg("setting ishift %zu tshift %zu\n",
+ verbose_msg("setting ishift %u tshift %u\n",
shift2, shift);
newopt(uit, numblocks, shift2, tbl);
--recurse;
tbl->ti_shift = shift;
tbl->ut_len = uniq * blocksize;
tbl->ut = tbl->ti + tbl->ti_len;
- for (i=0 ; i < uniq ; i++) {
+ for (i = 0; i < uniq; i++) {
memcpy(tbl->ut + i * blocksize, ti[uniqblock[i]], blocksize);
}
}