From e8a51ea07cc06c6f985f0d9b91e23a8c2848db76 Mon Sep 17 00:00:00 2001 From: kibook Date: Thu, 12 Dec 2024 12:34:03 -0500 Subject: [PATCH] s1kd-metadata: Add "language" metadata name Added a metadata name, "language", which returns the combined values of "languageIsoCode" and "countryIsoCode" (similar to "issueInfo" being a combined version of "issueNumber" and "inWork") --- tools/s1kd-metadata/s1kd-metadata.c | 33 ++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/tools/s1kd-metadata/s1kd-metadata.c b/tools/s1kd-metadata/s1kd-metadata.c index 53f308ca..d3085eab 100644 --- a/tools/s1kd-metadata/s1kd-metadata.c +++ b/tools/s1kd-metadata/s1kd-metadata.c @@ -13,7 +13,7 @@ #include "s1kd_tools.h" #define PROG_NAME "s1kd-metadata" -#define VERSION "4.5.0" +#define VERSION "4.6.0" #define ERR_PREFIX PROG_NAME ": ERROR: " @@ -1070,6 +1070,30 @@ static void show_issue_info(xmlNodePtr node, struct opts *opts) xmlFree(s); } +static xmlChar *get_language(xmlNodePtr node, struct opts *opts) +{ + xmlChar *l, *c; + l = first_xpath_string(node, BAD_CAST "@languageIsoCode|@language"); + c = first_xpath_string(node, BAD_CAST "@countryIsoCode|@country"); + + l = xmlStrcat(l, BAD_CAST "-"); + l = xmlStrcat(l, c); + + xmlFree(c); + + return l; +} + +static void show_language(xmlNodePtr node, struct opts *opts) +{ + xmlChar *s; + s = get_language(node, opts); + if (s) { + printf("%s", (char *) s); + } + xmlFree(s); +} + static int create_act_ref(xmlXPathContextPtr ctxt, const char *val) { xmlNodePtr node; @@ -1997,6 +2021,13 @@ static struct metadata metadata[] = { edit_item_location_code, NULL, "Item location code"}, + {"language", + "//language", + get_language, + show_language, + NULL, + NULL, + "Language and country ISO codes (en-CA, en-US, fr-FR, ...)"}, {"languageIsoCode", "//language/@languageIsoCode|//language/@language", NULL,