[AD] config iterators

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


The attached patch replaces the void** arguments of al_get_first|
next_config_entry|section with typed arguments. Andrey's automated (I
assume) tests prompted me to make the change - not because of the test
(it is wrong after all) but because I think it's also easier for users
when they have the type and not just a void** pointer. Not sure though.

-- 
Elias Pschernig <elias.pschernig@xxxxxxxxxx>
diff --git a/examples/ex_config.c b/examples/ex_config.c
index f847b6c..d9b3c39 100644
--- a/examples/ex_config.c
+++ b/examples/ex_config.c
@@ -26,7 +26,8 @@ int main(void)
 {
    ALLEGRO_CONFIG *cfg;
    const char *value;
-   void *iterator, *iterator2;
+   ALLEGRO_CONFIG_ENTRY *eiterator;
+   ALLEGRO_CONFIG_SECTION *siterator;
 
    if (!al_init()) {
       return 1;
@@ -55,37 +56,37 @@ int main(void)
    value = al_get_config_value(cfg, "adição", "€");
    TEST("unicode", value && !strcmp(value, "¿"));
 
-   value = al_get_first_config_section(cfg, &iterator);
+   value = al_get_first_config_section(cfg, &siterator);
    TEST("section1", value && !strcmp(value, ""));
    
-   value = al_get_first_config_entry(cfg, value, &iterator2);
+   value = al_get_first_config_entry(cfg, value, &eiterator);
    TEST("entry1", value && !strcmp(value, "old_var"));
    
-   value = al_get_next_config_entry(&iterator2);
+   value = al_get_next_config_entry(&eiterator);
    TEST("entry2", value && !strcmp(value, "mysha.xpm"));
    
-   value = al_get_next_config_entry(&iterator2);
+   value = al_get_next_config_entry(&eiterator);
    TEST("entry3", value == NULL);
 
-   value = al_get_next_config_section(&iterator);
+   value = al_get_next_config_section(&siterator);
    TEST("section2", value && !strcmp(value, "section"));
    
-   value = al_get_first_config_entry(cfg, value, &iterator2);
+   value = al_get_first_config_entry(cfg, value, &eiterator);
    TEST("entry4", value && !strcmp(value, "old_var"));
    
-   value = al_get_next_config_entry(&iterator2);
+   value = al_get_next_config_entry(&eiterator);
    TEST("entry5", value == NULL);
 
-   value = al_get_next_config_section(&iterator);
+   value = al_get_next_config_section(&siterator);
    TEST("section3", value && !strcmp(value, "adição"));
    
-   value = al_get_first_config_entry(cfg, value, &iterator2);
+   value = al_get_first_config_entry(cfg, value, &eiterator);
    TEST("entry6", value && !strcmp(value, "€"));
    
-   value = al_get_next_config_entry(&iterator2);
+   value = al_get_next_config_entry(&eiterator);
    TEST("entry7", value == NULL);
    
-   value = al_get_next_config_section(&iterator);
+   value = al_get_next_config_section(&siterator);
    TEST("section4", value == NULL);
    
    
diff --git a/include/allegro5/config.h b/include/allegro5/config.h
index 72feff0..9253f55 100644
--- a/include/allegro5/config.h
+++ b/include/allegro5/config.h
@@ -10,6 +10,8 @@ extern "C" {
 /* Type: ALLEGRO_CONFIG
  */
 typedef struct ALLEGRO_CONFIG ALLEGRO_CONFIG;
+typedef struct ALLEGRO_CONFIG_ENTRY ALLEGRO_CONFIG_ENTRY;
+typedef struct ALLEGRO_CONFIG_SECTION ALLEGRO_CONFIG_SECTION;
 
 AL_FUNC(ALLEGRO_CONFIG *, al_create_config, (void));
 AL_FUNC(void, al_add_config_section, (ALLEGRO_CONFIG *config, const char *name));
@@ -24,10 +26,10 @@ AL_FUNC(void, al_merge_config_into, (ALLEGRO_CONFIG *master, const ALLEGRO_CONFI
 AL_FUNC(ALLEGRO_CONFIG *, al_merge_config, (const ALLEGRO_CONFIG *cfg1, const ALLEGRO_CONFIG *cfg2));
 AL_FUNC(void, al_destroy_config, (ALLEGRO_CONFIG *config));
 
-AL_FUNC(char const *, al_get_first_config_section, (ALLEGRO_CONFIG const *config, void **iterator));
-AL_FUNC(char const *, al_get_next_config_section, (void **iterator));
-AL_FUNC(char const *, al_get_first_config_entry, (ALLEGRO_CONFIG const *config, char const *section, void **iterator));
-AL_FUNC(char const *, al_get_next_config_entry, (void **iterator));
+AL_FUNC(char const *, al_get_first_config_section, (ALLEGRO_CONFIG const *config, ALLEGRO_CONFIG_SECTION **iterator));
+AL_FUNC(char const *, al_get_next_config_section, (ALLEGRO_CONFIG_SECTION **iterator));
+AL_FUNC(char const *, al_get_first_config_entry, (ALLEGRO_CONFIG const *config, char const *section, ALLEGRO_CONFIG_ENTRY **iterator));
+AL_FUNC(char const *, al_get_next_config_entry, (ALLEGRO_CONFIG_ENTRY **iterator));
 
 #ifdef __cplusplus
 }
diff --git a/include/allegro5/internal/aintern_config.h b/include/allegro5/internal/aintern_config.h
index a5e2099..50526e5 100644
--- a/include/allegro5/internal/aintern_config.h
+++ b/include/allegro5/internal/aintern_config.h
@@ -3,9 +3,6 @@
 
 #include "allegro5/internal/aintern_aatree.h"
 
-typedef struct ALLEGRO_CONFIG_ENTRY ALLEGRO_CONFIG_ENTRY;
-typedef struct ALLEGRO_CONFIG_SECTION ALLEGRO_CONFIG_SECTION;
-
 struct ALLEGRO_CONFIG_ENTRY {
    bool is_comment;
    ALLEGRO_USTR *key;    /* comment if is_comment is true */
diff --git a/src/config.c b/src/config.c
index 49598e5..476b74a 100644
--- a/src/config.c
+++ b/src/config.c
@@ -577,7 +577,7 @@ void al_destroy_config(ALLEGRO_CONFIG *config)
 /* Function: al_get_first_config_section
  */
 char const *al_get_first_config_section(ALLEGRO_CONFIG const *config,
-   void **iterator)
+   ALLEGRO_CONFIG_SECTION **iterator)
 {
    ALLEGRO_CONFIG_SECTION *s;
 
@@ -591,7 +591,7 @@ char const *al_get_first_config_section(ALLEGRO_CONFIG const *config,
 
 /* Function: al_get_next_config_section
  */
-char const *al_get_next_config_section(void **iterator)
+char const *al_get_next_config_section(ALLEGRO_CONFIG_SECTION **iterator)
 {
    ALLEGRO_CONFIG_SECTION *s;
 
@@ -608,7 +608,7 @@ char const *al_get_next_config_section(void **iterator)
 /* Function: al_get_first_config_entry
  */
 char const *al_get_first_config_entry(ALLEGRO_CONFIG const *config,
-   char const *section, void **iterator)
+   char const *section, ALLEGRO_CONFIG_ENTRY **iterator)
 {
    ALLEGRO_USTR_INFO section_info;
    ALLEGRO_USTR *usection;
@@ -635,7 +635,7 @@ char const *al_get_first_config_entry(ALLEGRO_CONFIG const *config,
 
 /* Function: al_get_next_config_entry
  */
-char const *al_get_next_config_entry(void **iterator)
+char const *al_get_next_config_entry(ALLEGRO_CONFIG_ENTRY **iterator)
 {
    ALLEGRO_CONFIG_ENTRY *e;
 
diff --git a/src/x/xkeyboard.c b/src/x/xkeyboard.c
index a0625fd..35f9f2d 100644
--- a/src/x/xkeyboard.c
+++ b/src/x/xkeyboard.c
@@ -632,7 +632,7 @@ static void _al_xwin_get_keyboard_mapping(void)
    ALLEGRO_CONFIG *c = system->system.config;
    
    char const *key;
-   void *it;
+   ALLEGRO_CONFIG_ENTRY *it;
    key = al_get_first_config_entry(c, "xkeymap", &it);
    while (key) {
       char const *val;


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/