[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Pingus-CVS] CVS: Games/Pingus/src config_xml.cxx,NONE,1.1 config_xml.hx
From: |
grumbel |
Subject: |
[Pingus-CVS] CVS: Games/Pingus/src config_xml.cxx,NONE,1.1 config_xml.hxx,NONE,1.1 Makefile.am,1.115,1.116 |
Date: |
8 Oct 2002 22:58:04 -0000 |
Update of /usr/local/cvsroot/Games/Pingus/src
In directory dark:/tmp/cvs-serv6785
Modified Files:
Makefile.am
Added Files:
config_xml.cxx config_xml.hxx
Log Message:
added xml parser for config file (not hooked in yet)
--- NEW FILE: config_xml.cxx ---
// $Id: config_xml.cxx,v 1.1 2002/10/08 22:58:02 grumbel Exp $
//
// Pingus - A free Lemmings clone
// Copyright (C) 2002 Ingo Ruhnke <address@hidden>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <iostream>
#include "xml_helper.hxx"
#include "pingus_error.hxx"
#include "config_xml.hxx"
ConfigXML::ConfigXML(const std::string& arg_filename)
{
doc = xmlParseFile(arg_filename.c_str());
if (doc == NULL)
PingusError::raise("ConfigXML: Couldn't open \"" + arg_filename + "\"");
xmlNodePtr cur = doc->ROOT;
if (cur && XMLhelper::equal_str(cur->name, "pingus-config"))
{
cur = cur->children;
cur = XMLhelper::skip_blank(cur);
parse_directory(cur, "");
}
else
{
PingusError::raise("ConfigXML: Not a valid pingus-config file \"" +
arg_filename + "\"");
}
}
void
ConfigXML::parse_directory(xmlNodePtr cur, const std::string& prefix)
{
while(cur)
{
std::string name = reinterpret_cast<const char*>(cur->name);
if (is_directory(cur))
{
parse_directory(cur->children, prefix + name + "/");
}
else if (is_value(cur))
{
std::string value;
XMLhelper::node_list_get_string(doc, cur->children, 1, value);
std::cout << "ConfigXML: Value: " << prefix << name << " = " << value
<< std::endl;
}
else if (xmlIsBlankNode(cur) || XMLhelper::equal_str(cur->name,
"comment"))
{
// ignore blank nodes
}
else
{
std::cout << "ConfigXML: parse error 123: " << cur->name << std::endl;
}
cur = cur->next;
cur = XMLhelper::skip_blank(cur);
}
}
bool
ConfigXML::is_directory(xmlNodePtr cur)
{
return cur->children && (xmlIsBlankNode(cur->children) ||
!xmlNodeIsText(cur->children));
}
bool
ConfigXML::is_value(xmlNodePtr cur)
{
return cur->children && xmlNodeIsText(cur->children);
}
/* EOF */
--- NEW FILE: config_xml.hxx ---
// $Id: config_xml.hxx,v 1.1 2002/10/08 22:58:02 grumbel Exp $
//
// Pingus - A free Lemmings clone
// Copyright (C) 2002 Ingo Ruhnke <address@hidden>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifndef HEADER_PINGUS_CONFIG_XML_HXX
#define HEADER_PINGUS_CONFIG_XML_HXX
#include "libxmlfwd.hxx"
/** Reader for the pingus config file */
class ConfigXML
{
private:
xmlDocPtr doc;
public:
ConfigXML(const std::string& filename);
private:
void parse_directory(xmlNodePtr cur, const std::string& prefix);
bool is_directory(xmlNodePtr cur);
bool is_value(xmlNodePtr cur);
ConfigXML (const ConfigXML&);
ConfigXML& operator= (const ConfigXML&);
};
#endif
/* EOF */
Index: Makefile.am
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/Makefile.am,v
retrieving revision 1.115
retrieving revision 1.116
diff -u -d -r1.115 -r1.116
--- Makefile.am 4 Oct 2002 16:54:03 -0000 1.115
+++ Makefile.am 8 Oct 2002 22:58:02 -0000 1.116
@@ -99,6 +99,8 @@
color.hxx \
config.cxx \
config.hxx \
+config_xml.cxx \
+config_xml.hxx \
console.cxx \
console.hxx \
counter.cxx \
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Pingus-CVS] CVS: Games/Pingus/src config_xml.cxx,NONE,1.1 config_xml.hxx,NONE,1.1 Makefile.am,1.115,1.116,
grumbel <=
- Prev by Date:
[Pingus-CVS] CVS: Games/Pingus/src game_session.cxx,1.20,1.21 time_display.cxx,1.8,1.9
- Next by Date:
[Pingus-CVS] CVS: Games/Pingus pingus.dsp,1.18,1.19
- Previous by thread:
[Pingus-CVS] CVS: Games/Pingus/src game_session.cxx,1.20,1.21 time_display.cxx,1.8,1.9
- Next by thread:
[Pingus-CVS] CVS: Games/Pingus pingus.dsp,1.18,1.19
- Index(es):