PERFORCE change 149054 for review
Konrad Jankowski
konrad at FreeBSD.org
Tue Sep 2 09:16:47 UTC 2008
http://perforce.freebsd.org/chv.cgi?CH=149054
Change 149054 by konrad at vspredator on 2008/09/02 09:15:58
Throw out all the endianness dance. I was making using mmap impossible.
Also, minor changes to the struct __collate_st_info.
Affected files ...
.. //depot/projects/soc2008/konrad_collation/colldef.apple/collate.h#8 edit
.. //depot/projects/soc2008/konrad_collation/colldef.apple/parse.y#10 edit
Differences ...
==== //depot/projects/soc2008/konrad_collation/colldef.apple/collate.h#8 (text+ko) ====
@@ -63,36 +63,31 @@
#define IGNORE_EQUIV_CLASS 1
+struct weight_map_struct
+{
+ unsigned int v:4;
+};
+
+#define COLL_WEIGHTS_REAL (COLL_WEIGHTS_MAX * 4)
+struct __collate_st_char_pri {
+ struct weight_map_struct map[COLL_WEIGHTS_MAX];
+ __int32_t pri[COLL_WEIGHTS_REAL];
+};
+
struct __collate_st_info {
__uint8_t directive[COLL_WEIGHTS_MAX];
__uint8_t flags;
-#if _BYTE_ORDER == _LITTLE_ENDIAN
- unsigned int directive_count:4;
unsigned int chain_max_len:4;
-#else
- unsigned int chain_max_len:4;
unsigned int directive_count:4;
-#endif
- __int32_t undef_pri[COLL_WEIGHTS_MAX];
+ struct __collate_st_char_pri undef_pri;
__int32_t subst_count[COLL_WEIGHTS_MAX];
__int32_t chain_count;
__int32_t large_pri_count;
};
-struct weight_map_struct
-{
- unsigned int v:4;
-};
-
-#define COLL_WEIGHTS_REAL (COLL_WEIGHTS_MAX * 4)
-struct __collate_st_char_pri {
- struct weight_map_struct map[COLL_WEIGHTS_MAX];
- __int32_t pri[COLL_WEIGHTS_REAL];
-};
struct __collate_st_chain_pri {
- struct weight_map_struct map[COLL_WEIGHTS_MAX];
+ struct __collate_st_char_pri pri;
wchar_t str[STR_LEN];
- __int32_t pri[COLL_WEIGHTS_MAX];
};
struct __collate_st_large_char_pri {
__int32_t val;
@@ -124,15 +119,12 @@
wchar_t *__collate_wcsdup(const wchar_t *);
wchar_t *__collate_substitute(const wchar_t *, int);
int __collate_load_tables(const char *);
-void __collate_lookup_l(const wchar_t *, int *, int *, int *);
-void __collate_lookup_which(const wchar_t *, int *, int *, int);
void __collate_xfrm(const wchar_t *, wchar_t **);
int __collate_range_cmp(wchar_t, wchar_t);
size_t __collate_collating_symbol(wchar_t *, size_t, const char *, size_t, mbstate_t *);
int __collate_equiv_class(const char *, size_t, mbstate_t *);
size_t __collate_equiv_match(int, wchar_t *, size_t, wchar_t, const char *, size_t, mbstate_t *, size_t *);
-#else /* !__LIBC__ */
-void __collate_lookup(const unsigned char *, int *, int *, int *);
+struct __collate_st_char_pri *__collate_lookup(const wchar_t *, int *);
#endif /* __LIBC__ */
#ifdef COLLATE_DEBUG
void __collate_print_tables(void);
==== //depot/projects/soc2008/konrad_collation/colldef.apple/parse.y#10 (text+ko) ====
@@ -119,7 +119,8 @@
#ifdef COLLATE_DEBUG
int debug;
#endif
-struct __collate_st_info info = {{DIRECTIVE_FORWARD, DIRECTIVE_FORWARD}, 0, 0, 0, {PRI_UNDEFINED, PRI_UNDEFINED}, {PRI_UNDEFINED}, 0, 0};
+struct __collate_st_info info = {{DIRECTIVE_FORWARD, DIRECTIVE_FORWARD}, 0,
+ 0, 0, {{{0}, {1}, {2}, {3}}, {PRI_UNDEFINED, PRI_UNDEFINED}}, {PRI_UNDEFINED}, 0, 0};
int directive_count = COLL_WEIGHTS_MAX;
@@ -151,7 +152,8 @@
struct __collate_st_chain_pri *t, *v;
int flags, i, len;
- if ((__collate_chain_pri_table = (struct __collate_st_chain_pri *)malloc(nchain * sizeof(struct __collate_st_chain_pri))) == NULL)
+ if ((__collate_chain_pri_table = (struct __collate_st_chain_pri *)
+ malloc(nchain * sizeof(struct __collate_st_chain_pri))) == NULL)
err(1, "chain malloc");
flags = R_FIRST;
t = __collate_chain_pri_table;
@@ -166,7 +168,8 @@
}
if (chaindb->seq(chaindb, &key, &val, flags) == 0)
err(1, "More in chaindb after retrieving %d", nchain);
- qsort(__collate_chain_pri_table, nchain, sizeof(struct __collate_st_chain_pri), chainpricompar);
+ qsort(__collate_chain_pri_table, nchain, sizeof(struct __collate_st_chain_pri),
+ chainpricompar);
}
for(z = 0; z < directive_count; z++) {
if (nsubst[z] > 0) {
@@ -176,7 +179,8 @@
int flags, i, j;
int32_t cval;
- if ((__collate_substitute_table[z] = (struct __collate_st_subst *)calloc(nsubst[z], sizeof(struct __collate_st_subst))) == NULL)
+ if ((__collate_substitute_table[z] = (struct __collate_st_subst *)
+ calloc(nsubst[z], sizeof(struct __collate_st_subst))) == NULL)
err(1, "__collate_substitute_table[%d] calloc", z);
flags = R_FIRST;
t = __collate_substitute_table[z];
@@ -188,7 +192,7 @@
* need it for sorting */
t->val = cval;
for(wp = (wchar_t *)val.data, tp = t->str, j = STR_LEN; *wp && j-- > 0;)
- *tp++ = htonl(*wp++);
+ *tp++ = *wp++;
t++;
flags = R_NEXT;
}
@@ -217,7 +221,7 @@
* need it for sorting */
t->val = cval;
for(z = 0; z < COLL_WEIGHTS_REAL; z++)
- t->pri.pri[z] = htonl(p->pri[z]);
+ t->pri.pri[z] = p->pri[z];
for (z = 0; z < directive_count; z++)
t->pri.map[z].v = p->map[z].v;
t++;
@@ -228,11 +232,11 @@
qsort(__collate_large_char_pri_table, nlargemap, sizeof(struct __collate_st_large_char_pri), charpricompar);
}
- if (info.undef_pri[0] == PRI_UNDEFINED) {
+ if (info.undef_pri.pri[0] == PRI_UNDEFINED) {
int i;
- info.undef_pri[0] = prim_pri;
+ info.undef_pri.pri[0] = prim_pri;
for(i = 1; i < directive_count; i++)
- info.undef_pri[i] = -prim_pri;
+ info.undef_pri.pri[i] = -prim_pri;
}
if (localedef) {
@@ -249,14 +253,18 @@
struct __collate_st_char_pri *p = haspri(v->u.wc);
if (!p || p->pri[0] == PRI_UNDEFINED)
- warnx("<%s> was not defined", showwcs((const wchar_t *)key.data, key.size / sizeof(wchar_t)));
+ warnx("<%s> was not defined",
+ showwcs((const wchar_t *)key.data,
+ key.size / sizeof(wchar_t)));
break;
}
case SYMBOL_CHAIN: {
struct __collate_st_chain_pri *p = getchain(v->u.str, EXISTS);
- if (p->pri[0] == PRI_UNDEFINED)
- warnx("<%s> was not defined", showwcs((const wchar_t *)key.data, key.size / sizeof(wchar_t)));
+ if (p->pri.pri[0] == PRI_UNDEFINED)
+ warnx("<%s> was not defined",
+ showwcs((const wchar_t *)key.data,
+ key.size / sizeof(wchar_t)));
break;
}
}
@@ -268,12 +276,17 @@
for (ch = 1; ch < UCHAR_MAX + 1; ch++) {
for(z = 0; z < directive_count; z++)
if (__collate_char_pri_table[ch].pri[z] == PRI_UNDEFINED)
- __collate_char_pri_table[ch].pri[z] = (info.undef_pri[z] >= 0) ? info.undef_pri[z] : (ch - info.undef_pri[z]);
+ __collate_char_pri_table[ch].pri[z] =
+ (info.undef_pri.pri[z] >= 0) ? info.undef_pri.pri[z] :
+ (ch - info.undef_pri.pri[z]);
}
for (ch = 0; ch < nlargemap; ch++) {
for(z = 0; z < directive_count; z++)
if (__collate_large_char_pri_table[ch].pri.pri[z] == PRI_UNDEFINED)
- __collate_large_char_pri_table[ch].pri.pri[z] = (info.undef_pri[z] >= 0) ? info.undef_pri[z] : (__collate_large_char_pri_table[ch].val - info.undef_pri[z]);
+ __collate_large_char_pri_table[ch].pri.pri[z] =
+ (info.undef_pri.pri[z] >= 0) ? info.undef_pri.pri[z] :
+ (__collate_large_char_pri_table[ch].val -
+ info.undef_pri.pri[z]);
}
} else {
int ch, substed, ordered;
@@ -324,29 +337,10 @@
err(EX_IOERR,
"IO error writting collate version to destination file %s",
out_file);
-#if _BYTE_ORDER == _LITTLE_ENDIAN
- for(z = 0; z < directive_count; z++) {
- info.undef_pri[z] = htonl(info.undef_pri[z]);
- info.subst_count[z] = htonl(info.subst_count[z]);
- }
- info.chain_count = htonl(info.chain_count);
- info.large_pri_count = htonl(info.large_pri_count);
-#endif /* _BYTE_ORDER == _LITTLE_ENDIAN */
if (fwrite(&info, sizeof(info), 1, fp) != 1)
err(EX_IOERR,
"IO error writting collate info to destination file %s",
out_file);
-#if _BYTE_ORDER == _LITTLE_ENDIAN
- {
- int i, z;
- struct __collate_st_char_pri *p = __collate_char_pri_table;
-
- for(i = UCHAR_MAX + 1; i-- > 0; p++) {
- for(z = 0; z < COLL_WEIGHTS_REAL; z++)
- p->pri[z] = htonl(p->pri[z]);
- }
- }
-#endif /* _BYTE_ORDER == _LITTLE_ENDIAN */
if (fwrite(__collate_char_pri_table,
sizeof(__collate_char_pri_table), 1, fp) != 1)
err(EX_IOERR,
@@ -354,34 +348,14 @@
out_file);
for(z = 0; z < directive_count; z++) {
if (nsubst[z] > 0) {
-#if _BYTE_ORDER == _LITTLE_ENDIAN
- struct __collate_st_subst *t = __collate_substitute_table[z];
- int i;
-
- for(i = nsubst[z]; i > 0; i--) {
- t->val = htonl(t->val);
- t++;
- }
-#endif /* _BYTE_ORDER == _LITTLE_ENDIAN */
- if ((int)fwrite(__collate_substitute_table[z], sizeof(struct __collate_st_subst), nsubst[z], fp) != nsubst[z])
+ if ((int)fwrite(__collate_substitute_table[z],
+ sizeof(struct __collate_st_subst), nsubst[z], fp) != nsubst[z])
err(EX_IOERR,
"IO error writting large substprim table %d to destination file %s",
z, out_file);
}
}
if (nchain > 0) {
-#if _BYTE_ORDER == _LITTLE_ENDIAN
- int i, j, z;
- struct __collate_st_chain_pri *p = __collate_chain_pri_table;
- wchar_t *w;
-
- for(i = nchain; i-- > 0; p++) {
- for(j = STR_LEN, w = p->str; *w && j-- > 0; w++)
- *w = htonl(*w);
- for(z = 0; z < directive_count; z++)
- p->pri[z] = htonl(p->pri[z]);
- }
-#endif /* _BYTE_ORDER == _LITTLE_ENDIAN */
if (fwrite(__collate_chain_pri_table,
sizeof(*__collate_chain_pri_table), nchain, fp) !=
(size_t)nchain)
@@ -391,14 +365,6 @@
}
if (nlargemap > 0) {
-#if _BYTE_ORDER == _LITTLE_ENDIAN
- struct __collate_st_large_char_pri *t = __collate_large_char_pri_table;
- int i;
- for(i = 0; i < nlargemap; i++) {
- t->val = htonl(t->val);
- t++;
- }
-#endif /* _BYTE_ORDER == _LITTLE_ENDIAN */
if ((int)fwrite(__collate_large_char_pri_table, sizeof(struct __collate_st_large_char_pri), nlargemap, fp) != nlargemap)
err(EX_IOERR,
"IO error writting large pri tables to destination file %s",
@@ -759,24 +725,24 @@
case SYMBOL_CHAIN:
case SYMBOL_IGNORE:
case SYMBOL_SYMBOL:
- if (p->pri[i] != PRI_UNDEFINED)
+ if (p->pri.pri[i] != PRI_UNDEFINED)
yyerror("Chain %s previously defined",
showwcs(s->u.str, STR_LEN));
- p->pri[i] = weight_table[i].val;
+ p->pri.pri[i] = weight_table[i].val;
break;
case SYMBOL_STRING :
if (wcsncmp(s->u.str, weight_table[i].u.str, STR_LEN) != 0)
yyerror("Chain/string mismatch");
- if (p->pri[i] != PRI_UNDEFINED)
+ if (p->pri.pri[i] != PRI_UNDEFINED)
yyerror("Chain %s previously defined",
showwcs(s->u.str, STR_LEN));
/* negative value mean don't substitute
* the chain, but it is in an
* equivalence class */
- p->pri[i] = -weight_table[i].val;
+ p->pri.pri[i] = -weight_table[i].val;
}
}
- memcpy(p->map, weight_map, sizeof(p->map));
+ memcpy(p->pri.map, weight_map, sizeof(p->pri.map));
break;
}
}
@@ -839,12 +805,12 @@
case SYMBOL_CHAIN:
case SYMBOL_IGNORE:
case SYMBOL_SYMBOL:
- info.undef_pri[i] = weight_table[i].val;
+ info.undef_pri.pri[i] = weight_table[i].val;
break;
case SYMBOL_ELLIPSIS :
/* Negative values mean that the priority is
* relative to the lexical value */
- info.undef_pri[i] = -sym_undefined.val;
+ info.undef_pri.pri[i] = -sym_undefined.val;
prim_pri = UNDEFINED_PRI;
break;
case SYMBOL_STRING :
@@ -984,7 +950,7 @@
}
| chain {
struct __collate_st_chain_pri *c = getchain(curr_chain, NOTEXISTS);
- c->pri[0] = c->pri[1] = prim_pri;
+ c->pri.pri[0] = c->pri.pri[1] = prim_pri;
sec_pri = ++prim_pri;
}
| CHAR RANGE CHAR {
@@ -1017,10 +983,10 @@
}
;
mixed_sub_list : mixed_sub_item
- | mixed_sub_list ',' mixed_sub_item
+ | mixed_sub_list ',' mixed_sub_item
;
sec_order_list : sec_sub_item
- | sec_order_list ',' sec_sub_item
+ | sec_order_list ',' sec_sub_item
;
mixed_sub_item : CHAR {
struct __collate_st_char_pri *p = getpri($1);
@@ -1047,8 +1013,8 @@
}
| chain {
struct __collate_st_chain_pri *c = getchain(curr_chain, NOTEXISTS);
- c->pri[0] = prim_pri;
- c->pri[1] = sec_pri;
+ c->pri.pri[0] = prim_pri;
+ c->pri.pri[1] = sec_pri;
}
sec_sub_item : CHAR {
struct __collate_st_char_pri *p = getpri($1);
@@ -1075,8 +1041,8 @@
}
| chain {
struct __collate_st_chain_pri *c = getchain(curr_chain, NOTEXISTS);
- c->pri[0] = prim_pri;
- c->pri[1] = sec_pri++;
+ c->pri.pri[0] = prim_pri;
+ c->pri.pri[1] = sec_pri++;
}
;
%%
@@ -1222,7 +1188,7 @@
malloc(sizeof(struct __collate_st_chain_pri))) == NULL)
err(1, "getchain: malloc");
for(z = 0; z < COLL_WEIGHTS_MAX; z++)
- pn->pri[z] = PRI_UNDEFINED;
+ pn->pri.pri[z] = PRI_UNDEFINED;
bzero(pn->str, sizeof(pn->str));
wcsncpy(pn->str, wcs, STR_LEN);
val.data = &pn;
@@ -1498,7 +1464,7 @@
}
static void
-collate_print_tables(void)
+collate_print_tables(/*struct __locale_st_collate *collate_data*/)
{
int i, z, pos;
@@ -1506,7 +1472,7 @@
info.directive[0], info.directive[1],
info.flags, info.chain_max_len,
info.directive_count,
- info.undef_pri[0], info.undef_pri[1],
+ info.undef_pri.pri[0], info.undef_pri.pri[1],
info.subst_count[0], info.subst_count[1],
info.chain_count, info.large_pri_count);
for(z = 0; z < info.directive_count; z++) {
@@ -1529,7 +1495,7 @@
for (i = info.chain_count; i-- > 0; p2++) {
printf("\t\"%s\" :", showwcs(p2->str, STR_LEN));
for(z = 0; z < info.directive_count; z++)
- printf(" %d", p2->pri[z]);
+ printf(" %d", p2->pri.pri[z]);
putchar('\n');
}
}
More information about the p4-projects
mailing list