summaryrefslogtreecommitdiff
path: root/glcdskin/parser.c
diff options
context:
space:
mode:
authormrwastl <mrwastl@users.sourceforge.net>2011-07-30 13:53:25 +0200
committermrwastl <mrwastl@users.sourceforge.net>2011-07-30 13:53:25 +0200
commit2fa7db7a2d34973a168f90e6605ce123b293cf13 (patch)
tree9ce1db9c7b0e13ea36bdd26c7afb5a5d19965271 /glcdskin/parser.c
parent21d15ba6ddf7440f229eb627ff3cc28393e3faee (diff)
downloadgraphlcd-base-2fa7db7a2d34973a168f90e6605ce123b293cf13.tar.gz
graphlcd-base-2fa7db7a2d34973a168f90e6605ce123b293cf13.tar.bz2
skin definitions: added simple support for including files; increased graphlcd-base version to 0.3.0 and version of included libraries to 2.1.0; bug fix: don't syslog a detection of an invalid number when evaluating in cSkinFunction (just return that this is obviously not a valid function)
Diffstat (limited to 'glcdskin/parser.c')
-rw-r--r--glcdskin/parser.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/glcdskin/parser.c b/glcdskin/parser.c
index a06ebc4..411c832 100644
--- a/glcdskin/parser.c
+++ b/glcdskin/parser.c
@@ -143,6 +143,17 @@ static uint32_t oindex = 0;
static std::string errorDetail = "";
static std::string condblock_cond = "";
+// support for including files (templates, ...) in the skin definition
+// max. depth supported for file inclusion (-> detect recursive inclusions)
+#define MAX_INCLUDEDEPTH 5
+static int includeDepth = 0;
+static std::string subErrorDetail = "";
+
+bool StartElem(const std::string & name, std::map<std::string,std::string> & attrs);
+bool CharData(const std::string & text);
+bool EndElem(const std::string & name);
+
+
static bool CheckSkinVersion(const std::string & version) {
float currv;
@@ -186,6 +197,36 @@ bool StartElem(const std::string & name, std::map<std::string,std::string> & att
else
TAG_ERR_REMAIN("document");
}
+ else if (name == "include")
+ {
+ if (includeDepth + 1 < MAX_INCLUDEDEPTH) {
+ cSkinObject* tmpobj = new cSkinObject(new cSkinDisplay(skin));
+ cSkinString* path = new cSkinString(tmpobj, false);
+ ATTRIB_MAN_FUNC("path", path->Parse);
+ std::string strpath = path->Evaluate();
+ // is path relative? -> prepend skinpath
+ if (strpath[0] != '/') {
+ strpath = skin->Config().SkinPath() + "/" + strpath;
+ }
+ path = NULL;
+ tmpobj = NULL;
+
+ includeDepth++;
+ cXML incxml(strpath, skin->Config().CharSet());
+ incxml.SetNodeStartCB(StartElem);
+ incxml.SetNodeEndCB(EndElem);
+ incxml.SetCDataCB(CharData);
+ if (incxml.Parse() != 0) {
+ errorDetail = "error when parsing included xml file '"+strpath+"'"+ ( (subErrorDetail == "") ? "" : " ("+subErrorDetail+")");
+ syslog(LOG_ERR, "ERROR: graphlcd/skin: %s", errorDetail.c_str());
+ return false;
+ }
+ includeDepth--;
+ } else {
+ subErrorDetail = "max. include depth reached";
+ return false;
+ }
+ }
else if (name == "condblock")
{
int i = context.size() - 1;