<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>al_get_next_config_entry with repeating values</title>
		<link>http://www.allegro.cc/forums/view/610553</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Mon, 02 Jul 2012 00:29:54 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>So I&#39;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:</p><div class="source-code"><div class="toolbar"><span class="button numbers"><b>#</b></span><span class="button select">Select</span><span class="button expand">Expand</span></div><div class="inner"><span class="number">  1</span><span class="k1">int</span> cfg_section_values<span class="k2">(</span> <a href="http://www.allegro.cc/manual/ALLEGRO_CONFIG"><span class="a">ALLEGRO_CONFIG</span></a> <span class="k3">*</span>cfg, <span class="k1">const</span> <span class="k1">char</span> <span class="k3">*</span>section, <span class="k1">const</span> <span class="k1">char</span> <span class="k3">*</span>value<span class="k2">)</span><span class="k2">{</span>
<span class="number">  2</span>
<span class="number">  3</span>    <span class="k1">const</span> <span class="k1">char</span> <span class="k3">*</span>str <span class="k3">=</span> NULL<span class="k2">;</span>
<span class="number">  4</span>    ALLEGRO_CONFIG_ENTRY <span class="k3">*</span>iter <span class="k3">=</span> NULL<span class="k2">;</span>
<span class="number">  5</span>    <span class="k1">int</span> n <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span>
<span class="number">  6</span>
<span class="number">  7</span>    <span class="k1">if</span><span class="k2">(</span> <span class="k3">!</span><span class="k2">(</span>str <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_get_first_config_entry"><span class="a">al_get_first_config_entry</span></a><span class="k2">(</span> cfg, section, <span class="k3">&amp;</span>iter<span class="k2">)</span><span class="k2">)</span><span class="k2">)</span><span class="k2">{</span>
<span class="number">  8</span>        <a href="http://www.delorie.com/djgpp/doc/libc/libc_624.html" target="_blank">printf</a><span class="k2">(</span><span class="s">"ERROR: No such section [%s] while searcing for [%s]!\n"</span>, section, value<span class="k2">)</span><span class="k2">;</span>
<span class="number">  9</span>        <span class="k1">return</span><span class="k2">(</span> <span class="k3">-</span><span class="n">1</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 10</span>    <span class="k2">}</span>
<span class="number"> 11</span>
<span class="number"> 12</span>    <span class="k1">if</span><span class="k2">(</span> <span class="k3">!</span><a href="http://www.delorie.com/djgpp/doc/libc/libc_754.html" target="_blank">strcmp</a><span class="k2">(</span> str, value<span class="k2">)</span><span class="k2">)</span> n<span class="k3">+</span><span class="k3">+</span><span class="k2">;</span>
<span class="number"> 13</span>
<span class="number"> 14</span>    <span class="k1">while</span><span class="k2">(</span> <span class="k2">(</span>str <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_get_next_config_entry"><span class="a">al_get_next_config_entry</span></a><span class="k2">(</span> <span class="k3">&amp;</span>iter<span class="k2">)</span><span class="k2">)</span><span class="k2">)</span><span class="k2">{</span>
<span class="number"> 15</span>
<span class="number"> 16</span>        <a href="http://www.delorie.com/djgpp/doc/libc/libc_624.html" target="_blank">printf</a><span class="k2">(</span><span class="s">"%s\n"</span>, str<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 17</span>        <span class="k1">if</span><span class="k2">(</span> <span class="k3">!</span><a href="http://www.delorie.com/djgpp/doc/libc/libc_754.html" target="_blank">strcmp</a><span class="k2">(</span> str, value<span class="k2">)</span><span class="k2">)</span> n<span class="k3">+</span><span class="k3">+</span><span class="k2">;</span>
<span class="number"> 18</span>
<span class="number"> 19</span>    <span class="k2">}</span>
<span class="number"> 20</span>
<span class="number"> 21</span>    <a href="http://www.delorie.com/djgpp/doc/libc/libc_624.html" target="_blank">printf</a><span class="k2">(</span><span class="s">"Found %d [%s] value in section [%s]\n"</span>, n, value, section<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 22</span>
<span class="number"> 23</span>    <span class="k1">return</span><span class="k2">(</span> n<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 24</span><span class="k2">}</span>
</div></div><p>
I have this in my config file:</p><p>[GAME]<br />#--------------------------------------------------------------------------------<br />DATA-PATH 		= data<br />FONT-PATH 		= font<br />GFX-FLAGS		= WINDOWED<br />#GFX-FLAGS		= FULLSCREEN<br />GFX-OPTION		= VSYNC<br />TIMER-FREQ		= 24<br />#SYS-FONT		= bgothl.ttf,12<br />SYS-FONT		= pirulen.ttf,12<br />ANI-SET			= Animations.ani<br />BMP-SET			= snow.ani<br />FONT			= bgothl.ttf,12<br />FONT			= pirulen.ttf,12<br />#--------------------------------------------------------------------------------</p><p>However it only finds one FONT value instead of two. Is this normal?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Alianix)</author>
		<pubDate>Sun, 01 Jul 2012 22:06:31 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>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?<br />ie: what should al_get_config_value(cfg, &quot;Game&quot;, &quot;FONT&quot;) return? undefined if you have multiple entries for the same key.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (J-Gamer)</author>
		<pubDate>Sun, 01 Jul 2012 22:15:12 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I disagree, it could return the first value found. There are good reasons to have multiple entries of the same name.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Alianix)</author>
		<pubDate>Sun, 01 Jul 2012 22:20:59 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/610553/959269#target">Alianix</a> said:</div><div class="quote"><p>There are good reasons to have multiple entries of the same name.</p></div></div><p>
Which are?</p><p>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.</p><p><b>Append:</b><br />I haven&#39;t ever used the allegro config routines, so I don&#39;t know which element al_get_config_value will return. I figure it&#39;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,...).
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (J-Gamer)</author>
		<pubDate>Sun, 01 Jul 2012 22:24:20 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://alleg.sourceforge.net/a5docs/5.0.7/config.html">The Manual</a> said:</div><div class="quote"><p>
Keys do not need to be unique, but all but the last one are ignored.
</p></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Sun, 01 Jul 2012 22:40:01 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>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&#39;t see a good reason for this other than getting around the issue at hand.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Alianix)</author>
		<pubDate>Sun, 01 Jul 2012 22:44:05 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p> all but the last one are ignored.
</p></div></div></div>]]>
		</description>
		<author>no-reply@allegro.cc (Arthur Kalliokoski)</author>
		<pubDate>Sun, 01 Jul 2012 22:46:27 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Ok got it, so how do i count them? Or get intermediate entries? I doesn&#39;t sound like this behavior is making much sense.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Alianix)</author>
		<pubDate>Sun, 01 Jul 2012 22:47:15 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/610553/959274#target">Alianix</a> said:</div><div class="quote"><p> Ok got it, so how do i count them? Or get intermediate entries?
</p></div></div><p>Impossible. You&#39;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).
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Sun, 01 Jul 2012 22:49:56 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>XML isn&#39;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.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Sun, 01 Jul 2012 23:01:01 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Ok I&#39;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!
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Alianix)</author>
		<pubDate>Sun, 01 Jul 2012 23:17:53 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/610553/959278#target">Elias</a> said:</div><div class="quote"><p> XML isn&#39;t a configuration file format though, just a markup language.
</p></div></div><p>A markup language that&#39;s nearly never used for markup purposes <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" />.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Mon, 02 Jul 2012 00:29:54 +0000</pubDate>
	</item>
</rss>
