<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"> <title>Main Page</title> <link href="doxygen.css" rel="stylesheet" type="text/css"> <link href="tabs.css" rel="stylesheet" type="text/css"> </head><body> <!-- Generated by Doxygen 1.5.7.1 --> <div class="navigation" id="top"> <div class="tabs"> <ul> <li class="current"><a href="index.html"><span>Main Page</span></a></li> <li><a href="annotated.html"><span>Data Structures</span></a></li> <li><a href="files.html"><span>Files</span></a></li> <li><a href="dirs.html"><span>Directories</span></a></li> </ul> </div> </div> <div class="contents"> <h1></h1> <p> <h2><a class="anchor" name="intro"> Introduction</a></h2> libxnm is a C library for parsing the XNM format, which features:<p> <ul> <li>A bison based parser for the xnm syntax.</li></ul> <p> <ul> <li>A reference count handled structure <a class="el" href="structXnmValue.html">XnmValue</a> that can contain either a string, an array, or a table.</li></ul> <p> <ul> <li>Retriever utility functions for easy retrieval of data from a <a class="el" href="structXnmValue.html">XnmValue</a> tree.</li></ul> <h2><a class="anchor" name="API"> API documentation</a></h2> <ul> <li><a class="el" href="xnm_8h.html">xnm.h </a></li></ul> <h2><a class="anchor" name="Examples"> Examples</a></h2> Here are a few examples of some uses of libxnm.<h3><a class="anchor" name="conf_parsing"> simple configuration parsing</a></h3> Given a xnm file that looks like: <div class="fragment"><pre class="fragment">fullscreen: T audio_rate: 44100 stereo: F player: Player fps: 30 </pre></div><p> Here is code to parse this file: <div class="fragment"><pre class="fragment"><span class="preprocessor">#int <xnm.h></span> <span class="preprocessor"></span> <span class="keywordtype">int</span> main() { <a class="code" href="structXnmValue.html">XnmValue</a> *cnf; <span class="comment">// Configuration default values</span> gboolean fullscreen = FALSE; gdouble audio_rate = 44100; gboolean stereo = FALSE; <span class="keyword">const</span> gchar player = <span class="stringliteral">"Joe"</span>; gint fps = 15; gboolean reflection = TRUE; <span class="keywordflow">if</span> (<a class="code" href="xnm_8h.html#e2514b5cba985458cfc51c3eec10cab3">xnm_parse_file</a>(cnf_file, <span class="comment">// output</span> &cnf, &error) != 0) die(<span class="stringliteral">"Failed reading file.\n"</span>); ret = <a class="code" href="xnm_8h.html#56ff15c5debd596dc1b18b4efd772d95">xnm_value_get_values</a>(val, <span class="stringliteral">"fullscreen"</span>, XNM_GET_BOOL, &fullscreen, <span class="stringliteral">"audio_rate"</span>, XNM_GET_DOUBLE, &audio_root, <span class="stringliteral">"stereo"</span>, XNM_GET_BOOL, &stereo, <span class="stringliteral">"player"</span>, XNM_GET_STRING, &player, <span class="stringliteral">"fps"</span>, XNM_GET_INT, &fps, NULL); } </pre></div><h3><a class="anchor" name="gaim_like"> Gaim prefs like</a></h3> <div class="fragment"><pre class="fragment">core => { away => { idle_reporting=>system away_when_idle=>0 mins_before_way=>10 auto_reply=>awayidle report_idle=>1 } buddies => {} contact => { last_match => 0 offline_score => 2 away_score => 2 idle_score => 1 } gaim => { gtk=> { browsers=> { place=>F command=><span class="stringliteral">"xterm -e lynx %s"</span> browser=>firefox new_window=>F } plugins => [ <span class="stringliteral">'/usr/lib/gaim/gaimrc.so'</span> <span class="stringliteral">'/usr/lib/gaim/ssl-nss.so'</span> <span class="stringliteral">'/usr/lib/gaim/ssl.so'</span> ] } } } </pre></div><p> As a short example, let's just iterate over the plugins:<p> <div class="fragment"><pre class="fragment"> <a class="code" href="structXnmValue.html">XnmValue</a> *xnm_root, *xnm_plugins; <span class="comment">/* Retrieve a shortcut. */</span> <a class="code" href="xnm_8h.html#200b9e0ba79c5fb95e53c7c1a5869a76">xnm_value_get</a>(xnm_root, <span class="stringliteral">"core/gaim/gtk/plugins"</span>, &xnm_plugins); <span class="keywordtype">int</span> num_plugins = <a class="code" href="xnm_8h.html#7343bccb1d8c50c2de232dbd429e4dfc">xnm_value_get_array_length</a>(xnm_plugins, <span class="stringliteral">""</span>); <span class="keywordflow">for</span> (i=0; i<num_plugins; i++) { <span class="keyword">const</span> gchar *plugin_name; gchar key[16]; sprintf(key, <span class="stringliteral">"[%d]"</span>, i); <a class="code" href="xnm_8h.html#22eb29b840b66863d87bad4bb1a62314">xnm_value_get_const_string</a>(key, &plugin_name); } <a class="code" href="xnm_8h.html#e638c66188b57521792404e4cc61c629">xnm_value_unref</a>(xnm_plugins); } </pre></div> </div> <hr size="1"><address style="text-align: right;"><small>Generated on Thu Dec 25 10:36:27 2008 by <a href="http://www.doxygen.org/index.html"> <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.7.1 </small></address> </body> </html>