diff --git a/ipl/ini.c b/ipl/ini.c index 3e4401e..71ce787 100755 --- a/ipl/ini.c +++ b/ipl/ini.c @@ -1,5 +1,6 @@ /* * Copyright (c) 2018 naehrwert +* Copyright (C) 2018 CTCaer * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, @@ -45,10 +46,6 @@ int ini_parse(link_t *dst, char *ini_path) f_gets(lbuf, 512, &fp); lblen = strlen(lbuf); - //Skip empty lines and comments. - if (lblen <= 1 || lbuf[0] == '#') - continue; - //Remove trailing newline. if (lbuf[lblen - 1] == '\n') lbuf[lblen - 1] = 0; @@ -68,9 +65,58 @@ int ini_parse(link_t *dst, char *ini_path) csec = (ini_sec_t *)malloc(sizeof(ini_sec_t)); csec->name = _strdup(&lbuf[1]); + csec->type = INI_CHOICE; list_init(&csec->kvs); } - else if (csec) //Extract key/value. + else if (lblen > 2 && lbuf[0] == '{') //Create new caption. + { + if (csec) + { + list_append(dst, &csec->link); + csec = NULL; + } + + u32 i; + for (i = 0; i < lblen && lbuf[i] != '\n' && lbuf[i] != '}'; i++) + ; + lbuf[i] = 0; + + csec = (ini_sec_t *)malloc(sizeof(ini_sec_t)); + csec->name = _strdup(&lbuf[1]); + csec->type = INI_CAPTION; + csec->color = 0xFF0AB9E6; + } + else if (lblen > 2 && lbuf[0] == '#') //Create empty lines and comments. + { + if (csec) + { + list_append(dst, &csec->link); + csec = NULL; + } + + u32 i; + for (i = 0; i < lblen && lbuf[i] != '\n'; i++) + ; + lbuf[i] = 0; + + csec = (ini_sec_t *)malloc(sizeof(ini_sec_t)); + csec->name = _strdup(&lbuf[1]); + csec->type = INI_COMMENT; + + } + else if (lblen <= 1) + { + if (csec) + { + list_append(dst, &csec->link); + csec = NULL; + } + + csec = (ini_sec_t *)malloc(sizeof(ini_sec_t)); + csec->name = NULL; + csec->type = INI_NEWLINE; + } + else if (csec->type == INI_CHOICE) //Extract key/value. { u32 i; for (i = 0; i < lblen && lbuf[i] != '\n' && lbuf[i] != '='; i++) @@ -94,13 +140,19 @@ int ini_parse(link_t *dst, char *ini_path) void ini_free(link_t *dst) { + if (dst == NULL) + return; + LIST_FOREACH_ENTRY(ini_sec_t, ini_sec, dst, link) { - LIST_FOREACH_ENTRY(ini_kv_t, kv, &ini_sec->kvs, link) + if (ini_sec->type == INI_CHOICE) { - free(kv->key); - free(kv->val); - free(kv); + LIST_FOREACH_ENTRY(ini_kv_t, kv, &ini_sec->kvs, link) + { + free(kv->key); + free(kv->val); + free(kv); + } } free(ini_sec->name); free(ini_sec); diff --git a/ipl/ini.h b/ipl/ini.h index 6f8d692..af6b367 100755 --- a/ipl/ini.h +++ b/ipl/ini.h @@ -1,5 +1,6 @@ /* * Copyright (c) 2018 naehrwert +* Copyright (C) 2018 CTCaer * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, @@ -20,6 +21,12 @@ #include "types.h" #include "list.h" +#define INI_CHOICE 3 +#define INI_CAPTION 5 +#define INI_CHGLINE 6 +#define INI_NEWLINE 0xFE +#define INI_COMMENT 0xFF + typedef struct _ini_kv_t { char *key; @@ -32,6 +39,8 @@ typedef struct _ini_sec_t char *name; link_t kvs; link_t link; + u32 type; + u32 color; } ini_sec_t; int ini_parse(link_t *dst, char *ini_path); diff --git a/ipl/main.c b/ipl/main.c index c10430a..9b3e985 100755 --- a/ipl/main.c +++ b/ipl/main.c @@ -1333,7 +1333,7 @@ out:; void launch_firmware() { - u8 max_entries = 16; + u8 max_entries = 61; ini_sec_t *cfg_sec = NULL; LIST_INIT(ini_sections); @@ -1346,23 +1346,28 @@ void launch_firmware() if (ini_parse(&ini_sections, "hekate_ipl.ini")) { // Build configuration menu. - ment_t *ments = (ment_t *)malloc(sizeof(ment_t) * max_entries); + ment_t *ments = (ment_t *)malloc(sizeof(ment_t) * (max_entries + 3)); ments[0].type = MENT_BACK; ments[0].caption = "Back"; - u32 i = 1; + ments[1].type = MENT_CHGLINE; + + u32 i = 2; LIST_FOREACH_ENTRY(ini_sec_t, ini_sec, &ini_sections, link) { - if (!strcmp(ini_sec->name, "config")) + if (!strcmp(ini_sec->name, "config") || + ini_sec->type == INI_COMMENT || ini_sec->type == INI_NEWLINE) continue; - ments[i].type = MENT_CHOICE; + ments[i].type = ini_sec->type; ments[i].caption = ini_sec->name; ments[i].data = ini_sec; + if (ini_sec->type == MENT_CAPTION) + ments[i].color = ini_sec->color; i++; if (i > max_entries) break; } - if (i > 1) + if (i > 2) { memset(&ments[i], 0, sizeof(ment_t)); menu_t menu = {