0eb822a1c0c2bea495647510b75f77f0e57633ebcindi/*
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi * CDDL HEADER START
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi *
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi * The contents of this file are subject to the terms of the
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi * Common Development and Distribution License, Version 1.0 only
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi * (the "License"). You may not use this file except in compliance
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi * with the License.
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi *
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi * or http://www.opensolaris.org/os/licensing.
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi * See the License for the specific language governing permissions
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi * and limitations under the License.
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi *
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi * When distributing Covered Code, include this CDDL HEADER in each
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi * If applicable, add the following below this CDDL HEADER, with the
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi * fields enclosed by brackets "[]" replaced with your own identifying
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi * information: Portions Copyright [yyyy] [name of copyright owner]
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi *
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi * CDDL HEADER END
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi */
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi/*
44ed9dbbfa620821ecf59a131462082f628dd0f3Stephen Hanson * Copyright 2001, 2002 Sun Microsystems, Inc. All rights reserved.
aed5247ff899ec457005d93dfbdb4ffd74574695Joshua M. Clulow * Use is subject to license terms.
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi */
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi#pragma ident "%Z%%M% %I% %E% SMI"
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi#include "gnu_msgfmt.h"
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi#include "../../lib/libc/inc/msgfmt.h"
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi
0eb822a1c0c2bea495647510b75f77f0e57633ebcindistruct messages *
0eb822a1c0c2bea495647510b75f77f0e57633ebcindisearch_msg(struct catalog *p, const char *id, unsigned int hash_val)
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi{
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi unsigned int i, idx, inc;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi struct messages *m;
908f1e1388f616898b4e515d343c0414f2a6472esd
184cd04c26b064536977dfbb913a1240eaf6f708cth idx = hash_val % p->thash_size;
908f1e1388f616898b4e515d343c0414f2a6472esd inc = 1 + (hash_val % (p->thash_size - 2));
14ea4bb737263733ad80a36b4f73f681c30a6b45sd if (!p->thash[idx])
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi return (NULL);
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi m = p->msg;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi for (m = p->msg; (i = p->thash[idx]) != 0;
908f1e1388f616898b4e515d343c0414f2a6472esd idx = (idx + inc) % p->thash_size) {
e3d60c9bd991a9826cbfa63b10595d44e123b9c4Adrian Frost if (strcmp(m[i - 1].id, id) == 0) {
e3d60c9bd991a9826cbfa63b10595d44e123b9c4Adrian Frost /* found */
940d71d237794874e18a0eb72f6564821a823517eschrock return (&m[i - 1]);
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi }
13faa91230bde46da937bf33010b9accc5bdeb59sd }
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi return (NULL);
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi}
908f1e1388f616898b4e515d343c0414f2a6472esd
0eb822a1c0c2bea495647510b75f77f0e57633ebcindistatic int
2eeaed14a5e2ed9bd811643ad5bffc3510ca0310robjmsg_cmp(struct messages *m1, struct messages *m2)
ded9341448cd6e2573619c7f6fe98909bdd35ec6Hyon Kim{
2eeaed14a5e2ed9bd811643ad5bffc3510ca0310robj return (strcmp(m1->id, m2->id));
fc33347812f84907261f6fd501e2409da108b8d8Tom Pothier}
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi
0eb822a1c0c2bea495647510b75f77f0e57633ebcindivoid
0eb822a1c0c2bea495647510b75f77f0e57633ebcindioutput_all_gnu_mo_files(void)
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim{
13faa91230bde46da937bf33010b9accc5bdeb59sd struct catalog *p, *op;
908f1e1388f616898b4e515d343c0414f2a6472esd struct messages *m;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi size_t id_len, str_len, id_off, str_off, ids_top, strs_top;
908f1e1388f616898b4e515d343c0414f2a6472esd unsigned int *hash_tbl;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi unsigned int hash_size;
14ea4bb737263733ad80a36b4f73f681c30a6b45sd unsigned int num = 0, fnum = 0, unum = 0;
14ea4bb737263733ad80a36b4f73f681c30a6b45sd unsigned int i, idx;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi char *ids, *strs;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi struct msgtbl *id_tbl, *str_tbl;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi struct gnu_msg_info header;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi FILE *out;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi p = catalog_head;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi while (p) {
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi num += p->nmsg;
ded9341448cd6e2573619c7f6fe98909bdd35ec6Hyon Kim fnum += p->fnum;
2eeaed14a5e2ed9bd811643ad5bffc3510ca0310robj unum += p->unum;
2eeaed14a5e2ed9bd811643ad5bffc3510ca0310robj
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim free(p->thash);
908f1e1388f616898b4e515d343c0414f2a6472esd if (p->nmsg == 0) {
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim /*
908f1e1388f616898b4e515d343c0414f2a6472esd * no message in this file
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim * skip generating a mo
940d71d237794874e18a0eb72f6564821a823517eschrock */
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim goto skip;
4df55fde49134f9735f84011f23a767c75e393c7Janie Lu }
53dbcc5939527e6d5d52d814e51e364b5e8bb532Sundeep Panicker
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi if (p->header)
14ea4bb737263733ad80a36b4f73f681c30a6b45sd num--;
14ea4bb737263733ad80a36b4f73f681c30a6b45sd
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi p->msg = (struct messages *)Xrealloc(p->msg,
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi sizeof (struct messages) * p->nmsg);
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi /*
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi * Sort the message array
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi */
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi qsort(p->msg, p->nmsg, sizeof (struct messages),
9dd0f810214fdc8e1af881a9a5c4b6927629ff9ecindi (int (*)(const void *, const void *))msg_cmp);
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi
602ca9ea8f9ce0933f0944601cc5d230e91a950dcth
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi hash_size = find_prime(p->nmsg);
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi hash_tbl = (unsigned int *)Xcalloc(hash_size,
602ca9ea8f9ce0933f0944601cc5d230e91a950dcth sizeof (unsigned int));
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi /* Setting Header info */
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi header.magic = GNU_MAGIC;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi header.revision = GNU_REVISION;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi header.num_of_str = p->nmsg;
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi header.off_msgid_tbl = sizeof (struct gnu_msg_info);
eae2e508a8e70b1ec407b10bd068c080651bbe5ckrishnae header.off_msgstr_tbl = sizeof (struct gnu_msg_info) +
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi p->nmsg * sizeof (struct msgtbl);
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim header.sz_hashtbl = hash_size;
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim header.off_hashtbl = header.off_msgstr_tbl +
aed5247ff899ec457005d93dfbdb4ffd74574695Joshua M. Clulow p->nmsg * sizeof (struct msgtbl);
aed5247ff899ec457005d93dfbdb4ffd74574695Joshua M. Clulow
aed5247ff899ec457005d93dfbdb4ffd74574695Joshua M. Clulow m = p->msg;
aed5247ff899ec457005d93dfbdb4ffd74574695Joshua M. Clulow
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim id_len = 0;
44ed9dbbfa620821ecf59a131462082f628dd0f3Stephen Hanson str_len = 0;
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim for (i = 0; i < p->nmsg; i++) {
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim id_len += m[i].id_len;
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim str_len += m[i].str_len;
44ed9dbbfa620821ecf59a131462082f628dd0f3Stephen Hanson }
44ed9dbbfa620821ecf59a131462082f628dd0f3Stephen Hanson ids = (char *)Xmalloc(id_len);
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim strs = (char *)Xmalloc(str_len);
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim id_tbl = (struct msgtbl *)Xmalloc(sizeof (struct msgtbl) *
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim p->nmsg);
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim str_tbl = (struct msgtbl *)Xmalloc(sizeof (struct msgtbl) *
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim p->nmsg);
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim id_off = 0;
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim str_off = 0;
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim ids_top = header.off_hashtbl +
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim sizeof (unsigned int) * hash_size;
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim strs_top = ids_top + id_len;
ac88567a7a5bb7f01cf22cf366bc9d6203e24d7aHyon Kim for (i = 0; i < p->nmsg; i++) {
03f9f63d24f0494b7d47b927090ad9045e396402Tom Pothier /*
e58a33b62cd4c9a6815fd752ce58b5f389289da1Stephen Hanson * Set the hash table
e58a33b62cd4c9a6815fd752ce58b5f389289da1Stephen Hanson */
e58a33b62cd4c9a6815fd752ce58b5f389289da1Stephen Hanson idx = get_hash_index(hash_tbl, m[i].hash, hash_size);
e58a33b62cd4c9a6815fd752ce58b5f389289da1Stephen Hanson hash_tbl[idx] = i + 1;
e58a33b62cd4c9a6815fd752ce58b5f389289da1Stephen Hanson
e58a33b62cd4c9a6815fd752ce58b5f389289da1Stephen Hanson /*
e58a33b62cd4c9a6815fd752ce58b5f389289da1Stephen Hanson * rearrange msgid and msgstr
e58a33b62cd4c9a6815fd752ce58b5f389289da1Stephen Hanson */
e58a33b62cd4c9a6815fd752ce58b5f389289da1Stephen Hanson id_tbl[i].len = m[i].id_len - 1;
e58a33b62cd4c9a6815fd752ce58b5f389289da1Stephen Hanson str_tbl[i].len = m[i].str_len - 1;
e58a33b62cd4c9a6815fd752ce58b5f389289da1Stephen Hanson id_tbl[i].offset = id_off + ids_top;
e58a33b62cd4c9a6815fd752ce58b5f389289da1Stephen Hanson str_tbl[i].offset = str_off + strs_top;
e58a33b62cd4c9a6815fd752ce58b5f389289da1Stephen Hanson (void) memcpy(ids + id_off, m[i].id, m[i].id_len);
e58a33b62cd4c9a6815fd752ce58b5f389289da1Stephen Hanson (void) memcpy(strs + str_off, m[i].str, m[i].str_len);
e58a33b62cd4c9a6815fd752ce58b5f389289da1Stephen Hanson id_off += m[i].id_len;
e58a33b62cd4c9a6815fd752ce58b5f389289da1Stephen Hanson str_off += m[i].str_len;
e58a33b62cd4c9a6815fd752ce58b5f389289da1Stephen Hanson free(m[i].id);
e58a33b62cd4c9a6815fd752ce58b5f389289da1Stephen Hanson free(m[i].str);
e58a33b62cd4c9a6815fd752ce58b5f389289da1Stephen Hanson }
e58a33b62cd4c9a6815fd752ce58b5f389289da1Stephen Hanson
e58a33b62cd4c9a6815fd752ce58b5f389289da1Stephen Hanson if ((out = fopen(p->fname, "w")) == NULL) {
e58a33b62cd4c9a6815fd752ce58b5f389289da1Stephen Hanson error(gettext(ERR_OPEN_FAILED), p->fname);
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi /* NOTREACHED */
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi }
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi /* writing header */
0eb822a1c0c2bea495647510b75f77f0e57633ebcindi (void) fwrite(&header, sizeof (struct gnu_msg_info),
1, out);
/* writing msgid offset table */
(void) fwrite(id_tbl, sizeof (struct msgtbl),
p->nmsg, out);
/* writing msgstr offset table */
(void) fwrite(str_tbl, sizeof (struct msgtbl),
p->nmsg, out);
/* writing hash table */
(void) fwrite(hash_tbl, sizeof (unsigned int),
hash_size, out);
/* writing msgid table */
(void) fwrite(ids, id_len, 1, out);
/* writing msgstr table */
(void) fwrite(strs, str_len, 1, out);
(void) fclose(out);
free(id_tbl);
free(str_tbl);
free(hash_tbl);
free(ids);
free(strs);
skip:
free(p->fname);
free(p->msg);
op = p->next;
free(p);
p = op;
}
if (verbose_flag) {
diag(gettext(DIAG_RESULTS), num, fnum, unum);
}
}