version 1.28, 2012/07/30 23:04:42 |
version 1.29, 2015/05/29 12:26:28 |
Line 51 __RCSID("$NetBSD$"); |
|
Line 51 __RCSID("$NetBSD$"); |
|
#include "plural_parser.h" |
#include "plural_parser.h" |
#include "pathnames.h" |
#include "pathnames.h" |
|
|
|
/* GNU gettext added a hack to add some context to messages. If a message is |
|
* used in multiple locations, it needs some amount of context to make the |
|
* translation clear to translators. GNU gettext, rather than modifying the |
|
* message format, concatenates the context, \004 and the message id. |
|
*/ |
|
#define MSGCTXT_ID_SEPARATOR '\004' |
|
|
|
static const char *pgettext_impl(const char *, const char *, const char *, |
|
const char *, unsigned long int, int); |
|
static char *concatenate_ctxt_id(const char *, const char *); |
static const char *lookup_category(int); |
static const char *lookup_category(int); |
static const char *split_locale(const char *); |
static const char *split_locale(const char *); |
static const char *lookup_mofile(char *, size_t, const char *, const char *, |
static const char *lookup_mofile(char *, size_t, const char *, const char *, |
Line 105 dngettext(const char *domainname, const |
|
Line 115 dngettext(const char *domainname, const |
|
return dcngettext(domainname, msgid1, msgid2, n, LC_MESSAGES); |
return dcngettext(domainname, msgid1, msgid2, n, LC_MESSAGES); |
} |
} |
|
|
|
const char * |
|
pgettext(const char *msgctxt, const char *msgid) |
|
{ |
|
|
|
return pgettext_impl(NULL, msgctxt, msgid, NULL, 1UL, LC_MESSAGES); |
|
} |
|
|
|
const char * |
|
dpgettext(const char *domainname, const char *msgctxt, const char *msgid) |
|
{ |
|
|
|
return pgettext_impl(domainname, msgctxt, msgid, NULL, 1UL, LC_MESSAGES); |
|
} |
|
|
|
const char * |
|
dcpgettext(const char *domainname, const char *msgctxt, const char *msgid, |
|
int category) |
|
{ |
|
|
|
return pgettext_impl(domainname, msgctxt, msgid, NULL, 1UL, category); |
|
} |
|
|
|
const char * |
|
npgettext(const char *msgctxt, const char *msgid1, const char *msgid2, |
|
unsigned long int n) |
|
{ |
|
|
|
return pgettext_impl(NULL, msgctxt, msgid1, msgid2, n, LC_MESSAGES); |
|
} |
|
|
|
const char * |
|
dnpgettext(const char *domainname, const char *msgctxt, const char *msgid1, |
|
const char *msgid2, unsigned long int n) |
|
{ |
|
|
|
return pgettext_impl(domainname, msgctxt, msgid1, msgid2, n, LC_MESSAGES); |
|
} |
|
|
|
const char * |
|
dcnpgettext(const char *domainname, const char *msgctxt, const char *msgid1, |
|
const char *msgid2, unsigned long int n, int category) |
|
{ |
|
|
|
return pgettext_impl(domainname, msgctxt, msgid1, msgid2, n, category); |
|
} |
|
|
|
static const char * |
|
pgettext_impl(const char *domainname, const char *msgctxt, const char *msgid1, |
|
const char *msgid2, unsigned long int n, int category) |
|
{ |
|
char *msgctxt_id; |
|
char *translation; |
|
char *p; |
|
|
|
if ((msgctxt_id = concatenate_ctxt_id(msgctxt, msgid1)) == NULL) |
|
return msgid1; |
|
|
|
translation = dcngettext(domainname, msgctxt_id, |
|
msgid2, n, category); |
|
free(msgctxt_id); |
|
|
|
p = strchr(translation, '\004'); |
|
if (p) |
|
return p + 1; |
|
return translation; |
|
} |
|
|
/* |
/* |
* dcngettext() - |
* dcngettext() - |
* lookup internationalized message on database locale/category/domainname |
* lookup internationalized message on database locale/category/domainname |
Line 126 dngettext(const char *domainname, const |
|
Line 203 dngettext(const char *domainname, const |
|
* /usr/share/locale! (or we should move those files into /usr/libdata) |
* /usr/share/locale! (or we should move those files into /usr/libdata) |
*/ |
*/ |
|
|
|
static char * |
|
concatenate_ctxt_id(const char *msgctxt, const char *msgid) |
|
{ |
|
char *ret; |
|
|
|
if (asprintf(&ret, "%s%c%s", msgctxt, MSGCTXT_ID_SEPARATOR, msgid) == -1) |
|
return NULL; |
|
|
|
return ret; |
|
} |
|
|
static const char * |
static const char * |
lookup_category(int category) |
lookup_category(int category) |
{ |
{ |
|
|
static void |
static void |
free_sysdep_table(struct mosysdepstr_h **table, uint32_t nstring) |
free_sysdep_table(struct mosysdepstr_h **table, uint32_t nstring) |
{ |
{ |
uint32_t i; |
|
|
|
for (i=0; i<nstring; i++) { |
if (! table) |
|
return; |
|
|
|
for (uint32_t i = 0; i < nstring; i++) { |
if (table[i]) { |
if (table[i]) { |
if (table[i]->expanded) |
free(table[i]->expanded); |
free(table[i]->expanded); |
|
free(table[i]); |
free(table[i]); |
} |
} |
} |
} |
Line 680 unmapit(struct domainbinding *db) |
|
Line 769 unmapit(struct domainbinding *db) |
|
if (mohandle->addr && mohandle->addr != MAP_FAILED) |
if (mohandle->addr && mohandle->addr != MAP_FAILED) |
munmap(mohandle->addr, mohandle->len); |
munmap(mohandle->addr, mohandle->len); |
mohandle->addr = NULL; |
mohandle->addr = NULL; |
if (mohandle->mo.mo_otable) |
free(mohandle->mo.mo_otable); |
free(mohandle->mo.mo_otable); |
free(mohandle->mo.mo_ttable); |
if (mohandle->mo.mo_ttable) |
free(mohandle->mo.mo_charset); |
free(mohandle->mo.mo_ttable); |
free(mohandle->mo.mo_htable); |
if (mohandle->mo.mo_charset) |
free(mohandle->mo.mo_sysdep_segs); |
free(mohandle->mo.mo_charset); |
free_sysdep_table(mohandle->mo.mo_sysdep_otable, |
if (mohandle->mo.mo_htable) |
mohandle->mo.mo_sysdep_nstring); |
free(mohandle->mo.mo_htable); |
free_sysdep_table(mohandle->mo.mo_sysdep_ttable, |
if (mohandle->mo.mo_sysdep_segs) |
mohandle->mo.mo_sysdep_nstring); |
free(mohandle->mo.mo_sysdep_segs); |
_gettext_free_plural(mohandle->mo.mo_plural); |
if (mohandle->mo.mo_sysdep_otable) { |
|
free_sysdep_table(mohandle->mo.mo_sysdep_otable, |
|
mohandle->mo.mo_sysdep_nstring); |
|
} |
|
if (mohandle->mo.mo_sysdep_ttable) { |
|
free_sysdep_table(mohandle->mo.mo_sysdep_ttable, |
|
mohandle->mo.mo_sysdep_nstring); |
|
} |
|
if (mohandle->mo.mo_plural) |
|
_gettext_free_plural(mohandle->mo.mo_plural); |
|
memset(&mohandle->mo, 0, sizeof(mohandle->mo)); |
memset(&mohandle->mo, 0, sizeof(mohandle->mo)); |
return 0; |
return 0; |
} |
} |
Line 918 dcngettext(const char *domainname, const |
|
Line 997 dcngettext(const char *domainname, const |
|
domainname, db) == NULL) |
domainname, db) == NULL) |
goto fail; |
goto fail; |
|
|
if (odomainname) |
free(odomainname); |
free(odomainname); |
free(ocname); |
if (ocname) |
|
free(ocname); |
|
odomainname = strdup(domainname); |
odomainname = strdup(domainname); |
ocname = strdup(cname); |
ocname = strdup(cname); |
if (!odomainname || !ocname) { |
if (!odomainname || !ocname) { |
if (odomainname) |
free(odomainname); |
free(odomainname); |
free(ocname); |
if (ocname) |
|
free(ocname); |
|
odomainname = ocname = NULL; |
odomainname = ocname = NULL; |
} |
} |
else |
else |