So I'm using al_get_next_config_entry to iterate through a config section however when it finds multiples of the same value it ends the section iteration:
I have this in my config file:
[GAME]
#--------------------------------------------------------------------------------
DATA-PATH = data
FONT-PATH = font
GFX-FLAGS = WINDOWED
#GFX-FLAGS = FULLSCREEN
GFX-OPTION = VSYNC
TIMER-FREQ = 24
#SYS-FONT = bgothl.ttf,12
SYS-FONT = pirulen.ttf,12
ANI-SET = Animations.ani
BMP-SET = snow.ani
FONT = bgothl.ttf,12
FONT = pirulen.ttf,12
#--------------------------------------------------------------------------------
However it only finds one FONT value instead of two. Is this normal?
]]>That is indeed expected behaviour, because you would otherwise have to find a way to make one key have multiple values. ie: if you look up the value of font, what should it be?
ie: what should al_get_config_value(cfg, "Game", "FONT") return? undefined if you have multiple entries for the same key.
I disagree, it could return the first value found. There are good reasons to have multiple entries of the same name.
]]>There are good reasons to have multiple entries of the same name.
Which are?
Anyway, it is impossible to specify which of the double entries you want to get with al_get_config_value, just like an std::map.
Append:
I haven't ever used the allegro config routines, so I don't know which element al_get_config_value will return. I figure it'll be either the first or the last entry, depending on how it the routines were written(overwriting the value at each read, or check if the element already exists,...).
Keys do not need to be unique, but all but the last one are ignored.
]]>
The fact that we are not sure which entry we get when multiples are found suggest that something is perhaps missing. Otherwise having multiple fonts is perfectly natural and would make sense to be able to load them all by iterating through the config entries. This makes sense to me from a programming point of view also. If you have a loading class it would need to find matching entries to know which loader to call for example. I guess I could use prefixes FONT_ and strstr instead but i don't see a good reason for this other than getting around the issue at hand.
]]>all but the last one are ignored.
Ok got it, so how do i count them? Or get intermediate entries? I doesn't sound like this behavior is making much sense.
]]>Ok got it, so how do i count them? Or get intermediate entries?
Impossible. You'll need to either use different keys (font0, font1), separate multiple fonts by delimeters, or use a different configuration file format. Not many configuration file formats support duplicate keys like that, incidentally... XML is the most popular one I can think ok. Everything else forces you to use lists (like JSON/YAML).
]]>XML isn't a configuration file format though, just a markup language. If you use actual keys by attaching id attributes to elements they must be unique as well.
]]>Ok I'm not going to make a fuss out of this, probably just using FONT_XXX will do, then I will use strstr or strncmp...Thanks for your help!
]]>XML isn't a configuration file format though, just a markup language.
A markup language that's nearly never used for markup purposes .
]]>