Added options loading
options_load loads the config file at ~/.m4kc/m4kc.conf and is called within options_init. Entering in adbormal values for parameters causes the second page to segfault. Will attempt fix in next commit.
This commit is contained in:
@@ -1,3 +1,6 @@
|
||||
#include <stdio.h>
|
||||
#include "data.h"
|
||||
#include "string.h"
|
||||
#include "options.h"
|
||||
|
||||
Options options = { 0 };
|
||||
@@ -19,5 +22,44 @@ int options_init (void) {
|
||||
}
|
||||
};
|
||||
|
||||
int err = options_load();
|
||||
return err;
|
||||
}
|
||||
|
||||
/* options_load
|
||||
* Loads options from the configuration file into the options struct. Returns 0
|
||||
* on success, non-zero on failure.
|
||||
*/
|
||||
int options_load (void) {
|
||||
const char *path = data_getOptionsFileName();
|
||||
|
||||
// If the file doesn't exist, calmly exit the function and just use
|
||||
// default values
|
||||
FILE *file = fopen(path, "r");
|
||||
if (file == NULL) { return 0; }
|
||||
|
||||
int version;
|
||||
fscanf(file, "%i", &version);
|
||||
if (version != 0) { return 1; }
|
||||
|
||||
char parameter[16];
|
||||
while (1) {
|
||||
if (fscanf(file, "%15s", parameter) == EOF) { break; }
|
||||
|
||||
#define PARAMETER(what, how, where) \
|
||||
else if (strcmp(parameter, #what) == 0) { \
|
||||
fscanf(file, how, where); \
|
||||
}
|
||||
PARAMETER(fogType, "%i", &options.fogType)
|
||||
PARAMETER(drawDistance, "%i", &options.drawDistance)
|
||||
PARAMETER(trapMouse, "%i", &options.trapMouse)
|
||||
PARAMETER(fov, "%lf", &options.fov)
|
||||
PARAMETER(username, "%7s", username)
|
||||
#undef PARAMETER
|
||||
}
|
||||
|
||||
options.username.cursor = strlen(username);
|
||||
|
||||
fclose(file);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -12,3 +12,4 @@ typedef struct {
|
||||
extern Options options;
|
||||
|
||||
int options_init (void);
|
||||
int options_load (void);
|
||||
|
||||
Reference in New Issue
Block a user