diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/catalog.c | 21 | ||||
-rw-r--r-- | src/catalog.h | 2 | ||||
-rw-r--r-- | src/i18n.c | 5 | ||||
-rw-r--r-- | src/i18n.h | 3 |
4 files changed, 23 insertions, 8 deletions
diff --git a/src/catalog.c b/src/catalog.c index 3e40bf2..9550631 100644 --- a/src/catalog.c +++ b/src/catalog.c @@ -11,12 +11,16 @@ #include "catalog.h" + static const char *const CATALOG_NAME = NAME; static nl_catd catalog_descriptor = NULL; +static size_t +msgs_length = 0U; + static const char *const NLSPATH = LOCALEDIR "/%l_%t/LC_MESSAGES/%N.cat" ":" LOCALEDIR "/%l/LC_MESSAGES/%N.cat"; @@ -26,7 +30,7 @@ NLSPATH_KEY = "NLSPATH"; int -i18n_init(void) { +i18n_init_msgs(const char *const MSGS[]) { int rc = -1; static const int should_overwrite = 0; @@ -42,6 +46,11 @@ i18n_init(void) { goto out; } + msgs_length = 0U; + while (MSGS[msgs_length] != NULL) { + msgs_length++; + } + rc = 0; out: return rc; @@ -66,14 +75,12 @@ out: return rc; } -/** - * Infallible: always returns a valid string, no matter what. - */ const char * s(const char* const MSGS[], const int msg_id) { - assert(msg_id > 0); - // FIXME: assert within bounds! - // printf("sizeof(MSGS): %ld\n", sizeof(MSGS)); + assert(msg_id >= 0); + if (msgs_length != 0U) { + assert((size_t)msg_id < msgs_length); + } if (catalog_descriptor == NULL) { return MSGS[msg_id]; } diff --git a/src/catalog.h b/src/catalog.h index 25adbeb..3acb24d 100644 --- a/src/catalog.h +++ b/src/catalog.h @@ -1,5 +1,5 @@ int -i18n_init(void); +i18n_init_msgs(const char *const MSGS[]); int i18n_destroy(void); @@ -54,3 +54,8 @@ const char * _(const int msg_id) { return s(MSGS, msg_id); } + +int +i18n_init(void) { + return i18n_init_msgs(MSGS); +} @@ -45,3 +45,6 @@ MSGS[]; const char * _(const int msg_id); + +int +i18n_init(void); |