Changeset View
Changeset View
Standalone View
Standalone View
usr.bin/localedef/collate.c
Show First 20 Lines • Show All 1,107 Lines • ▼ Show 20 Lines | |||||
{ | { | ||||
FILE *f; | FILE *f; | ||||
int i, j, n; | int i, j, n; | ||||
size_t sz; | size_t sz; | ||||
int32_t pri; | int32_t pri; | ||||
collelem_t *ce; | collelem_t *ce; | ||||
collchar_t *cc; | collchar_t *cc; | ||||
subst_t *sb; | subst_t *sb; | ||||
char vers[COLLATE_STR_LEN]; | char format_version[COLLATE_FORMAT_VERSION_LEN]; | ||||
char data_version[XLOCALE_VERSION_LEN]; | |||||
collate_char_t chars[UCHAR_MAX + 1]; | collate_char_t chars[UCHAR_MAX + 1]; | ||||
collate_large_t *large; | collate_large_t *large; | ||||
collate_subst_t *subst[COLL_WEIGHTS_MAX]; | collate_subst_t *subst[COLL_WEIGHTS_MAX]; | ||||
collate_chain_t *chain; | collate_chain_t *chain; | ||||
/* | /* | ||||
* We have to run through a preliminary pass to identify all the | * We have to run through a preliminary pass to identify all the | ||||
* weights that we use for each sorting level. | * weights that we use for each sorting level. | ||||
Show All 24 Lines | for (i = 0; i < NUM_WT; i++) { | ||||
weight_t *w; | weight_t *w; | ||||
RB_FOREACH(w, weights, &weights[i]) { | RB_FOREACH(w, weights, &weights[i]) { | ||||
w->opt = nweight[i]; | w->opt = nweight[i]; | ||||
nweight[i] += 1; | nweight[i] += 1; | ||||
} | } | ||||
} | } | ||||
(void) memset(&chars, 0, sizeof (chars)); | (void) memset(&chars, 0, sizeof (chars)); | ||||
(void) memset(vers, 0, COLLATE_STR_LEN); | (void) memset(format_version, 0, COLLATE_FORMAT_VERSION_LEN); | ||||
(void) strlcpy(vers, COLLATE_VERSION, sizeof (vers)); | (void) strlcpy(format_version, COLLATE_VERSION, | ||||
sizeof (format_version)); | |||||
(void) memset(data_version, 0, XLOCALE_VERSION_LEN); | |||||
if (version) | |||||
yuripv: Just a nit: I know that current localedef code does that a lot, but still `version != NULL`… | |||||
Done Inline ActionsHmm well it'd look odd next to all the nearby uses of implicit NULL comparison in this file, so I think it's probably better to keep it that way. munro_ip9.org: Hmm well it'd look odd next to all the nearby uses of implicit NULL comparison in this file, so… | |||||
(void) strlcpy(data_version, version, sizeof (data_version)); | |||||
/* | /* | ||||
* We need to make sure we arrange for the UNDEFINED field | * We need to make sure we arrange for the UNDEFINED field | ||||
* to show up. Also, set the total weight counts. | * to show up. Also, set the total weight counts. | ||||
*/ | */ | ||||
for (i = 0; i < NUM_WT; i++) { | for (i = 0; i < NUM_WT; i++) { | ||||
if (resolve_pri(pri_undefined[i]) == -1) { | if (resolve_pri(pri_undefined[i]) == -1) { | ||||
set_pri(pri_undefined[i], -1, RESOLVED); | set_pri(pri_undefined[i], -1, RESOLVED); | ||||
▲ Show 20 Lines • Show All 116 Lines • ▼ Show 20 Lines | dump_collate(void) | ||||
} | } | ||||
if ((f = open_category()) == NULL) { | if ((f = open_category()) == NULL) { | ||||
return; | return; | ||||
} | } | ||||
/* Time to write the entire data set out */ | /* Time to write the entire data set out */ | ||||
if ((wr_category(vers, COLLATE_STR_LEN, f) < 0) || | if ((wr_category(format_version, COLLATE_FORMAT_VERSION_LEN, f) < 0) || | ||||
(wr_category(data_version, XLOCALE_VERSION_LEN, f) < 0) || | |||||
(wr_category(&collinfo, sizeof (collinfo), f) < 0) || | (wr_category(&collinfo, sizeof (collinfo), f) < 0) || | ||||
(wr_category(&chars, sizeof (chars), f) < 0)) { | (wr_category(&chars, sizeof (chars), f) < 0)) { | ||||
return; | return; | ||||
} | } | ||||
for (i = 0; i < NUM_WT; i++) { | for (i = 0; i < NUM_WT; i++) { | ||||
sz = sizeof (collate_subst_t) * collinfo.subst_count[i]; | sz = sizeof (collate_subst_t) * collinfo.subst_count[i]; | ||||
if (wr_category(subst[i], sz, f) < 0) { | if (wr_category(subst[i], sz, f) < 0) { | ||||
Show All 14 Lines |
Just a nit: I know that current localedef code does that a lot, but still version != NULL would be a proper comparison here.