mirror of
https://gitlab.com/dosowisko.net/libsuperderpy.git
synced 2025-02-01 19:16:44 +01:00
a little reorganization of config manager structure
This commit is contained in:
parent
52aa7c3f1e
commit
c1cdde9f92
2 changed files with 10 additions and 14 deletions
22
src/config.c
22
src/config.c
|
@ -10,27 +10,22 @@ struct ConfigOption {
|
||||||
struct ConfigOption *next;
|
struct ConfigOption *next;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Config {
|
struct ConfigOption *config;
|
||||||
FILE *file;
|
|
||||||
struct ConfigOption *list;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct Config config;
|
|
||||||
|
|
||||||
void InitConfig() {
|
void InitConfig() {
|
||||||
config.file = fopen("SuperDerpy.ini","r+");
|
FILE *file = fopen("SuperDerpy.ini","r+");
|
||||||
if (! config.file) { fopen("SuperDerpy.ini","w+"); return; }
|
if (! file) { fopen("SuperDerpy.ini","w+"); return; }
|
||||||
char string[255];
|
char string[255];
|
||||||
char section[255] = "[MuffinAttack]";
|
char section[255] = "[MuffinAttack]";
|
||||||
struct ConfigOption *old = NULL;
|
struct ConfigOption *old = NULL;
|
||||||
while ( fgets (string , 255 , config.file) != NULL ) {
|
while ( fgets (string , 255 , file) != NULL ) {
|
||||||
if (string[0]=='#') { continue; }
|
if (string[0]=='#') { continue; }
|
||||||
if (string[strlen(string)-1]=='\n') string[strlen(string)-1]='\0';
|
if (string[strlen(string)-1]=='\n') string[strlen(string)-1]='\0';
|
||||||
if (string[0]=='[') { strcpy(section, string); continue; }
|
if (string[0]=='[') { strcpy(section, string); continue; }
|
||||||
bool before=true;
|
bool before=true;
|
||||||
struct ConfigOption *new = malloc(sizeof(struct ConfigOption));
|
struct ConfigOption *new = malloc(sizeof(struct ConfigOption));
|
||||||
if (old==NULL) {
|
if (old==NULL) {
|
||||||
config.list = new;
|
config = new;
|
||||||
old = new;
|
old = new;
|
||||||
} else { old->next = new; old = new; }
|
} else { old->next = new; old = new; }
|
||||||
new->section = malloc(sizeof(char)*255);
|
new->section = malloc(sizeof(char)*255);
|
||||||
|
@ -49,7 +44,7 @@ void InitConfig() {
|
||||||
//printf("%s", temp);
|
//printf("%s", temp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fclose(config.file);
|
fclose(file);
|
||||||
|
|
||||||
/* old = config.list;
|
/* old = config.list;
|
||||||
while (old!=NULL) {
|
while (old!=NULL) {
|
||||||
|
@ -59,7 +54,7 @@ void InitConfig() {
|
||||||
}
|
}
|
||||||
|
|
||||||
char* ReadConfigOption(char* section, char* name) {
|
char* ReadConfigOption(char* section, char* name) {
|
||||||
struct ConfigOption *old = config.list;
|
struct ConfigOption *old = config;
|
||||||
char *ret = malloc(sizeof(char)*255);
|
char *ret = malloc(sizeof(char)*255);
|
||||||
while (old!=NULL) {
|
while (old!=NULL) {
|
||||||
if (!strcmp(section, old->section) && !strcmp(name, old->name)) {
|
if (!strcmp(section, old->section) && !strcmp(name, old->name)) {
|
||||||
|
@ -73,7 +68,8 @@ char* ReadConfigOption(char* section, char* name) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void DeinitConfig() {
|
void DeinitConfig() {
|
||||||
struct ConfigOption *old = config.list;
|
//store memory state to file here
|
||||||
|
struct ConfigOption *old = config;
|
||||||
while (old!=NULL) {
|
while (old!=NULL) {
|
||||||
struct ConfigOption *prev = old;
|
struct ConfigOption *prev = old;
|
||||||
old=old->next;
|
old=old->next;
|
||||||
|
|
|
@ -231,7 +231,7 @@ int main(int argc, char **argv){
|
||||||
al_flip_display();
|
al_flip_display();
|
||||||
|
|
||||||
al_start_timer(game.timer);
|
al_start_timer(game.timer);
|
||||||
printf("%s\n", ReadConfigOption("[MuffinAttack]", "lol"));
|
|
||||||
game.loadstate = GAMESTATE_LOADING;
|
game.loadstate = GAMESTATE_LOADING;
|
||||||
PreloadGameState(&game);
|
PreloadGameState(&game);
|
||||||
LoadGameState(&game);
|
LoadGameState(&game);
|
||||||
|
|
Loading…
Reference in a new issue