summaryrefslogtreecommitdiff
path: root/src/catalog.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/catalog.c')
-rw-r--r--src/catalog.c21
1 files changed, 14 insertions, 7 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];
}