void dump_monetary(void) { FILE *f; if ((f = open_category()) == NULL) { return; } if ((putl_category(mon.int_curr_symbol, f) == EOF) || (putl_category(mon.currency_symbol, f) == EOF) || (putl_category(mon.mon_decimal_point, f) == EOF) || (putl_category(mon.mon_thousands_sep, f) == EOF) || (putl_category(mon.mon_grouping, f) == EOF) || (putl_category(mon.positive_sign, f) == EOF) || (putl_category(mon.negative_sign, f) == EOF) || (putl_category(mon.int_frac_digits, f) == EOF) || (putl_category(mon.frac_digits, f) == EOF) || (putl_category(mon.p_cs_precedes, f) == EOF) || (putl_category(mon.p_sep_by_space, f) == EOF) || (putl_category(mon.n_cs_precedes, f) == EOF) || (putl_category(mon.n_sep_by_space, f) == EOF) || (putl_category(mon.p_sign_posn, f) == EOF) || (putl_category(mon.n_sign_posn, f) == EOF) || (putl_category(mon.int_p_cs_precedes, f) == EOF) || (putl_category(mon.int_n_cs_precedes, f) == EOF) || (putl_category(mon.int_p_sep_by_space, f) == EOF) || (putl_category(mon.int_n_sep_by_space, f) == EOF) || (putl_category(mon.int_p_sign_posn, f) == EOF) || (putl_category(mon.int_n_sign_posn, f) == EOF)) { return; } close_category(f); }
void dump_time(void) { FILE *f; int i; if ((f = open_category()) == NULL) { return; } for (i = 0; i < 12; i++) { if (putl_category(tm.mon[i], f) == EOF) { return; } } for (i = 0; i < 12; i++) { if (putl_category(tm.month[i], f) == EOF) { return; } } for (i = 0; i < 7; i++) { if (putl_category(tm.wday[i], f) == EOF) { return; } } for (i = 0; i < 7; i++) { if (putl_category(tm.weekday[i], f) == EOF) { return; } } /* * NOTE: If date_fmt is not specified, then we'll default to * using the %c for date. This is reasonable for most * locales, although for reasons that I don't understand * Solaris historically has had a separate format for date. */ if ((putl_category(tm.X_fmt, f) == EOF) || (putl_category(tm.x_fmt, f) == EOF) || (putl_category(tm.c_fmt, f) == EOF) || (putl_category(tm.am, f) == EOF) || (putl_category(tm.pm, f) == EOF) || (putl_category(tm.date_fmt ? tm.date_fmt : tm.c_fmt, f) == EOF) || (putl_category(tm.ampm_fmt, f) == EOF)) { return; } close_category(f); }
void dump_numeric(void) { FILE *f; if ((f = open_category()) == NULL) { return; } if ((putl_category(numeric.decimal_point, f) == EOF) || (putl_category(numeric.thousands_sep, f) == EOF) || (putl_category(numeric.grouping, f) == EOF)) { return; } close_category(f); }
void dump_ctype(void) { FILE *f; _FileRuneLocale rl; ctype_node_t *ctn, *last_ct, *last_lo, *last_up; _FileRuneEntry *ct = NULL; _FileRuneEntry *lo = NULL; _FileRuneEntry *up = NULL; wchar_t wc; (void) memset(&rl, 0, sizeof (rl)); last_ct = NULL; last_lo = NULL; last_up = NULL; if ((f = open_category()) == NULL) return; (void) memcpy(rl.magic, _FILE_RUNE_MAGIC_1, 8); (void) strncpy(rl.encoding, get_wide_encoding(), sizeof (rl.encoding)); /* * Initialize the identity map. */ for (wc = 0; (unsigned)wc < _CACHED_RUNES; wc++) { rl.maplower[wc] = wc; rl.mapupper[wc] = wc; } for (ctn = avl_first(&ctypes); ctn; ctn = AVL_NEXT(&ctypes, ctn)) { int conflict = 0; wc = ctn->wc; /* * POSIX requires certain portable characters have * certain types. Add them if they are missing. */ if ((wc >= 1) && (wc <= 127)) { if ((wc >= 'A') && (wc <= 'Z')) ctn->ctype |= _ISUPPER; if ((wc >= 'a') && (wc <= 'z')) ctn->ctype |= _ISLOWER; if ((wc >= '0') && (wc <= '9')) ctn->ctype |= _ISDIGIT; if (wc == ' ') ctn->ctype |= _ISPRINT; if (strchr(" \f\n\r\t\v", (char)wc) != NULL) ctn->ctype |= _ISSPACE; if (strchr("0123456789ABCDEFabcdef", (char)wc) != NULL) ctn->ctype |= _ISXDIGIT; if (strchr(" \t", (char)wc)) ctn->ctype |= _ISBLANK; /* * Technically these settings are only * required for the C locale. However, it * turns out that because of the historical * version of isprint(), we need them for all * locales as well. Note that these are not * necessarily valid punctation characters in * the current language, but ispunct() needs * to return TRUE for them. */ if (strchr("!\"'#$%&()*+,-./:;<=>?@[\\]^_`{|}~", (char)wc)) ctn->ctype |= _ISPUNCT; } /* * POSIX also requires that certain types imply * others. Add any inferred types here. */ if (ctn->ctype & (_ISUPPER |_ISLOWER)) ctn->ctype |= _ISALPHA; if (ctn->ctype & _ISDIGIT) ctn->ctype |= _ISXDIGIT; if (ctn->ctype & _ISBLANK) ctn->ctype |= _ISSPACE; if (ctn->ctype & (_ISALPHA|_ISDIGIT|_ISXDIGIT)) ctn->ctype |= _ISGRAPH; if (ctn->ctype & _ISGRAPH) ctn->ctype |= _ISPRINT; /* * Finally, POSIX requires that certain combinations * are invalid. We don't flag this as a fatal error, * but we will warn about. */ if ((ctn->ctype & _ISALPHA) && (ctn->ctype & (_ISPUNCT|_ISDIGIT))) conflict++; if ((ctn->ctype & _ISPUNCT) & (ctn->ctype & (_ISDIGIT|_ISALPHA|_ISXDIGIT))) conflict++; if ((ctn->ctype & _ISSPACE) && (ctn->ctype & _ISGRAPH)) conflict++; if ((ctn->ctype & _ISCNTRL) & _ISPRINT) conflict++; if ((wc == ' ') && (ctn->ctype & (_ISPUNCT|_ISGRAPH))) conflict++; if (conflict) { warn("conflicting classes for character 0x%x (%x)", wc, ctn->ctype); } /* * Handle the lower 256 characters using the simple * optimization. Note that if we have not defined the * upper/lower case, then we identity map it. */ if ((unsigned)wc < _CACHED_RUNES) { rl.runetype[wc] = ctn->ctype; if (ctn->tolower) rl.maplower[wc] = ctn->tolower; if (ctn->toupper) rl.mapupper[wc] = ctn->toupper; continue; } if ((last_ct != NULL) && (last_ct->ctype == ctn->ctype)) { ct[rl.runetype_ext_nranges-1].max = wc; last_ct = ctn; } else { rl.runetype_ext_nranges++; ct = realloc(ct, sizeof (*ct) * rl.runetype_ext_nranges); ct[rl.runetype_ext_nranges - 1].min = wc; ct[rl.runetype_ext_nranges - 1].max = wc; ct[rl.runetype_ext_nranges - 1].map = ctn->ctype; last_ct = ctn; } if (ctn->tolower == 0) { last_lo = NULL; } else if ((last_lo != NULL) && (last_lo->tolower + 1 == ctn->tolower)) { lo[rl.maplower_ext_nranges-1].max = wc; last_lo = ctn; } else { rl.maplower_ext_nranges++; lo = realloc(lo, sizeof (*lo) * rl.maplower_ext_nranges); lo[rl.maplower_ext_nranges - 1].min = wc; lo[rl.maplower_ext_nranges - 1].max = wc; lo[rl.maplower_ext_nranges - 1].map = ctn->tolower; last_lo = ctn; } if (ctn->toupper == 0) { last_up = NULL; } else if ((last_up != NULL) && (last_up->toupper + 1 == ctn->toupper)) { up[rl.mapupper_ext_nranges-1].max = wc; last_up = ctn; } else { rl.mapupper_ext_nranges++; up = realloc(up, sizeof (*up) * rl.mapupper_ext_nranges); up[rl.mapupper_ext_nranges - 1].min = wc; up[rl.mapupper_ext_nranges - 1].max = wc; up[rl.mapupper_ext_nranges - 1].map = ctn->toupper; last_up = ctn; } } if ((wr_category(&rl, sizeof (rl), f) < 0) || (wr_category(ct, sizeof (*ct) * rl.runetype_ext_nranges, f) < 0) || (wr_category(lo, sizeof (*lo) * rl.maplower_ext_nranges, f) < 0) || (wr_category(up, sizeof (*up) * rl.mapupper_ext_nranges, f) < 0)) { return; } close_category(f); }
void dump_collate(void) { FILE *f; int i, j, n; size_t sz; int32_t pri; collelem_t *ce; collchar_t *cc; subst_t *sb; char vers[COLLATE_STR_LEN]; collate_char_t chars[UCHAR_MAX + 1]; collate_large_t *large; collate_subst_t *subst[COLL_WEIGHTS_MAX]; collate_chain_t *chain; /* * We have to run throught a preliminary pass to identify all the * weights that we use for each sorting level. */ for (i = 0; i < NUM_WT; i++) { add_weight(pri_ignore, i); } for (i = 0; i < NUM_WT; i++) { for (sb = avl_first(&substs[i]); sb; sb = AVL_NEXT(&substs[i], sb)) { for (j = 0; sb->ref[j]; j++) { add_weight(sb->ref[j], i); } } } for (ce = avl_first(&elem_by_expand); ce != NULL; ce = AVL_NEXT(&elem_by_expand, ce)) { add_weights(ce->ref); } for (cc = avl_first(&collchars); cc; cc = AVL_NEXT(&collchars, cc)) { add_weights(cc->ref); } /* * Now we walk the entire set of weights, removing the gaps * in the weights. This gives us optimum usage. The walk * occurs in priority. */ for (i = 0; i < NUM_WT; i++) { weight_t *w; for (w = avl_first(&weights[i]); w; w = AVL_NEXT(&weights[i], w)) { w->opt = nweight[i]; nweight[i] += 1; } } (void) memset(&chars, 0, sizeof (chars)); (void) memset(vers, 0, COLLATE_STR_LEN); (void) strlcpy(vers, COLLATE_VERSION, sizeof (vers)); /* * We need to make sure we arrange for the UNDEFINED field * to show up. Also, set the total weight counts. */ for (i = 0; i < NUM_WT; i++) { if (resolve_pri(pri_undefined[i]) == -1) { set_pri(pri_undefined[i], -1, RESOLVED); /* they collate at the end of everything else */ collinfo.undef_pri[i] = COLLATE_MAX_PRIORITY; } collinfo.pri_count[i] = nweight[i]; } collinfo.pri_count[NUM_WT] = max_wide(); collinfo.undef_pri[NUM_WT] = COLLATE_MAX_PRIORITY; collinfo.directive[NUM_WT] = DIRECTIVE_UNDEFINED; /* * Ordinary character priorities */ for (i = 0; i <= UCHAR_MAX; i++) { if ((cc = get_collchar(i, 0)) != NULL) { for (j = 0; j < NUM_WT; j++) { chars[i].pri[j] = get_weight(cc->ref[j], j); } } else { for (j = 0; j < NUM_WT; j++) { chars[i].pri[j] = get_weight(pri_undefined[j], j); } /* * Per POSIX, for undefined characters, we * also have to add a last item, which is the * character code. */ chars[i].pri[NUM_WT] = i; } } /* * Substitution tables */ for (i = 0; i < NUM_WT; i++) { collate_subst_t *st = NULL; n = collinfo.subst_count[i] = avl_numnodes(&substs[i]); if ((st = calloc(sizeof (collate_subst_t) * n, 1)) == NULL) { errf(_("out of memory")); return; } n = 0; for (sb = avl_first(&substs[i]); sb; sb = AVL_NEXT(&substs[i], sb)) { if ((st[n].key = resolve_pri(sb->key)) < 0) { /* by definition these resolve! */ INTERR; } if (st[n].key != (n | COLLATE_SUBST_PRIORITY)) { INTERR; } for (j = 0; sb->ref[j]; j++) { st[n].pri[j] = get_weight(sb->ref[j], i); } n++; } if (n != collinfo.subst_count[i]) INTERR; subst[i] = st; } /* * Chains, i.e. collating elements */ collinfo.chain_count = avl_numnodes(&elem_by_expand); chain = calloc(sizeof (collate_chain_t), collinfo.chain_count); if (chain == NULL) { errf(_("out of memory")); return; } for (n = 0, ce = avl_first(&elem_by_expand); ce != NULL; ce = AVL_NEXT(&elem_by_expand, ce), n++) { (void) wsncpy(chain[n].str, ce->expand, COLLATE_STR_LEN); for (i = 0; i < NUM_WT; i++) { chain[n].pri[i] = get_weight(ce->ref[i], i); } } if (n != collinfo.chain_count) INTERR; /* * Large (> UCHAR_MAX) character priorities */ large = calloc(sizeof (collate_large_t) * avl_numnodes(&collchars), 1); if (large == NULL) { errf(_("out of memory")); return; } i = 0; for (cc = avl_first(&collchars); cc; cc = AVL_NEXT(&collchars, cc)) { int undef = 0; /* we already gathered those */ if (cc->wc <= UCHAR_MAX) continue; for (j = 0; j < NUM_WT; j++) { if ((pri = get_weight(cc->ref[j], j)) < 0) { undef = 1; } if (undef && (pri >= 0)) { /* if undefined, then all priorities are */ INTERR; } else { large[i].pri.pri[j] = pri; } } if (!undef) { large[i].val = cc->wc; collinfo.large_count = i++; } } if ((f = open_category()) == NULL) { return; } /* Time to write the entire data set out */ if ((wr_category(vers, COLLATE_STR_LEN, f) < 0) || (wr_category(&collinfo, sizeof (collinfo), f) < 0) || (wr_category(&chars, sizeof (chars), f) < 0)) { delete_category(f); return; } for (i = 0; i < NUM_WT; i++) { sz = sizeof (collate_subst_t) * collinfo.subst_count[i]; if (wr_category(subst[i], sz, f) < 0) { delete_category(f); return; } } sz = sizeof (collate_chain_t) * collinfo.chain_count; if (wr_category(chain, sz, f) < 0) { delete_category(f); return; } sz = sizeof (collate_large_t) * collinfo.large_count; if (wr_category(large, sz, f) < 0) { delete_category(f); return; } close_category(f); }