Reads settings

maybe
This commit is contained in:
CTurt 2014-12-07 15:07:13 +00:00
parent 3251bc553c
commit 4654c44c0b

View file

@ -24,6 +24,23 @@ struct settings defaultSettings = {
Tap: 'T',
};
static bool getSetting(char *name, char *src, char *dest) {
char *start = strstr(src, name) + strlen(name);
if(start) {
char *end = start + strlen(start);
if(strstr(start, "\n") < end) end = strstr(start, "\n") - 1;
size_t size = (size_t)end - (size_t)start;
strncpy(dest, start, size);
dest[size] = '\0';
return true;
}
return false;
}
bool readSettings(void) {
FILE *f;
size_t len = 0;
@ -46,7 +63,31 @@ bool readSettings(void) {
return false;
}
fread(buffer, 1, len, f);
char setting[64] = { '\0', };
getSetting("circlePad: ", buffer, setting);
if(strcmp(setting, "mouse") == 0) settings.circlePad = mouse;
else if(strcmp(setting, "joystick") == 0) settings.circlePad = joystick;
getSetting("touch: ", buffer, setting);
if(strcmp(setting, "mouse") == 0) settings.touch = mouse;
else if(strcmp(setting, "joystick") == 0) settings.touch = joystick;
if(getSetting("A: ", buffer, setting)) settings.A = setting[0];
if(getSetting("B: ", buffer, setting)) settings.B = setting[0];
if(getSetting("X: ", buffer, setting)) settings.X = setting[0];
if(getSetting("Y: ", buffer, setting)) settings.Y = setting[0];
if(getSetting("L: ", buffer, setting)) settings.L = setting[0];
if(getSetting("R: ", buffer, setting)) settings.R = setting[0];
if(getSetting("Left: ", buffer, setting)) settings.Left = setting[0];
if(getSetting("Right: ", buffer, setting)) settings.Right = setting[0];
if(getSetting("Up: ", buffer, setting)) settings.Up = setting[0];
if(getSetting("Down: ", buffer, setting)) settings.Down = setting[0];
if(getSetting("Start: ", buffer, setting)) settings.Start = setting[0];
if(getSetting("Select: ", buffer, setting)) settings.Select = setting[0];
if(getSetting("Tap: ", buffer, setting)) settings.Tap = setting[0];
fclose(f);