Commit c381c1c1 authored by Cyril Deguet's avatar Cyril Deguet

* configure.ac: check xml2-config for skins2

* modules/gui/skins2/src/var_manager.cpp: delete the variables in the
  right order to avoid invalid reads in the destructor
* modules/gui/skins2/parser/xmlparser: skeleton of a new parser based
  on the text reader API of libxml2
parent 5d3d0380
dnl Autoconf settings for vlc
dnl $Id: configure.ac,v 1.153 2004/01/23 15:36:23 titer Exp $
dnl $Id: configure.ac,v 1.154 2004/01/24 13:08:12 asmax Exp $
AC_INIT(vlc,0.7.1-cvs)
......@@ -2793,19 +2793,29 @@ if test "${enable_skins2}" != "no"; then
AX_ADD_CXXFLAGS([skins2],[-O2 -fno-rtti])
AX_ADD_LDFLAGS([skins2],[-loleaut32 -lwinspool -lwinmm -lshell32 -lctl3d32 -ladvapi32 -lwsock32 -lgdi32 -lcomdlg32 -lole32 -luuid -lcomctl32 -lmsimg32])
else if test "${enable_skins2}" = "yes"; then
else
AX_ADD_PLUGINS([skins2])
ALIASES="${ALIASES} svlc"
AX_ADD_CPPFLAGS([skins2],[-Imodules/gui/skins2 -I${x_includes} -DX11_SKINS])
AX_ADD_CXXFLAGS([skins2],[-O2 -fno-rtti])
AX_ADD_LDFLAGS([skins2],[-L${x_libraries} -lXext -lX11])
fi fi
fi
if test "${FREETYPE_CONFIG}" != "no"
then
AX_ADD_CPPFLAGS([skins2],[`${FREETYPE_CONFIG} --cflags` ${INCICONV}])
AX_ADD_LDFLAGS([skins2],[`${FREETYPE_CONFIG} --libs` ${LIBICONV} -lpng])
AX_ADD_CPPFLAGS([skins2],[`${FREETYPE_CONFIG} --cflags`])
AX_ADD_LDFLAGS([skins2],[`${FREETYPE_CONFIG} --libs`])
fi
AC_PATH_PROG(XML2_CONFIG, xml2-config, no)
if test "${XML2_CONFIG}" != "no"
then
AX_ADD_CPPFLAGS([skins2],[`${XML2_CONFIG} --cflags`])
AX_ADD_LDFLAGS([skins2],[`${XML2_CONFIG} --libs`])
fi
AX_ADD_CPPFLAGS([skins2],[${INCICONV}])
AX_ADD_LDFLAGS([skins2],[${LIBICONV} -lpng])
fi
......
......@@ -73,6 +73,8 @@ SOURCES_skins2 = \
parser/parser_context.hpp \
parser/skin.c \
parser/skin.h \
parser/xmlparser.cpp \
parser/xmlparser.hpp \
parser/wrappers.cpp \
parser/wrappers.h \
\
......
/*****************************************************************************
* xmlparser.cpp
*****************************************************************************
* Copyright (C) 2004 VideoLAN
* $Id: xmlparser.cpp,v 1.1 2004/01/24 13:08:12 asmax Exp $
*
* Authors: Cyril Deguet <asmax@via.ecp.fr>
* Olivier Teulire <ipkiss@via.ecp.fr>
*
* 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, USA.
*****************************************************************************/
#include "xmlparser.hpp"
XMLParser::XMLParser( intf_thread_t *pIntf, const string &rFileName ):
SkinObject( pIntf )
{
m_pReader = xmlNewTextReaderFilename( rFileName.c_str() );
if( !m_pReader )
{
msg_Err( getIntf(), "Failed to open %s for parsing",
rFileName.c_str() );
}
}
XMLParser::~XMLParser()
{
if( m_pReader )
{
xmlFreeTextReader( m_pReader );
}
}
int XMLParser::parse()
{
if( !m_pReader )
{
return -1;
}
int ret = xmlTextReaderRead( m_pReader );
while (ret == 1)
{
// Get the node type
int type = xmlTextReaderNodeType( m_pReader );
switch (type )
{
// Error
case -1:
return -1;
break;
// Begin element
case 1:
// Read the element name
const xmlChar *eltName = xmlTextReaderConstName( m_pReader );
if( !eltName )
{
return -1;
}
// Read the attributes
AttrList_t attributes;
while( xmlTextReaderMoveToNextAttribute( m_pReader ) == 1 )
{
const xmlChar *name = xmlTextReaderConstName( m_pReader );
const xmlChar *value = xmlTextReaderConstValue( m_pReader );
if( !name || !value )
{
return -1;
}
attributes[(const char*)name] = (const char*)value;
}
handleBeginElement( (const char*)eltName, attributes);
break;
}
ret = xmlTextReaderRead( m_pReader );
}
return 0;
}
void XMLParser::handleBeginElement( const string &rName,
AttrList_t &attributes )
{
fprintf(stderr,"%s\n", rName.c_str());
AttrList_t::const_iterator it;
for (it = attributes.begin(); it != attributes.end(); it++)
{
fprintf(stderr," %s = %s\n", (*it).first, (*it).second);
}
}
/*****************************************************************************
* xmlparser.hpp
*****************************************************************************
* Copyright (C) 2004 VideoLAN
* $Id: xmlparser.hpp,v 1.1 2004/01/24 13:08:12 asmax Exp $
*
* Authors: Cyril Deguet <asmax@via.ecp.fr>
* Olivier Teulire <ipkiss@via.ecp.fr>
*
* 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, USA.
*****************************************************************************/
#ifndef XMLPARSER_HPP
#define XMLPARSER_HPP
#include "../src/skin_common.hpp"
#include <libxml/xmlreader.h>
#include <map>
#include <string>
/// XML parser using libxml2 text reader API
class XMLParser: public SkinObject
{
public:
XMLParser( intf_thread_t *pIntf, const string &rFileName );
virtual ~XMLParser();
int parse();
private:
// Key comparison function for type "const char*"
struct ltstr
{
bool operator()(const char* s1, const char* s2) const
{
return strcmp(s1, s2) < 0;
}
};
/// Type for attribute lists
typedef map<const char*, const char*, ltstr> AttrList_t;
/// Reader context
xmlTextReaderPtr m_pReader;
void handleBeginElement( const string &rName, AttrList_t &attributes );
};
#endif
......@@ -2,7 +2,7 @@
* theme_loader.cpp
*****************************************************************************
* Copyright (C) 2003 VideoLAN
* $Id: theme_loader.cpp,v 1.4 2004/01/18 00:25:02 asmax Exp $
* $Id: theme_loader.cpp,v 1.5 2004/01/24 13:08:12 asmax Exp $
*
* Authors: Cyril Deguet <asmax@via.ecp.fr>
* Olivier Teulire <ipkiss@via.ecp.fr>
......@@ -26,6 +26,7 @@
#include "theme.hpp"
#include "../parser/builder.hpp"
#include "../parser/parser_context.hpp"
#include "../parser/xmlparser.hpp"
#include "../src/os_factory.hpp"
#include "../src/window_manager.hpp"
......@@ -207,6 +208,9 @@ bool ThemeLoader::parse( const string &xmlFile )
return false;
}
XMLParser parser( getIntf(), xmlFile );
parser.parse();
// Build and store the theme
Builder builder( getIntf(), context.m_data );
getIntf()->p_sys->p_theme = builder.build();
......
......@@ -2,7 +2,7 @@
* var_manager.cpp
*****************************************************************************
* Copyright (C) 2003 VideoLAN
* $Id: var_manager.cpp,v 1.2 2004/01/11 17:12:17 asmax Exp $
* $Id: var_manager.cpp,v 1.3 2004/01/24 13:08:12 asmax Exp $
*
* Authors: Cyril Deguet <asmax@via.ecp.fr>
* Olivier Teulire <ipkiss@via.ecp.fr>
......@@ -31,6 +31,17 @@ VarManager::VarManager( intf_thread_t *pIntf ): SkinObject( pIntf ),
}
VarManager::~VarManager()
{
// Delete the variables in the reverse order they were added
list<string>::const_iterator it;
for( it = m_varList.begin(); it != m_varList.end(); it++ )
{
m_varMap.erase(*it);
}
}
VarManager *VarManager::instance( intf_thread_t *pIntf )
{
if( ! pIntf->p_sys->p_varManager )
......@@ -59,6 +70,7 @@ void VarManager::destroy( intf_thread_t *pIntf )
void VarManager::registerVar( const VariablePtr &rcVar, const string &rName )
{
m_varMap[rName] = rcVar;
m_varList.push_front(rName);
}
......
......@@ -2,7 +2,7 @@
* var_manager.hpp
*****************************************************************************
* Copyright (C) 2003 VideoLAN
* $Id: var_manager.hpp,v 1.2 2004/01/11 17:12:17 asmax Exp $
* $Id: var_manager.hpp,v 1.3 2004/01/24 13:08:12 asmax Exp $
*
* Authors: Cyril Deguet <asmax@via.ecp.fr>
* Olivier Teulire <ipkiss@via.ecp.fr>
......@@ -26,6 +26,7 @@
#define VAR_MANAGER_HPP
#include "../utils/var_text.hpp"
#include <list>
#include <map>
......@@ -60,10 +61,12 @@ class VarManager: public SkinObject
VarText m_helpText;
/// Map of registerd variables
map<string, VariablePtr> m_varMap;
/// List of registed variables
list<string> m_varList;
/// Private because it is a singleton
VarManager( intf_thread_t *pIntf );
virtual ~VarManager() {}
virtual ~VarManager();
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment