? doc.diff
? keyfile-old.sgml
? keyfile.diff
? keyfile.sgml
? patch-keyfile.tar
? build/win32/vs8/Makefile
? build/win32/vs8/Makefile.in
Index: docs/reference/glib/tmpl/keyfile.sgml
===================================================================
RCS file: /cvs/gnome/glib/docs/reference/glib/tmpl/keyfile.sgml,v
retrieving revision 1.5
diff -u -r1.5 keyfile.sgml
--- docs/reference/glib/tmpl/keyfile.sgml	5 May 2005 14:57:27 -0000	1.5
+++ docs/reference/glib/tmpl/keyfile.sgml	8 Feb 2006 19:17:26 -0000
@@ -92,6 +92,106 @@
 </itemizedlist>
 </para>
 
+<informalexample><programlisting>
+/*
+   Sample example for loading, reading and writing a configuration file 
+   with GKeyFile
+*/
+
+#include &lt;stdlib.h&gt;
+#include &lt;stdio.h&gt;
+#include &lt;glib.h&gt;
+
+
+int main (void)
+{
+   GKeyFile *  p_key_file;
+   GError   *  p_error     = NULL;
+   gchar    *  s_data;
+   gchar    *  s_name;
+   gchar    *  s_sex;
+   gint        age;
+   gsize       size;
+   gboolean    b_ret;
+
+
+   /* ----- Create new GKeyFile */
+   p_key_file = g_key_file_new ();
+
+
+   /* ----- Load config file to GKeyFile */
+   if (! g_key_file_load_from_file (
+         p_key_file,
+         "sample_config.ini",
+         G_KEY_FILE_KEEP_COMMENTS,
+         &amp; p_error))
+   {
+      /* Error, exit program. */
+      g_warning ("Impossible to load config file : %s\n", p_error->message);
+      g_error_free (p_error);
+
+      exit (EXIT_FAILURE);
+   }
+
+
+   /* ----- Read data from GKeyFile */
+   s_name = g_key_file_get_string (p_key_file, "Person", "name", NULL);
+   s_sex = g_key_file_get_string (p_key_file, "Person", "sex", NULL);
+   age = g_key_file_get_integer (p_key_file, "Person", "age", NULL);
+
+   /*
+      g_key_file_get_string returns NULL if key don't exist.
+      With g_key_file_get_integer use GError to see if key exist
+   */
+   g_print ("\nName: %s\n", s_name);
+   g_print ("Sex: %s\n", s_sex);
+   g_print ("Age: %d\n\n", age);
+   g_free (s_name);
+   g_free (s_sex);
+
+
+   /* ----- Change data to GKeyFile */
+   g_key_file_set_string (p_key_file, "Person", "name", "Angelina");
+   g_key_file_set_string (p_key_file, "Person", "sex", "female");
+   g_key_file_set_integer (p_key_file, "Person", "age", 20);
+
+
+   /* ----- Convert data to string */
+   s_data = g_key_file_to_data (p_key_file, &amp;size, &amp;p_error);
+
+   if (!s_data)
+   {
+      /* Error, exit program. */
+      g_warning ("Impossible to convert data to string : %s\n", p_error->message);
+      g_error_free (p_error);
+
+      exit (EXIT_FAILURE);
+   }
+
+
+   /* ----- Write data to file */
+   b_ret = g_file_set_contents ("sample_config.ini", s_data, size,  &amp;p_error);
+   g_free (s_data);
+
+   if (!b_ret)
+   {
+      /* Error, exit program. */
+      g_warning ("Impossible to write config file : %s\n", p_error->message);
+      g_error_free (p_error);
+
+      exit (EXIT_FAILURE);
+   }
+
+
+   /* ----- Free GKeyFile */
+   g_key_file_free (p_key_file);
+
+
+   return EXIT_SUCCESS;
+}
+
+</programlisting></informalexample>
+
 <!-- ##### SECTION See_Also ##### -->
 <para>
 
