Browse Source

allow loading of other locals on top of the current locale (to enable unfilled strings to default to english if necessary)

jp9000 12 years ago
parent
commit
50666040e5
2 changed files with 17 additions and 7 deletions
  1. 16 7
      libobs/util/text-lookup.c
  2. 1 0
      libobs/util/text-lookup.h

+ 16 - 7
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)

+ 1 - 0
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);