Use the key=value format for bgm.conf too

This commit is contained in:
Andrei "Akari" Alexeyev 2017-03-11 23:57:03 +02:00
parent b78eadc202
commit 38e13b9855
4 changed files with 20 additions and 47 deletions

View file

@ -1,13 +1,13 @@
bgm_stage1 Generic Stage 1 Theme
bgm_stage2 Generic Stage 2 Theme
bgm_stage3 Generic Stage 3 Theme
bgm_stage4 Generic Stage 4 Theme
bgm_stage5 Generic Stage 5 Theme
bgm_stage6 Generic Stage 6 Theme
bgm_stage1 = Generic Stage 1 Theme
bgm_stage2 = Generic Stage 2 Theme
bgm_stage3 = Generic Stage 3 Theme
bgm_stage4 = Generic Stage 4 Theme
bgm_stage5 = Generic Stage 5 Theme
bgm_stage6 = Generic Stage 6 Theme
bgm_stage1boss Stage 1 Boss Theme
bgm_stage2boss Stage 2 Boss Theme
bgm_stage3boss Stage 3 Boss Theme
bgm_stage4boss Stage 4 Boss Theme
bgm_stage5boss Stage 5 Boss Theme
bgm_stage6boss Stage 6 Boss Theme
bgm_stage1boss = Stage 1 Boss Theme
bgm_stage2boss = Stage 2 Boss Theme
bgm_stage3boss = Stage 3 Boss Theme
bgm_stage4boss = Stage 4 Boss Theme
bgm_stage5boss = Stage 5 Boss Theme
bgm_stage6boss = Stage 6 Boss Theme

View file

@ -68,42 +68,13 @@ static void bgm_cfg_volume_callback(ConfigIndex idx, ConfigValue v) {
static void load_bgm_descriptions(void) {
char *fullname = strjoin(get_prefix(), "bgm/bgm.conf", NULL);
FILE *fp = fopen(fullname, "rt");
bgm_descriptions = parse_keyvalue_file(fullname, 16);
free(fullname);
bgm_descriptions = hashtable_new_stringkeys(16);
if(fp == NULL) {
return;
}
char line[256];
while(fgets(line, sizeof(line), fp)) {
char *rem;
while((rem = strchr(line,'\n')) != NULL) *rem = '\0';
while((rem = strchr(line,'\r')) != NULL) *rem = '\0';
while((rem = strchr(line,'\t')) != NULL) *rem = ' ';
if((rem = strchr(line,' ' )) == NULL) {
if(strlen(line) > 0)
warnx("load_bgm_description(): illegal string format. See README.");
continue;
}
*(rem++)='\0';
char *value = strjoin("BGM: ", rem, NULL);
hashtable_set_string(bgm_descriptions, line, value);
printf("Music %s is now known as \"%s\".\n", line, value);
}
fclose(fp);
return;
}
static inline char* get_bgm_desc(char *name) {
return (char*)hashtable_get_string(bgm_descriptions, name);
return bgm_descriptions ? (char*)hashtable_get_string(bgm_descriptions, name) : NULL;
}
void resume_bgm(void) {
@ -193,6 +164,9 @@ void audio_init(void) {
void audio_shutdown(void) {
audio_backend_shutdown();
hashtable_foreach(bgm_descriptions, hashtable_iter_free_data, NULL);
hashtable_free(bgm_descriptions);
if(bgm_descriptions) {
hashtable_foreach(bgm_descriptions, hashtable_iter_free_data, NULL);
hashtable_free(bgm_descriptions);
}
}

View file

@ -35,7 +35,6 @@ void* load_animation(const char *filename, unsigned int flags) {
ani->cols = atoi((char*)hashtable_get_string(ht, "cols"));
ani->speed = atoi((char*)hashtable_get_string(ht, "speed"));
hashtable_foreach(ht, hashtable_iter_free_data, NULL);
hashtable_print_stringkeys(ht);
hashtable_free(ht);
if(ani->rows < 1) ANIFAIL("rows")

View file

@ -255,7 +255,7 @@ char* read_all(const char *filename, int *outsize) {
bool parse_keyvalue_stream_cb(SDL_RWops *strm, KVCallback callback, void *data) {
const size_t bufsize = 128;
#define SYNTAXERROR { warnx("%s(): syntax error on line %i, aborted! [%s:%i]\n", __func__, line, __FILE__, __LINE__); return false; }
#define SYNTAXERROR { warnx("%s(): syntax error on line %i, aborted! [%s:%i]", __func__, line, __FILE__, __LINE__); return false; }
#define BUFFERERROR { warnx("%s(): string exceed the limit of %i, aborted! [%s:%i]", __func__, bufsize, __FILE__, __LINE__); return false; }
int i = 0, found, line = 0;