From: Bruno Haible Date: Mon, 27 Nov 2006 12:34:20 +0000 (+0000) Subject: New functions message_list_copy, msgdomain_list_copy. X-Git-Tag: v0.17~639 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1d8f7c817d1979138b9af22b3bb8e3818cb56b0d;p=thirdparty%2Fgettext.git New functions message_list_copy, msgdomain_list_copy. --- diff --git a/gettext-tools/src/ChangeLog b/gettext-tools/src/ChangeLog index 2ebb8b1fc..1c3c9f8c5 100644 --- a/gettext-tools/src/ChangeLog +++ b/gettext-tools/src/ChangeLog @@ -1,3 +1,8 @@ +2006-11-25 Bruno Haible + + * message.h (message_list_copy, msgdomain_list_copy): New declarations. + * message.c (message_list_copy, msgdomain_list_copy): New functions. + 2006-11-25 Bruno Haible * msgl-iconv.h (iconv_msgdomain_list): Add update_header argument. diff --git a/gettext-tools/src/message.c b/gettext-tools/src/message.c index b7019f305..6bacc7fbf 100644 --- a/gettext-tools/src/message.c +++ b/gettext-tools/src/message.c @@ -448,6 +448,24 @@ message_list_msgids_changed (message_list_ty *mlp) } +message_list_ty * +message_list_copy (message_list_ty *mlp, int copy_level) +{ + message_list_ty *result; + size_t j; + + result = message_list_alloc (mlp->use_hashtable); + for (j = 0; j < mlp->nitems; j++) + { + message_ty *mp = mlp->item[j]; + + message_list_append (result, copy_level ? mp : message_copy (mp)); + } + + return result; +} + + message_ty * message_list_search (message_list_ty *mlp, const char *msgctxt, const char *msgid) @@ -780,6 +798,43 @@ msgdomain_list_sublist (msgdomain_list_ty *mdlp, const char *domain, } +/* Copy a message domain list. + If copy_level = 0, also copy the messages. If copy_level = 1, share the + messages but copy the domains. If copy_level = 2, share the domains. */ +msgdomain_list_ty * +msgdomain_list_copy (msgdomain_list_ty *mdlp, int copy_level) +{ + msgdomain_list_ty *result; + size_t j; + + result = XMALLOC (msgdomain_list_ty); + result->nitems = 0; + result->nitems_max = 0; + result->item = NULL; + result->use_hashtable = mdlp->use_hashtable; + result->encoding = mdlp->encoding; + + for (j = 0; j < mdlp->nitems; j++) + { + msgdomain_ty *mdp = mdlp->item[j]; + + if (copy_level < 2) + { + msgdomain_ty *result_mdp = XMALLOC (msgdomain_ty); + + result_mdp->domain = mdp->domain; + result_mdp->messages = message_list_copy (mdp->messages, copy_level); + + msgdomain_list_append (result, result_mdp); + } + else + msgdomain_list_append (result, mdp); + } + + return result; +} + + #if 0 /* unused */ message_ty * msgdomain_list_search (msgdomain_list_ty *mdlp, diff --git a/gettext-tools/src/message.h b/gettext-tools/src/message.h index dc7a234ee..09648831e 100644 --- a/gettext-tools/src/message.h +++ b/gettext-tools/src/message.h @@ -225,6 +225,11 @@ extern void changed. */ extern bool message_list_msgids_changed (message_list_ty *mlp); +/* Copy a message list. + If copy_level = 0, also copy the messages. If copy_level = 1, share the + messages. */ +extern message_list_ty * + message_list_copy (message_list_ty *mlp, int copy_level); extern message_ty * message_list_search (message_list_ty *mlp, const char *msgctxt, const char *msgid); @@ -298,6 +303,11 @@ extern void extern message_list_ty * msgdomain_list_sublist (msgdomain_list_ty *mdlp, const char *domain, bool create); +/* Copy a message domain list. + If copy_level = 0, also copy the messages. If copy_level = 1, share the + messages but copy the domains. If copy_level = 2, share the domains. */ +extern msgdomain_list_ty * + msgdomain_list_copy (msgdomain_list_ty *mdlp, int copy_level); extern message_ty * msgdomain_list_search (msgdomain_list_ty *mdlp, const char *msgctxt, const char *msgid);