- struct WinConf * winconfs = try_malloc(4 * sizeof(struct WinConf),
- world, f_name);
- create_winconf('i', &winconfs[0], draw_info_win);
- create_winconf('k', &winconfs[1], draw_keys_win);
- create_winconf('l', &winconfs[2], draw_log_win);
- create_winconf('m', &winconfs[3], draw_map_win);
+ char * err_o = "Trouble in init_winconfs() with opendir().";
+ char * err_r = "Trouble in init_winconfs() with readdir().";
+ char * err_c = "Trouble in init_winconfs() with closedir().";
+
+ DIR * dp = opendir("config/windows");
+ exit_err(NULL == dp, world, err_o);
+ struct dirent * fn;
+ errno = 0;
+ char * winconf_ids = try_malloc(256, world, f_name);
+ uint8_t i = 0;
+ char id;
+ while (NULL != (fn = readdir(dp)))
+ {
+ if ( 5 == strlen(fn->d_name)
+ && fn->d_name == strstr(fn->d_name, "Win_"))
+ {
+ id = fn->d_name[4];
+ winconf_ids[i] = id;
+ i++;
+ }
+ }
+ winconf_ids[i] = '\0';
+ exit_err(errno, world, err_r);
+ exit_err(closedir(dp), world, err_c);
+ world->winconf_ids = try_malloc(strlen(winconf_ids + 1), world, f_name);
+ memcpy(world->winconf_ids, winconf_ids, strlen(winconf_ids) + 1);
+ free(winconf_ids);
+
+ struct WinConf * winconfs;
+ winconfs = try_malloc(strlen(world->winconf_ids) * sizeof(struct WinConf),
+ world, f_name);
+ i = 0;
+ while (0 != (id = get_next_winconf_id(world)))
+ {
+ create_winconf(id, &winconfs[i]);
+ i++;
+ }