diff options
author | Hans Ulrich Niedermann <hun@n-dimensional.de> | 2022-05-15 18:36:46 +0200 |
---|---|---|
committer | Hans Ulrich Niedermann <hun@n-dimensional.de> | 2022-05-19 17:11:17 +0200 |
commit | 77f3b22e937c212fb330a18b3f1924b3a7539122 (patch) | |
tree | ec9fa26e96f8f26535d086c2db30f34b2fa4cccb /libgphoto2_port | |
parent | 00b09b0d45f503e4cb4e02bc25e239c109bd7865 (diff) | |
download | libgphoto2-77f3b22e937c212fb330a18b3f1924b3a7539122.tar.gz |
Complete what adding gp_init_localedir() started
Complete what adding the gp_init_localedir() function implied:
* only set success flag in the success case
* consistent use of "initialize" spelling
* add analogous gp_port_init_localedir() function
* implement and document edge cases
* update NEWS
Diffstat (limited to 'libgphoto2_port')
-rw-r--r-- | libgphoto2_port/configure.ac | 5 | ||||
-rw-r--r-- | libgphoto2_port/gphoto2/gphoto2-port-info-list.h | 3 | ||||
-rw-r--r-- | libgphoto2_port/libgphoto2_port/gphoto2-port-info-list.c | 60 | ||||
-rw-r--r-- | libgphoto2_port/libgphoto2_port/libgphoto2_port.ver | 3 |
4 files changed, 64 insertions, 7 deletions
diff --git a/libgphoto2_port/configure.ac b/libgphoto2_port/configure.ac index cbf2e6f7f..848dcff6f 100644 --- a/libgphoto2_port/configure.ac +++ b/libgphoto2_port/configure.ac @@ -58,9 +58,10 @@ dnl A:R:C=7:0:7 libgphoto2_port-0.7.0 libgphoto2-2.3 dnl A:R:C=7:1:7 libgphoto2_port-0.7.1 libgphoto2-2.3.x dnl A:R:C=8:0:8 libgphoto2_port-0.8.0 libgphoto2-2.4.x dnl A:R:C=9:1:9 libgphoto2_port-0.10.0 libgphoto2-2.5.x -AC_SUBST([LIBGPHOTO2_PORT_AGE], [0]) +dnl A:R:C=1:0:13 libgphoto2-2.5.XXX (added gp_port_init_localedir ... ) +AC_SUBST([LIBGPHOTO2_PORT_AGE], [1]) AC_SUBST([LIBGPHOTO2_PORT_REVISION], [0]) -AC_SUBST([LIBGPHOTO2_PORT_CURRENT], [12]) +AC_SUBST([LIBGPHOTO2_PORT_CURRENT], [13]) AC_SUBST([LIBGPHOTO2_PORT_CURRENT_MIN], [`expr $LIBGPHOTO2_PORT_CURRENT - $LIBGPHOTO2_PORT_AGE`]) AC_SUBST([LIBGPHOTO2_PORT_VERSION_INFO], diff --git a/libgphoto2_port/gphoto2/gphoto2-port-info-list.h b/libgphoto2_port/gphoto2/gphoto2-port-info-list.h index 9fe85a123..53f9ef39d 100644 --- a/libgphoto2_port/gphoto2/gphoto2-port-info-list.h +++ b/libgphoto2_port/gphoto2/gphoto2-port-info-list.h @@ -94,6 +94,9 @@ int gp_port_info_list_get_info (GPPortInfoList *list, int n, GPPortInfo *info); const char *gp_port_message_codeset (const char*); +int gp_port_init_localedir (const char *localedir); + + /** * Name of the environment variable which may contain the path where * to look for the IO libs. If this environment variable is not defined, diff --git a/libgphoto2_port/libgphoto2_port/gphoto2-port-info-list.c b/libgphoto2_port/libgphoto2_port/gphoto2-port-info-list.c index 83c531f30..ad131ef6b 100644 --- a/libgphoto2_port/libgphoto2_port/gphoto2-port-info-list.c +++ b/libgphoto2_port/libgphoto2_port/gphoto2-port-info-list.c @@ -27,6 +27,7 @@ #include <gphoto2/gphoto2-port-info-list.h> +#include <errno.h> #include <stdlib.h> #include <string.h> #include <stdio.h> @@ -63,13 +64,64 @@ struct _GPPortInfoList { /** + * \brief Initialize the localedir directory for the libgphoto2_port gettext domain + * + * Override the localedir directory libgphoto2_port uses for its message + * translations. + * + * This function is called by the gp_init_localedir() function, so if + * you are calling that already, there is no need to call + * gp_port_init_localedir() yourself. + * + * You only need to call this if you have a non-standard installation + * where the locale files are at a location which differs from the + * compiled in default location. + * + * If you need to call this function, call it before calling any + * non-initialization function. + * + * Internally, this will make sure bindtextdomain() is called for the + * relevant gettext text domain(s). + * + * \param localedir Root directory of libgphoto2_port's localization files. + * If NULL, use the compiled in default value, which + * will be something like "/usr/share/locale". + * \return gphoto2 error code. + */ +int +gp_port_init_localedir (const char *localedir) +{ + static int locale_initialized = 0; + if (locale_initialized) { + gp_log(GP_LOG_DEBUG, "gp_port_init_localedir", + "ignoring late call (localedir value %s)", + localedir?localedir:"NULL"); + return GP_OK; + } + const char *const actual_localedir = (localedir?localedir:LOCALEDIR); + const char *const gettext_domain = GETTEXT_PACKAGE_LIBGPHOTO2_PORT; + if (bindtextdomain (gettext_domain, actual_localedir) == NULL) { + if (errno == ENOMEM) + return GP_ERROR_NO_MEMORY; + return GP_ERROR; + } + gp_log(GP_LOG_DEBUG, "gp_port_init_localedir", + "localedir has been set to %s%s", + actual_localedir, + localedir?"":" (compile-time default)"); + locale_initialized = 1; + return GP_OK; +} + + +/** * \brief Specify codeset for translations * - * This function specifies the codeset that are used for the translated + * This function specifies the codeset that is used for the translated * strings that are passed back by the libgphoto2_port functions. * - * This function is called by the gp_message_codeset() function, there is - * no need to call it yourself. + * This function is called by the gp_message_codeset() function, so + * there is no need to call it yourself. * * \param codeset new codeset to use * \return the previous codeset @@ -99,7 +151,7 @@ gp_port_info_list_new (GPPortInfoList **list) * We put this in here because everybody needs to call this function * before accessing ports... */ - bindtextdomain (GETTEXT_PACKAGE_LIBGPHOTO2_PORT, LOCALEDIR); + gp_port_init_localedir (NULL); C_MEM (*list = calloc (1, sizeof (GPPortInfoList))); diff --git a/libgphoto2_port/libgphoto2_port/libgphoto2_port.ver b/libgphoto2_port/libgphoto2_port/libgphoto2_port.ver index 0947e2bd9..e8886fc54 100644 --- a/libgphoto2_port/libgphoto2_port/libgphoto2_port.ver +++ b/libgphoto2_port/libgphoto2_port/libgphoto2_port.ver @@ -27,6 +27,7 @@ LIBGPHOTO2_5_0 { gp_port_info_list_lookup_name; gp_port_info_list_lookup_path; gp_port_info_list_new; + gp_port_init_localedir; gp_port_library_version; gp_port_message_codeset; gp_port_new; @@ -90,7 +91,7 @@ LIBGPHOTO2_INTERNAL { # # The asm(".symver ...") constructs will put stuff into this node, # # it needs to stay. # # Currently used by: -# # gp_port_set_info, gp_port_get_info, +# # gp_port_set_info, gp_port_get_info, # # gp_port_info_list_append, gp_port_info_list_get_info # # # Add new exported functions here too! |