From 714ee26b1bdcfdac2968d7dcf885803074c4aa57 Mon Sep 17 00:00:00 2001 From: louis Date: Sat, 29 Nov 2014 16:00:42 +0100 Subject: [PATCH] fixed bug that global double vars are not working --- HISTORY | 2 ++ libtemplate/globals.c | 3 +++ libtemplate/parameter.c | 9 ++++++++- libtemplate/xmlparser.c | 10 +++++----- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/HISTORY b/HISTORY index baf0617..85e296c 100644 --- a/HISTORY +++ b/HISTORY @@ -100,3 +100,5 @@ Version 0.0.6 Version 0.0.7 +- fixed bug that global double vars are not working + diff --git a/libtemplate/globals.c b/libtemplate/globals.c index af83da2..1896e7c 100644 --- a/libtemplate/globals.c +++ b/libtemplate/globals.c @@ -71,6 +71,9 @@ void cGlobals::Debug(void) { for (map ::iterator myInt = intVars.begin(); myInt != intVars.end(); myInt++) { dsyslog("skindesigner: Integer Variable \"%s\": %d", (myInt->first).c_str(), myInt->second); } + for (map ::iterator myDouble = doubleVars.begin(); myDouble != doubleVars.end(); myDouble++) { + dsyslog("skindesigner: Double Variable \"%s\": %f", (myDouble->first).c_str(), myDouble->second); + } for (map ::iterator myStr = stringVars.begin(); myStr != stringVars.end(); myStr++) { dsyslog("skindesigner: String Variable \"%s\": \"%s\"", (myStr->first).c_str(), (myStr->second).c_str()); } diff --git a/libtemplate/parameter.c b/libtemplate/parameter.c index c646f06..e3e48bd 100644 --- a/libtemplate/parameter.c +++ b/libtemplate/parameter.c @@ -1,3 +1,4 @@ +#include "../config.h" #include "parameter.h" using namespace std; @@ -164,7 +165,13 @@ bool cNumericParameter::CheckExpression(int &val, string &parsedVal) { if (foundToken != string::npos) { stringstream st; st << globDouble->second; - parsedValue = parsedValue.replace(foundToken, token.size(), st.str()); + string doubleVal = st.str(); + if (config.replaceDecPoint) { + if (doubleVal.find_first_of('.') != string::npos) { + std::replace( doubleVal.begin(), doubleVal.end(), '.', config.decPoint); + } + } + parsedValue = parsedValue.replace(foundToken, token.size(), doubleVal); } } } diff --git a/libtemplate/xmlparser.c b/libtemplate/xmlparser.c index bdaf0bb..8931f2f 100644 --- a/libtemplate/xmlparser.c +++ b/libtemplate/xmlparser.c @@ -145,11 +145,6 @@ bool cXmlParser::ParseView(void) { xmlAttrPtr attr = node->properties; vector > attribs; ParseAttributes(attr, node, attribs); - /* - for (vector >::iterator it = attribs.begin(); it != attribs.end(); it++) { - esyslog("skindesigner: attribute %s value %s", (it->first).c_str(), (it->second).c_str()); - } - */ ParseViewElement(node->name, node->xmlChildrenNode, attribs); } else if (view->ValidViewList((const char*)node->name)) { ParseViewList(node); @@ -360,6 +355,11 @@ void cXmlParser::InsertVariable(string name, string type, string value) { int val = atoi(value.c_str()); globals->intVars.insert(pair(name, val)); } else if (!type.compare("double")) { + if (config.replaceDecPoint) { + if (value.find_first_of('.') != string::npos) { + std::replace( value.begin(), value.end(), '.', config.decPoint); + } + } double val = atof(value.c_str()); globals->doubleVars.insert(pair(name, val)); } else if (!type.compare("string")) {