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 {
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");
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)
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';
}
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);
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 } },
int indexAlloced;
int sorted;
- /*@refs@*/int usageCount;
+ /*@refs@*/ int usageCount;
};
struct entryInfo {
};
struct extensionCache {
- int_32 type, count;
- int avail, freeit;
+ int_32 type;
+ int_32 count;
+ int avail;
+ int freeit;
void * data;
};
const struct headerTagTableEntry * entry;
const struct headerSprintfExtension * ext;
char * tagname;
- int i;
*tagMatch = NULL;
*extMatch = NULL;
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;
}
}
struct sprintfToken * format;
int numTokens;
int currToken;
- const struct headerTagTableEntry * entry;
+ const struct headerTagTableEntry * tag;
const struct headerSprintfExtension * ext;
int i;
int done = 0;
}
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;
break;
default:
- val = xmalloc(20);
- strcpy(val, _("(unknown type)"));
+ val = xstrdup(_("(unknown type)"));
break;
}
}
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);
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");
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");
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");