Simplified config parsing

dev
shariq 8 years ago
parent 8fa5278dc6
commit b761fae326
  1. 24
      assets/config.cfg
  2. 20
      src/config_vars.c
  3. 62
      src/input.c
  4. 2
      src/input.h

@ -1,13 +1,13 @@
msaa_levels: 4
debug_draw_color: 1.000, 0.000, 0.000, 1.000
render_width: 800
fog_density: 0.0020
render_height: 600
fog_mode: 2
fog_color: 0.500, 0.200, 0.200
fog_max_dist: 150.0000
msaa_enabled: true
fog_start_dist: 20.0000
debug_draw_enabled: false
debug_draw_mode: 0
ambient_light: 0.100, 0.100, 0.100
debug_draw_color : 1.000, 0.000, 0.000, 1.000
render_width : 800
fog_density : 0.0020
render_height : 600
fog_mode : 2
fog_color : 0.500, 0.200, 0.200
fog_max_dist : 150.0000
msaa_enabled : true
fog_start_dist : 20.0000
debug_draw_enabled : false
debug_draw_mode : 0
ambient_light : 0.100, 0.100, 0.100

@ -60,26 +60,25 @@ int config_vars_load(const char* filename)
while(fgets(line_buffer, MAX_LINE_LEN - 1, config_file))
{
current_line++;
line_buffer[strcspn(line_buffer, "\r\n")] = '\0';
memset(key_str, '\0', HASH_MAX_KEY_LEN);
if(line_buffer[0] == '#' || strlen(line_buffer) == 0)
continue;
log_message("Line : %s", line_buffer);
memset(key_str, '\0', HASH_MAX_KEY_LEN);
char* value_str = strstr(line_buffer, ":");
if(!value_str)
{
log_warning("Malformed value in config file %s, line %d", filename, current_line);
continue;
}
int key_str_len = value_str - line_buffer;
strncpy(key_str, line_buffer, key_str_len);
if(key_str_len >= HASH_MAX_KEY_LEN)
key_str[HASH_MAX_KEY_LEN - 1] = '\0';
else
key_str[key_str_len] = '\0';
value_str++; /* Ignore the colon(:) */
if(sscanf(line_buffer, " %1024[^: ] : %*s", key_str) != 1)
{
log_warning("Unable to read key in config file %s, line %d", filename, current_line);
continue;
}
struct Variant* value = hashmap_value_get(cvars, key_str);
if(!value)
@ -112,7 +111,6 @@ int config_vars_save(const char* filename)
{
memset(variant_str, '\0', MAX_VARIANT_STR_LEN);
variant_to_str(value, variant_str, MAX_VARIANT_STR_LEN);
log_message("Writing : %s: %s", key, variant_str);
fprintf(config_file, "%s: %s\n", key, variant_str);
}
log_message("Config file %s written.", filename);

@ -6,6 +6,7 @@
#include "platform.h"
#include "log.h"
#include "gui.h"
#include "file_io.h"
struct Input_Map
{
@ -42,6 +43,67 @@ void input_cleanup(void)
array_free(input_map_list);
}
int input_load(const char* filename)
{
int success = 0;
/* const int MAX_KEYBIND_LEN = 128; */
/* const int MAX_LINE_LEN = 512; */
/* FILE* config_file = io_file_open(filename, "r"); */
/* if(!config_file) */
/* { */
/* log_error("input:vars_load", "Could not open %s", filename); */
/* return success; */
/* } */
/* /\* Read line by line, ignore comments *\/ */
/* char key_str[MAX_KEYBIND_LEN]; */
/* char line_buffer[MAX_LINE_LEN]; */
/* memset(key_str, '\0', MAX_KEYBIND_LEN); */
/* memset(line_buffer, '\0', MAX_LINE_LEN); */
/* int current_line = 0; */
/* while(fgets(line_buffer, MAX_LINE_LEN - 1, config_file)) */
/* { */
/* current_line++; */
/* line_buffer[strcspn(line_buffer, "\r\n")] = '\0'; */
/* if(line_buffer[0] == '#' || strlen(line_buffer) == 0) */
/* continue; */
/* log_message("Line : %s", line_buffer); */
/* memset(key_str, '\0', MAX_KEYBIND_LEN); */
/* char* value_str = strstr(line_buffer, ":"); */
/* if(!value_str) */
/* { */
/* log_warning("Malformed value in config file %s, line %d", filename, current_line); */
/* continue; */
/* } */
/* int key_str_len = value_str - line_buffer; */
/* strncpy(key_str, line_buffer, key_str_len); */
/* if(key_str_len >= MAX_KEYBIND_LEN) */
/* key_str[MAX_KEYBIND_LEN - 1] = '\0'; */
/* else */
/* key_str[key_str_len] = '\0'; */
/* value_str++; /\* Ignore the colon(:) *\/ */
/* struct Variant* value = hashmap_value_get(cvars, key_str); */
/* if(!value) */
/* { */
/* log_warning("Unknown value in config file %s, line %d", filename, current_line); */
/* continue; */
/* } */
/* variant_from_str(value, value_str, value->type); */
/* } */
/* success = 1; */
/* fclose(config_file); */
return success;
}
int input_save(const char* filename)
{
}
void input_on_mousemotion(int x, int y, int xrel, int yrel)
{
/* TODO: This is temporary. After proper event loop is added this code should not be here */

@ -409,6 +409,8 @@ enum Keyboard_Scancode
};
void input_init(void);
int input_load(const char* filename);
int input_save(const char* filename);
void input_cleanup(void);
int input_mousebutton_state_get(uint button, int state_type);
int input_is_key_pressed(int key);

Loading…
Cancel
Save