Introduction

libxnm is a C library for parsing the XNM format, which features:

API documentation

Examples

Here are a few examples of some uses of libxnm.

simple configuration parsing

Given a xnm file that looks like:
fullscreen: T
audio_rate: 44100
stereo: F
player: Player
fps: 30

Here is code to parse this file:

#int <xnm.h>

int main()
{
  XnmValue *cnf;

  // Configuration default values
  gboolean fullscreen = FALSE;
  gdouble audio_rate = 44100;
  gboolean stereo = FALSE;
  const gchar player = "Joe";
  gint fps = 15;
  gboolean reflection = TRUE;


  if (xnm_parse_file(cnf_file,
                     // output
                     &cnf,
                     &error) != 0)
      die("Failed reading file.\n");

  ret = xnm_value_get_values(val,
                            "fullscreen", XNM_GET_BOOL, &fullscreen,
                            "audio_rate", XNM_GET_DOUBLE, &audio_root,
                            "stereo", XNM_GET_BOOL, &stereo,
                            "player", XNM_GET_STRING, &player,
                            "fps", XNM_GET_INT,  &fps,
                             NULL);
}

Gaim prefs like

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=>"xterm -e lynx %s"
        browser=>firefox
        new_window=>F
      }
      plugins => [
        '/usr/lib/gaim/gaimrc.so'
        '/usr/lib/gaim/ssl-nss.so'
        '/usr/lib/gaim/ssl.so'
      ]
    }
  }
}

As a short example, let's just iterate over the plugins:

    XnmValue *xnm_root, *xnm_plugins;

    /* Retrieve a shortcut. */
    xnm_value_get(xnm_root,
                  "core/gaim/gtk/plugins",
                  &xnm_plugins);

    int num_plugins = xnm_value_get_array_length(xnm_plugins, "");

    for (i=0; i<num_plugins; i++)
      {
        const gchar *plugin_name;
        gchar key[16];
        sprintf(key, "[%d]", i);
        xnm_value_get_const_string(key, &plugin_name);
      }

    xnm_value_unref(xnm_plugins);
}

Generated on Thu Dec 25 10:36:27 2008 by  doxygen 1.5.7.1