Allegro.cc - Online Community

Allegro.cc Forums » Allegro Development » list_config_sections not working correctly and section name problem

This thread is locked; no one can reply to it. rss feed Print
list_config_sections not working correctly and section name problem
spellcaster
Member #1,493
September 2001
avatar

Hiho!

If you take the example program for list_config_entries

1int i, n;
2 char const **sections = NULL;
3 char const **entries = NULL;
4 
5 n = list_config_sections(&sections);
6 /* loop through all section names */
7 for (i = 0; i < n; i++)
8 {
9 int j, m;
10 printf("%s\n", sections<i>);
11 m = list_config_entries(sections<i>, &entries);
12 /* loop through all entries in the section */
13 for (j = 0; j < m; j++)
14 {
15 printf(" %s=\"%s\"\n", entries[j], get_config_string(
16 sections<i>, entries[j], "-"));
17 }
18 }
19 free_config_entries(&sections);
20 free_config_entries(&entries);

and feed it with a config file like this:

value0=foo
value1=bar

You won't see anything since the "global" section is not returned at all. I'd suggest to return global settings belonging to a section named "" or a NULL pointer.

Also, if use a section name that contains a space, the section will not be loaded at all. This should either be pointed out in the documentation or changed in the implementation.

--
There are no stupid questions, but there are a lot of inquisitive idiots.

Elias
Member #358
May 2000

Quote:

If you take the example program for list_config_entries and feed it with a config file like this:

value0=foo
value1=bar

You won't see anything since the "global" section is not returned at all. I'd suggest to return global settings belonging to a section named "" or a NULL pointer.

Another way to fix it would be if the example would first use list_config_entries to get all global entries, and only then loop through the sections. This would not require code changes, just modifying the example.

Quote:

Also, if use a section name that contains a space, the section will not be loaded at all. This should either be pointed out in the documentation or changed in the implementation.

That's not specific to list_config_sections though.

--
"Either help out or stop whining" - Evert

CGamesPlay
Member #2,559
July 2002
avatar

Elias: I remember telling you about the bug in that example (where free_config_sections is called outside the loop where it should be called)... Was this fix only in SVN?

--
Tomasu: Every time you read this: hugging!

Ryan Patterson - <http://cgamesplay.com/>

Elias
Member #358
May 2000

It should work like that, as it uses realloc internally - so it's enough to free it outside. You fixed something else though:

Quote:

r7812 | elias | 2007-04-04 15:11:04 +0200 (Wed, 04 Apr 2007) | 1 line

Ryan Patterson fixed a crash in free_config_entries.

--
"Either help out or stop whining" - Evert

spellcaster
Member #1,493
September 2001
avatar

Quote:

That's not specific to list_config_sections though.

Yep, that's why I specified two problems in the topic name ;)

Quote:

this would not require code changes, just modifying the example.

That might be an idea as well ;)

--
There are no stupid questions, but there are a lot of inquisitive idiots.

Elias
Member #358
May 2000

Quote:

Yep, that's why I specified two problems in the topic name ;)

Ah, so you expected me to read the topic ;)

Quote:

That might be an idea as well ;)

Quote:

------------------------------------------------------------------------
r7909 | elias | 2007-06-10 17:59:07 +0200 (Sun, 10 Jun 2007) | 4 lines

Fixed two problems pointed out by spellcaster on allegro.cc:
- Mention in the docs that config section and variable names cannot contain spaces.
- Fixed the example for list_config_entries to really display all entries, even those not in any section.

------------------------------------------------------------------------

--
"Either help out or stop whining" - Evert

Go to: