Further langauge loading improvements:

0) add more error logging and NULL checking
1) changed missing characters to lower ascii for now
This commit is contained in:
GammaTendonNine 2020-10-23 01:10:04 -05:00
parent 7874550d10
commit 3ecd6bd027
2 changed files with 17 additions and 10 deletions

View File

@ -29,7 +29,7 @@ void load_language(char *jsonTxt, s8 language){
cJSON *json = cJSON_ParseWithOpts(jsonTxt, &endTxt, 1); cJSON *json = cJSON_ParseWithOpts(jsonTxt, &endTxt, 1);
if(*endTxt != 0) { if(*endTxt != 0) {
fprintf(stderr, "Error before: %s\n", endTxt); fprintf(stderr, "Loading File: Error before: %s\n", endTxt);
exit(1); exit(1);
} }
@ -221,7 +221,12 @@ void alloc_languages(char *exePath, char *gamedir){
printf("Loading File: %s\n", file); printf("Loading File: %s\n", file);
char *jsonTxt = read_file(file); char *jsonTxt = read_file(file);
if(jsonTxt != NULL){
load_language(jsonTxt, languagesAmount - 1); load_language(jsonTxt, languagesAmount - 1);
}else{
fprintf(stderr, "Loading File: Error reading '%s'\n", file);
exit(1);
}
free(jsonTxt); free(jsonTxt);
free(file); free(file);
} }
@ -234,7 +239,7 @@ void alloc_languages(char *exePath, char *gamedir){
if(languagesAmount > 0){ if(languagesAmount > 0){
languages = realloc(languages, sizeof(struct LanguageEntry*) * (languagesAmount)); languages = realloc(languages, sizeof(struct LanguageEntry*) * (languagesAmount));
}else{ }else{
printf("Loading File: No language files found, aborting.\n"); fprintf(stderr, "Loading File: No language files found, aborting.\n");
exit(1); exit(1);
} }
} }

View File

@ -1,4 +1,6 @@
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include "txtconv.h" #include "txtconv.h"
struct Character charmap[358] = { struct Character charmap[358] = {
@ -62,10 +64,10 @@ struct Character charmap[358] = {
// *MISSING* SPECIAL CHARACTERS WITH SUBSTITIONS // *MISSING* SPECIAL CHARACTERS WITH SUBSTITIONS
// *NOTE: when adding characters here, don't forget to increment charmap size // *NOTE: when adding characters here, don't forget to increment charmap size
// (value is number of '}}' in this file minus 1) // (value is number of '}}' in this file minus 1)
{"{00227}", {0x61, NULL}}, // latin small letter a with tilde (PT_br) {"{00227}", {0x24, NULL}}, // latin small letter a with tilde (PT_br)
{"{00195}", {0x65, NULL}}, // latin capital letter A with tilde (PT_br) {"{00195}", {0x0a, NULL}}, // latin capital letter A with tilde (PT_br)
{"{00245}", {0x91, NULL}}, // latin small letter o with tilde (PT_br) {"{00245}", {0x32, NULL}}, // latin small letter o with tilde (PT_br)
{"{00213}", {0x95, NULL}}, // latin capital letter O with tilde (PT_br) {"{00213}", {0x18, NULL}}, // latin capital letter O with tilde (PT_br)
{"{00236}", {0x2c, NULL}}, // latin small letter i with grave (ES_es) {"{00236}", {0x2c, NULL}}, // latin small letter i with grave (ES_es)
{"{07765}", {0x33, NULL}} // latin small letter p with acute (ES_la) {"{07765}", {0x33, NULL}} // latin small letter p with acute (ES_la)
}; };