From 277645f5b0d9aea985e1f266ed7bbcf0483abb6a Mon Sep 17 00:00:00 2001 From: jbj Date: Sun, 13 Feb 2000 19:23:55 +0000 Subject: [PATCH] Implementation of i18n look-aside, no-op'ed for now. CVS patchset: 3555 CVS date: 2000/02/13 19:23:55 --- lib/formats.c | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++++------ lib/header.c | 69 ++++++++++++++++++++++----------------------- lib/query.c | 3 +- 3 files changed, 116 insertions(+), 46 deletions(-) diff --git a/lib/formats.c b/lib/formats.c index 77869d3..55c94b2 100644 --- a/lib/formats.c +++ b/lib/formats.c @@ -65,8 +65,7 @@ static char * triggertypeFormat(int_32 type, const void * data, char * val; if (type != RPM_INT32_TYPE) { - val = xmalloc(20); - strcpy(val, _("(not a number)")); + val = xstrdup(_("(not a number)")); } else if (*item & RPMSENSE_TRIGGERIN) { val = xstrdup("in"); } else { @@ -83,8 +82,7 @@ static char * permsFormat(int_32 type, const void * data, char * buf; if (type != RPM_INT32_TYPE) { - val = xmalloc(20); - strcpy(val, _("(not a number)")); + val = xstrdup(_("(not a number)")); } else { val = xmalloc(15 + padding); strcat(formatPrefix, "s"); @@ -104,8 +102,7 @@ static char * fflagsFormat(int_32 type, const void * data, int anint = *((int_32 *) data); if (type != RPM_INT32_TYPE) { - val = xmalloc(20); - strcpy(val, _("(not a number)")); + val = xstrdup(_("(not a number)")); } else { buf[0] = '\0'; if (anint & RPMFILE_DOC) @@ -137,8 +134,7 @@ static char * depflagsFormat(int_32 type, const void * data, int anint = *((int_32 *) data); if (type != RPM_INT32_TYPE) { - val = xmalloc(20); - strcpy(val, _("(not a number)")); + val = xstrdup(_("(not a number)")); } else { buf[0] = '\0'; @@ -336,7 +332,8 @@ static int triggertypeTag(Header h, int_32 * type, /*@out@*/void ** data, } static int filenamesTag(Header h, int_32 * type, /*@out@*/void ** data, - int_32 * count, int * freeData) { + int_32 * count, int * freeData) +{ *type = RPM_STRING_ARRAY_TYPE; rpmBuildFileList(h, (const char ***) data, count); @@ -347,7 +344,82 @@ static int filenamesTag(Header h, int_32 * type, /*@out@*/void ** data, return 0; } +/* I18N look aside diversions */ + +static int i18nTag(Header h, int_32 tag, /*@out@*/ int_32 * type, + /*@out@*/ void ** data, /*@out@*/ int_32 * count, + /*@out@*/ int * freeData) +{ +#ifdef NOTYET + const char * domains = "specs:powertools"; +#else + const char * domains = NULL; +#endif + + *type = RPM_STRING_TYPE; + *data = NULL; + *count = 0; + *freeData = 1; + + if (domains) { + char * dstring, *domain, *de; + const char * locale; + char * msgkey; + const char * msgid; + const char * n; + const char * t = tagName(tag); + + headerNVR(h, &n, NULL, NULL); + msgkey = alloca(strlen(n) + strlen(t) + sizeof("()")); + sprintf(msgkey, "%s(%s)", n, t); + + msgid = NULL; + locale = setlocale(LC_MESSAGES, "C"); + dstring = xstrdup(domains); + for (domain = dstring; domain != NULL; domain = de) { + de = strchr(domain, ':'); + if (de) *de++ = '\0'; + msgid = /*@-unrecog@*/ dgettext(domain, msgkey) /*@=unrecog@*/; + if (msgid != msgkey) break; + } + setlocale(LC_MESSAGES, locale); + + if (domain && msgid) { + *data = xstrdup(/*@-unrecog@*/ dgettext(domain, msgid) /*@=unrecog@*/); + *count = 1; + } + xfree(dstring); + return (*data ? 0 : 1); + } + + return headerGetEntry(h, tag, type, data, count); +} + +static int summaryTag(Header h, /*@out@*/ int_32 * type, + /*@out@*/ void ** data, /*@out@*/ int_32 * count, + /*@out@*/ int * freeData) +{ + return i18nTag(h, RPMTAG_SUMMARY, type, data, count, freeData); +} + +static int descriptionTag(Header h, /*@out@*/ int_32 * type, + /*@out@*/ void ** data, /*@out@*/ int_32 * count, + /*@out@*/ int * freeData) +{ + return i18nTag(h, RPMTAG_DESCRIPTION, type, data, count, freeData); +} + +static int groupTag(Header h, /*@out@*/ int_32 * type, + /*@out@*/ void ** data, /*@out@*/ int_32 * count, + /*@out@*/ int * freeData) +{ + return i18nTag(h, RPMTAG_GROUP, type, data, count, freeData); +} + const struct headerSprintfExtension rpmHeaderFormats[] = { + { HEADER_EXT_TAG, "RPMTAG_GROUP", { groupTag } }, + { HEADER_EXT_TAG, "RPMTAG_DESCRIPTION", { descriptionTag } }, + { HEADER_EXT_TAG, "RPMTAG_SUMMARY", { summaryTag } }, { HEADER_EXT_TAG, "RPMTAG_FILENAMES", { filenamesTag } }, { HEADER_EXT_TAG, "RPMTAG_FSSIZES", { fssizesTag } }, { HEADER_EXT_TAG, "RPMTAG_FSNAMES", { fsnamesTag } }, diff --git a/lib/header.c b/lib/header.c index da38b76..b77bb6e 100644 --- a/lib/header.c +++ b/lib/header.c @@ -49,7 +49,7 @@ struct headerToken { int indexAlloced; int sorted; - /*@refs@*/int usageCount; + /*@refs@*/ int usageCount; }; struct entryInfo { @@ -79,8 +79,10 @@ struct sprintfTag { }; struct extensionCache { - int_32 type, count; - int avail, freeit; + int_32 type; + int_32 count; + int avail; + int freeit; void * data; }; @@ -1466,7 +1468,6 @@ static void findTag(char * name, const struct headerTagTableEntry * tags, const struct headerTagTableEntry * entry; const struct headerSprintfExtension * ext; char * tagname; - int i; *tagMatch = NULL; *extMatch = NULL; @@ -1479,29 +1480,30 @@ static void findTag(char * name, const struct headerTagTableEntry * tags, tagname = name; } + /* Search extensions first to permit overriding header tags. */ + ext = extensions; + while (ext->type != HEADER_EXT_LAST) { + if (ext->type == HEADER_EXT_TAG && !strcasecmp(ext->name, tagname)) + break; + + if (ext->type == HEADER_EXT_MORE) + ext = ext->u.more; + else + ext++; + } + + if (ext->type == HEADER_EXT_TAG) { + *extMatch = ext; + return; + } + + /* Search header tags. */ for (entry = tags; entry->name; entry++) if (!strcasecmp(entry->name, tagname)) break; if (entry->name) { *tagMatch = entry; - } else { - ext = extensions, i =0; - while (ext->type != HEADER_EXT_LAST) { - if (ext->type == HEADER_EXT_TAG && - !strcasecmp(ext->name, tagname)) { - break; - } - - if (ext->type == HEADER_EXT_MORE) - ext = ext->u.more; - else - ext++; - i++; - } - - if (ext->type == HEADER_EXT_TAG) { - *extMatch = ext; - } + return; } } @@ -1520,7 +1522,7 @@ static int parseFormat(char * str, const struct headerTagTableEntry * tags, struct sprintfToken * format; int numTokens; int currToken; - const struct headerTagTableEntry * entry; + const struct headerTagTableEntry * tag; const struct headerSprintfExtension * ext; int i; int done = 0; @@ -1633,11 +1635,11 @@ static int parseFormat(char * str, const struct headerTagTableEntry * tags, } i = 0; - findTag(start, tags, extensions, &entry, &ext); + findTag(start, tags, extensions, &tag, &ext); - if (entry) { + if (tag) { format[currToken].u.tag.ext = NULL; - format[currToken].u.tag.tag = entry->val; + format[currToken].u.tag.tag = tag->val; } else if (ext) { format[currToken].u.tag.ext = ext->u.tagFunction; format[currToken].u.tag.extNum = ext - extensions; @@ -1968,8 +1970,7 @@ static char * formatValue(struct sprintfTag * tag, Header h, break; default: - val = xmalloc(20); - strcpy(val, _("(unknown type)")); + val = xstrdup(_("(unknown type)")); break; } @@ -2059,8 +2060,7 @@ static char * singleSprintf(Header h, struct sprintfToken * token, } if (numElements == -1) { - val = xmalloc(20); - strcpy(val, "(none)"); /* XXX i18n? NO!, sez; gafton */ + val = xstrdup("(none)"); /* XXX i18n? NO!, sez; gafton */ } else { alloced = numElements * token->u.array.numTokens * 20; val = xmalloc(alloced); @@ -2185,8 +2185,7 @@ static char * octalFormat(int_32 type, const void * data, char * val; if (type != RPM_INT32_TYPE) { - val = xmalloc(20); - strcpy(val, _("(not a number)")); + val = xstrdup(_("(not a number)")); } else { val = xmalloc(20 + padding); strcat(formatPrefix, "o"); @@ -2202,8 +2201,7 @@ static char * hexFormat(int_32 type, const void * data, char * val; if (type != RPM_INT32_TYPE) { - val = xmalloc(20); - strcpy(val, _("(not a number)")); + val = xstrdup(_("(not a number)")); } else { val = xmalloc(20 + padding); strcat(formatPrefix, "x"); @@ -2222,8 +2220,7 @@ static char * realDateFormat(int_32 type, const void * data, char buf[50]; if (type != RPM_INT32_TYPE) { - val = xmalloc(20); - strcpy(val, _("(not a number)")); + val = xstrdup(_("(not a number)")); } else { val = xmalloc(50 + padding); strcat(formatPrefix, "s"); diff --git a/lib/query.c b/lib/query.c index 5e06fdf..7ce9d45 100644 --- a/lib/query.c +++ b/lib/query.c @@ -388,7 +388,8 @@ printNewSpecfile(Spec spec) } } -void rpmDisplayQueryTags(FILE * f) { +void rpmDisplayQueryTags(FILE * f) +{ const struct headerTagTableEntry * t; int i; const struct headerSprintfExtension * ext = rpmHeaderFormats; -- 2.7.4