From 50666040e56f484aeedc8169eca5bf05457bd4e4 Mon Sep 17 00:00:00 2001 From: jp9000 Date: Tue, 17 Dec 2013 13:55:09 -0700 Subject: [PATCH] allow loading of other locals on top of the current locale (to enable unfilled strings to default to english if necessary) --- libobs/util/text-lookup.c | 23 ++++++++++++++++------- libobs/util/text-lookup.h | 1 + 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/libobs/util/text-lookup.c b/libobs/util/text-lookup.c index 620fe303a..637ec88ef 100644 --- a/libobs/util/text-lookup.c +++ b/libobs/util/text-lookup.c @@ -357,24 +357,33 @@ static inline bool lookup_getstring(const char *lookup_val, lookup_t text_lookup_create(const char *path) { - struct text_lookup *lookup; + struct text_lookup *lookup = bmalloc(sizeof(struct text_lookup)); + memset(lookup, 0, sizeof(struct text_lookup)); + + if (!text_lookup_add(lookup, path)) { + bfree(lookup); + lookup = NULL; + } + + return lookup; +} + +bool text_lookup_add(lookup_t lookup, const char *path) +{ struct dstr file_str; char *temp = NULL; FILE *file; file = os_fopen(path, "rb"); if (!file) - return NULL; + return false; os_fread_utf8(file, &temp); dstr_init_move_array(&file_str, temp); fclose(file); if (!file_str.array) - return NULL; - - lookup = bmalloc(sizeof(struct text_lookup)); - memset(lookup, 0, sizeof(struct text_lookup)); + return false; lookup->top = bmalloc(sizeof(struct text_node)); memset(lookup->top, 0, sizeof(struct text_node)); @@ -383,7 +392,7 @@ lookup_t text_lookup_create(const char *path) lookup_addfiledata(lookup, file_str.array); dstr_free(&file_str); - return lookup; + return true; } void text_lookup_destroy(lookup_t lookup) diff --git a/libobs/util/text-lookup.h b/libobs/util/text-lookup.h index 6f9e2c0a5..4461dad9e 100644 --- a/libobs/util/text-lookup.h +++ b/libobs/util/text-lookup.h @@ -43,6 +43,7 @@ typedef struct text_lookup *lookup_t; /* functions */ EXPORT lookup_t text_lookup_create(const char *path); +EXPORT bool text_lookup_add(lookup_t lookup, const char *path); EXPORT void text_lookup_destroy(lookup_t lookup); EXPORT bool text_lookup_getstr(lookup_t lookup, const char *lookup_val, const char **out);