<?xml version="1.0" encoding="UTF-8"?> <rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
><channel><title>kometbomb &#187; Webfinds</title> <atom:link href="http://kometbomb.net/category/webfinds/feed/" rel="self" type="application/rss+xml" /><link>http://kometbomb.net</link> <description>Journal of my adventures in Programming, the Internet and Life.</description> <lastBuildDate>Wed, 16 Jun 2010 14:56:50 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.0.1</generator> <item><title>An Alternative to XML</title><link>http://kometbomb.net/2010/02/28/libconfig/</link> <comments>http://kometbomb.net/2010/02/28/libconfig/#comments</comments> <pubDate>Sun, 28 Feb 2010 15:42:06 +0000</pubDate> <dc:creator>kometbomb</dc:creator> <category><![CDATA[Programming]]></category> <category><![CDATA[Webfinds]]></category> <category><![CDATA[API]]></category> <category><![CDATA[C]]></category> <category><![CDATA[Libraries]]></category> <category><![CDATA[XML]]></category><guid
isPermaLink="false">http://kometbomb.net/?p=701</guid> <description><![CDATA[XML can be overkill or simply cumbersome to edit manually for example when used in configuration files. Or, it may simply be unavailable for the preferred platform. Here's a great alternative.]]></description> <content:encoded><![CDATA[<p>My new weapon of choice. <strong><a
href="http://www.hyperrealm.com/libconfig/">libconfig</a></strong> is a configuration file parser that supports arrays, named and typed members, selection by path (e.g. <tt>cfg.users.[3].name</tt>) and more. That is, it has basically all the useful (as in 80% of cases) features of XML and none of the bad. There&#8217;s a minimal but well defined structure that will work for most situations and that can be used to enforce e.g. all array items having to be of the same type. There&#8217;s no overkill markup so it&#8217;s easy to read and write by humans. The library can also write the settings tree into a text file.</p><p>The configuration files look like this:</p><pre class="brush: plain;">screen = { width = 300; height = 200; }
users = ( { name = &quot;Torgo&quot;; items = [ &quot;Item 1&quot;, &quot;Item 2&quot; ]; } );</pre><p>And in C you would do something like this:</p><pre class="brush: cpp;">int screen_height = 100;
const char *name;
config_init(&amp;cfg);
config_read_file(&amp;cfg, &quot;config&quot;);
if (!config_lookup_int(&amp;cfg, &quot;screen.height&quot;, &amp;screen_height))
  puts(&quot;Using default screen height&quot;);
if (config_lookup_string(&amp;cfg, &quot;users.[0].name&quot;, &amp;name))
  puts(name);
config_destroy(&amp;cfg);</pre><p>You can also iterate the setting tree without the path for easier array or tree traversal. In all, I would say it involves less work compared to any XML library, especially in C. I like to think it&#8217;s a good example of software designed by the same guy who also uses it and not by some external committee.</p><ul><li><a
href="http://www.hyperrealm.com/libconfig/">Homepage</a></li><li><a
href="http://www.hyperrealm.com/libconfig/test.cfg.txt">An example config file</a></li></ul><h3  class="related_post_title">You might also like...</h3><ul
class="related_post"><li><a
href="http://kometbomb.net/2008/03/21/a-tiny-xml-parser/" title="A Tiny XML Parser">A Tiny XML Parser</a></li><li><a
href="http://kometbomb.net/2009/09/22/introducing-my-latest-projects/" title="Introducing My Latest Projects">Introducing My Latest Projects</a></li><li><a
href="http://kometbomb.net/2008/02/24/google-chart-api-is-pretty-cool/" title="Google Chart API is pretty cool">Google Chart API is pretty cool</a></li><li><a
href="http://kometbomb.net/2007/11/07/what-exactly-does-gcc-optimize/" title="What exactly does GCC optimize?">What exactly does GCC optimize?</a></li><li><a
href="http://kometbomb.net/2009/12/31/creating-a-simple-gui-from-scratch/" title="Creating a Simple GUI from Scratch">Creating a Simple GUI from Scratch</a></li></ul>]]></content:encoded> <wfw:commentRss>http://kometbomb.net/2010/02/28/libconfig/feed/</wfw:commentRss> <slash:comments>2</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Page Caching using disk (enhanced)

Served from: kometbomb.net @ 2010-09-09 02:38:19 -->