Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals  

xmlconfig.c

00001 /*
00002  *  xmlconfig.c - Handle the XML configuration file.
00003  *                This file is part of the FreeLCD package.
00004  *  
00005  *  $Id: xmlconfig_8c-source.html,v 1.1 2003/02/16 22:50:41 unicorn Exp $
00006  *
00007  *  This program is free software; you can redistribute it and/or modify it
00008  *  under the terms of the GNU General Public License as published by the
00009  *  Free Software Foundation; either version 2 of the License, or (at your
00010  *  option) any later version.
00011  * 
00012  *  This program is distributed in the hope that it will be useful,
00013  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  *  GNU General Public License for more details.
00016  *
00017  *  You should have received a copy of the GNU General Public License
00018  *  along with this program; if not, write to the Free Software
00019  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00020  *  MA  02111-1307  USA
00021  *
00022  *  Copyright (c) 2002, 2003, Jeroen van den Berg <unicorn@hippie.nu>
00023  */
00024 
00025 
00026 #include <stdio.h>
00027 
00028 #include "xmlconfig.h"
00029 #include "common/dictionary.h"
00030 #include "drivers/backend.h"
00031 #include "drivers/driver.h"
00032 
00033 static tag_idx tag_array[] = { ROOT, OUTPUT };
00034 static attr_idx attr_array[] = { ID };
00035 
00036 static dict_pair tag_translate[] = {
00037   {"flcdd-config", &tag_array[0]},
00038   {"output", &tag_array[1]}
00039 };
00040 
00041 static dict_pair attr_translate[] = {
00042   {"id", &attr_array[0]}
00043 };
00044 
00045 static dictionary tag_dict = { tag_translate, 2 };
00046 static dictionary attr_dict = { attr_translate, 1 };
00047 
00048 static xml_node *finished_doc;
00049 
00050 
00051 static void
00052 _finished (void *ignore, xml_node *root_node)
00053 {
00054   finished_doc = root_node;
00055 }
00056 
00057 xml_node *
00058 xc_parse_config_file (const char *filename)
00059 {
00060   FILE *fp;
00061   char read_buf[4096];
00062   size_t read_len;
00063   void *context;
00064 
00065   finished_doc = 0;
00066 
00067   /* Attempt to open the file */
00068   fp = fopen (filename, "r");
00069   if (!fp)
00070     return 0;
00071 
00072   /* Create a context for parsing the file's content */
00073   context = xmlt_create_context (_finished, 0, &tag_dict, &attr_dict);
00074   if (!context)
00075     {
00076       fclose (fp);
00077       return 0;
00078     }
00079 
00080   /* Parse the file block by block */
00081   while (!feof (fp) && !ferror (fp))
00082     {
00083       read_len = fread (read_buf, 1, 4096, fp);
00084       if (read_len > 0)
00085         xmlt_parse (context, read_buf, read_len);
00086     }
00087 
00088   xmlt_free_context (context);
00089 
00090   return finished_doc;
00091 }

Generated on Sun Feb 16 23:39:49 2003 for FreeLCD by doxygen1.2.18