mohandle
db->mohandle.mo.mo_magic)
if (db->mohandle.mo.mo_plural) {
_gettext_calculate_plural(db->mohandle.mo.mo_plural, n);
if (plural_index >= db->mohandle.mo.mo_nplurals)
if (db->mohandle.mo.mo_plural)
validate(void *arg, struct mohandle *mohandle)
if (p < (char *)mohandle->addr ||
p > (char *)mohandle->addr + mohandle->len)
expand_sysdep(struct mohandle *mohandle, struct mosysdepstr_h *str)
mohandle->mo.mo_sysdep_segs[str->segs[i].ref].len;
memcpy(dst, mohandle->mo.mo_sysdep_segs[str->segs[i].ref].str,
mohandle->mo.mo_sysdep_segs[str->segs[i].ref].len);
dst += mohandle->mo.mo_sysdep_segs[str->segs[i].ref].len;
setup_sysdep_stuffs(struct mo *mo, struct mohandle *mohandle, char *base)
mohandle->mo.mo_sysdep_nsegs = flip(mo->mo_sysdep_nsegs, magic);
mohandle->mo.mo_sysdep_nstring = flip(mo->mo_sysdep_nstring, magic);
if (mohandle->mo.mo_sysdep_nstring == 0)
if (mohandle->mo.mo_hsize <= 2 ||
mohandle->mo.mo_hsize <
(mohandle->mo.mo_nstring + mohandle->mo.mo_sysdep_nstring))
l = sizeof(struct mosysdepsegs_h) * mohandle->mo.mo_sysdep_nsegs;
mohandle->mo.mo_sysdep_segs = (struct mosysdepsegs_h *)malloc(l);
if (!mohandle->mo.mo_sysdep_segs)
for (i=0; i<mohandle->mo.mo_sysdep_nsegs; i++) {
mohandle->mo.mo_sysdep_segs[i].str =
&mohandle->mo.mo_sysdep_segs[i].len);
mohandle->mo.mo_sysdep_otable =
(struct mosysdepstr_h **)calloc(mohandle->mo.mo_sysdep_nstring,
if (!mohandle->mo.mo_sysdep_otable)
if (get_sysdep_string_table(mohandle->mo.mo_sysdep_otable, ofstable,
mohandle->mo.mo_sysdep_nstring, magic,
mohandle->mo.mo_sysdep_ttable =
(struct mosysdepstr_h **)calloc(mohandle->mo.mo_sysdep_nstring,
if (!mohandle->mo.mo_sysdep_ttable)
if (get_sysdep_string_table(mohandle->mo.mo_sysdep_ttable, ofstable,
mohandle->mo.mo_sysdep_nstring, magic,
for (i=0; i<mohandle->mo.mo_sysdep_nstring; i++) {
if (expand_sysdep(mohandle, mohandle->mo.mo_sysdep_otable[i]))
insert_to_hash(mohandle->mo.mo_htable,
mohandle->mo.mo_hsize,
mohandle->mo.mo_sysdep_otable[i]->expanded,
struct mohandle *mohandle = &db->mohandle;
if (mohandle->addr && mohandle->addr != MAP_FAILED &&
mohandle->mo.mo_magic)
mohandle->addr = mmap(NULL, (size_t)st.st_size, PROT_READ,
if (!mohandle->addr || mohandle->addr == MAP_FAILED) {
mohandle->len = (size_t)st.st_size;
base = mohandle->addr;
mo = (struct mo *)mohandle->addr;
mohandle->mo.mo_magic = mo->mo_magic;
mohandle->mo.mo_revision = flip(mo->mo_revision, magic);
mohandle->mo.mo_nstring = flip(mo->mo_nstring, magic);
mohandle->mo.mo_hsize = flip(mo->mo_hsize, magic);
mohandle->mo.mo_flags = flags;
if (!validate(otable, mohandle) ||
!validate(&otable[mohandle->mo.mo_nstring], mohandle)) {
if (!validate(ttable, mohandle) ||
!validate(&ttable[mohandle->mo.mo_nstring], mohandle)) {
l = sizeof(struct moentry_h) * mohandle->mo.mo_nstring;
mohandle->mo.mo_otable = (struct moentry_h *)malloc(l);
if (!mohandle->mo.mo_otable) {
mohandle->mo.mo_ttable = (struct moentry_h *)malloc(l);
if (!mohandle->mo.mo_ttable) {
p = mohandle->mo.mo_otable;
for (i = 0; i < mohandle->mo.mo_nstring; i++) {
if (!validate(p[i].off, mohandle) ||
!validate(p[i].off + p[i].len + 1, mohandle)) {
p = mohandle->mo.mo_ttable;
for (i = 0; i < mohandle->mo.mo_nstring; i++) {
if (!validate(p[i].off, mohandle) ||
!validate(p[i].off + p[i].len + 1, mohandle)) {
if (mohandle->mo.mo_hsize > 2) {
l = sizeof(uint32_t) * mohandle->mo.mo_hsize;
mohandle->mo.mo_htable = (uint32_t *)malloc(l);
if (!mohandle->mo.mo_htable) {
static int validate(void *, struct mohandle *);
for (i=0; i < mohandle->mo.mo_hsize; i++) {
mohandle->mo.mo_htable[i] = flip(htable[i], magic);
if (mohandle->mo.mo_htable[i] >=
mohandle->mo.mo_nstring+1) {
mohandle->mo.mo_header = lookup("", db, &headerlen);
if (mohandle->mo.mo_header)
value = strstr(mohandle->mo.mo_header, "charset=");
mohandle->mo.mo_charset = strdup(value + 8);
if (!mohandle->mo.mo_charset)
char *newline = strchr(mohandle->mo.mo_charset, '\n');
if (!mohandle->mo.mo_header ||
_gettext_parse_plural(&mohandle->mo.mo_plural,
&mohandle->mo.mo_nplurals,
mohandle->mo.mo_header, headerlen))
mohandle->mo.mo_plural = NULL;
if ((mohandle->mo.mo_flags & MO_F_SYSDEP) != 0) {
if (setup_sysdep_stuffs(mo, mohandle, base)) {
struct mohandle *mohandle = &db->mohandle;
if (mohandle->addr && mohandle->addr != MAP_FAILED)
munmap(mohandle->addr, mohandle->len);
mohandle->addr = NULL;
free(mohandle->mo.mo_otable);
free(mohandle->mo.mo_ttable);
free(mohandle->mo.mo_charset);
free(mohandle->mo.mo_htable);
free(mohandle->mo.mo_sysdep_segs);
free_sysdep_table(mohandle->mo.mo_sysdep_otable,
mohandle->mo.mo_sysdep_nstring);
free_sysdep_table(mohandle->mo.mo_sysdep_ttable,
mohandle->mo.mo_sysdep_nstring);
_gettext_free_plural(mohandle->mo.mo_plural);
memset(&mohandle->mo, 0, sizeof(mohandle->mo));
struct mohandle *mohandle = &db->mohandle;
if (mohandle->mo.mo_hsize <= 2 || mohandle->mo.mo_htable == NULL)
step = calc_collision_step(hashval, mohandle->mo.mo_hsize);
idx = hashval % mohandle->mo.mo_hsize;
strno = mohandle->mo.mo_htable[idx];
if (len <= mohandle->mo.mo_otable[strno].len &&
!strcmp(msgid, mohandle->mo.mo_otable[strno].off)) {
mohandle->mo.mo_ttable[strno].len;
return mohandle->mo.mo_ttable[strno].off;
sysdep_otable = mohandle->mo.mo_sysdep_otable[strno];
sysdep_ttable = mohandle->mo.mo_sysdep_ttable[strno];
if (expand_sysdep(mohandle, sysdep_ttable))
idx = calc_next_index(idx, mohandle->mo.mo_hsize, step);
struct mohandle *mohandle = &db->mohandle;
bottom = mohandle->mo.mo_nstring;
if ((size_t)middle >= mohandle->mo.mo_nstring)
n = strcmp(msgid, mohandle->mo.mo_otable[middle].off);
*rlen = mohandle->mo.mo_ttable[middle].len;
return (const char *)mohandle->mo.mo_ttable[middle].off;
const char *fromcode = db->mohandle.mo.mo_charset;
struct mohandle mohandle;
p->mohandle.mo.mo_magic = 0; /* invalidate current mapping */