summaryrefslogtreecommitdiff
path: root/plugins/IEView/src/Template.cpp
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2013-04-06 21:07:53 +0000
committerGeorge Hazan <george.hazan@gmail.com>2013-04-06 21:07:53 +0000
commit37f0dfdfac4dc0af578769b02e29efb9926415bb (patch)
treecadf855bb7a074eb78f45b725e5b9a3e965fa045 /plugins/IEView/src/Template.cpp
parente7891a7f13d94b6eae7f74f7354e0a3643d1de01 (diff)
postfix to the standard functions patch by Mataes
git-svn-id: http://svn.miranda-ng.org/main/trunk@4351 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/IEView/src/Template.cpp')
-rw-r--r--plugins/IEView/src/Template.cpp281
1 files changed, 149 insertions, 132 deletions
diff --git a/plugins/IEView/src/Template.cpp b/plugins/IEView/src/Template.cpp
index 5400906ae7..20a3dd2cc9 100644
--- a/plugins/IEView/src/Template.cpp
+++ b/plugins/IEView/src/Template.cpp
@@ -21,58 +21,65 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "ieview_common.h"
-TokenDef::TokenDef(const char *tokenString) {
+TokenDef::TokenDef(const char *tokenString)
+{
this->tokenString = tokenString;
this->tokenLen = (int)strlen(tokenString);
this->token = 0;
this->escape = 0;
}
-TokenDef::TokenDef(const char *tokenString, int token, int escape) {
+TokenDef::TokenDef(const char *tokenString, int token, int escape)
+{
this->tokenString = tokenString;
this->token = token;
this->tokenLen = (int)strlen(tokenString);
this->escape = escape;
}
-Token::Token(int type, const char *text, int escape) {
+Token::Token(int type, const char *text, int escape)
+{
next = NULL;
this->type = type;
this->escape = escape;
- if (text!=NULL) {
+ if (text!=NULL)
this->text = mir_strdup(text);
- } else {
+ else
this->text = NULL;
- }
}
-Token::~Token() {
- if (text!=NULL) {
- mir_free(text);
- }
+Token::~Token()
+{
+ mir_free(text);
}
-Token * Token::getNext() {
+Token* Token::getNext()
+{
return next;
}
-void Token::setNext(Token *ptr) {
+void Token::setNext(Token *ptr)
+{
next = ptr;
}
-int Token::getType() {
+int Token::getType()
+{
return type;
}
-int Token::getEscape() {
+int Token::getEscape()
+{
return escape;
}
-const char *Token::getText() {
+const char* Token::getText()
+{
return text;
}
-Template::Template(const char *name, const char *text) {
+Template::Template(const char *name, const char *text)
+{
next = NULL;
tokens = NULL;
this->text = mir_strdup(text);
@@ -80,9 +87,10 @@ Template::Template(const char *name, const char *text) {
tokenize();
}
-Template::~Template() {
- if (text != NULL) mir_free(text);
- if (name != NULL) mir_free(name);
+Template::~Template()
+{
+ mir_free(text);
+ mir_free(name);
Token *ptr = tokens, *ptr2;
tokens = NULL;
for (;ptr!=NULL;ptr = ptr2) {
@@ -91,22 +99,26 @@ Template::~Template() {
}
}
-const char *Template::getText() {
+const char* Template::getText()
+{
return text;
}
-const char *Template::getName() {
+const char* Template::getName()
+{
return name;
}
-Template* Template::getNext() {
+Template* Template::getNext()
+{
return next;
}
-bool Template::equals(const char *name) {
- if (!strcmp(name, this->name)) {
+bool Template::equals(const char *name)
+{
+ if (!strcmp(name, this->name))
return true;
- }
+
return false;
}
@@ -152,73 +164,77 @@ static TokenDef tokenNames[] = {
TokenDef("%\\fileDesc%", Token::FILEDESC, 1)
};
-void Template::tokenize() {
- if (text!=NULL) {
-// debugView->writef("Tokenizing: %s<br>---<br>", text);
- char *str = mir_strdup(text);
- Token *lastToken = NULL;
- int lastTokenType = Token::PLAIN;
- int lastTokenEscape = 0;
- int l = (int)strlen(str);
- for (int i=0, lastTokenStart=0; i<=l;) {
- Token *newToken;
- int newTokenType = 0, newTokenSize = 0, newTokenEscape = 0;
- if (str[i]=='\0') {
- newTokenType = Token::END;
- newTokenSize = 1;
- newTokenEscape = 0;
- } else {
- bool found = false;
- for (unsigned int j=0; j<(sizeof(tokenNames)/sizeof(tokenNames[0])); j++) {
- if (!strncmp(str+i, tokenNames[j].tokenString, tokenNames[j].tokenLen)) {
- newTokenType = tokenNames[j].token;
- newTokenSize = tokenNames[j].tokenLen;
- newTokenEscape = tokenNames[j].escape;
- found = true;
- break;
- }
- }
- if (!found) {
- newTokenType = Token::PLAIN;
- newTokenSize = 1;
- newTokenEscape = 0;
+void Template::tokenize()
+{
+ if (text == NULL)
+ return;
+
+ char *str = mir_strdup(text);
+ Token *lastToken = NULL;
+ int lastTokenType = Token::PLAIN;
+ int lastTokenEscape = 0;
+ int l = (int)strlen(str);
+ for (int i=0, lastTokenStart=0; i<=l;) {
+ Token *newToken;
+ int newTokenType = 0, newTokenSize = 0, newTokenEscape = 0;
+ if (str[i]=='\0') {
+ newTokenType = Token::END;
+ newTokenSize = 1;
+ newTokenEscape = 0;
+ }
+ else {
+ bool found = false;
+ for (unsigned int j=0; j<(sizeof(tokenNames)/sizeof(tokenNames[0])); j++) {
+ if (!strncmp(str+i, tokenNames[j].tokenString, tokenNames[j].tokenLen)) {
+ newTokenType = tokenNames[j].token;
+ newTokenSize = tokenNames[j].tokenLen;
+ newTokenEscape = tokenNames[j].escape;
+ found = true;
+ break;
}
}
- if (newTokenType != Token::PLAIN) {
- if (str[i + newTokenSize] == '%') {
- //newTokenSize++;
- }
- str[i] = '\0';
+ if (!found) {
+ newTokenType = Token::PLAIN;
+ newTokenSize = 1;
+ newTokenEscape = 0;
}
- if ((lastTokenType!=newTokenType || lastTokenEscape != newTokenEscape) && i!=lastTokenStart) {
- if (lastTokenType == Token::PLAIN) {
- newToken = new Token(lastTokenType, str+lastTokenStart, lastTokenEscape);
- } else {
- newToken = new Token(lastTokenType, NULL, lastTokenEscape);
- }
- if (lastToken != NULL) {
- lastToken->setNext(newToken);
- } else {
- tokens = newToken;
- }
- lastToken = newToken;
- lastTokenStart = i;
+ }
+ if (newTokenType != Token::PLAIN) {
+ if (str[i + newTokenSize] == '%') {
+ //newTokenSize++;
}
- lastTokenEscape = newTokenEscape;
- lastTokenType = newTokenType;
- i += newTokenSize;
+ str[i] = '\0';
+ }
+ if ((lastTokenType != newTokenType || lastTokenEscape != newTokenEscape) && i != lastTokenStart) {
+ if (lastTokenType == Token::PLAIN)
+ newToken = new Token(lastTokenType, str+lastTokenStart, lastTokenEscape);
+ else
+ newToken = new Token(lastTokenType, NULL, lastTokenEscape);
+
+ if (lastToken != NULL)
+ lastToken->setNext(newToken);
+ else
+ tokens = newToken;
+
+ lastToken = newToken;
+ lastTokenStart = i;
}
- mir_free(str);
+ lastTokenEscape = newTokenEscape;
+ lastTokenType = newTokenType;
+ i += newTokenSize;
}
+ mir_free(str);
}
-Token * Template::getTokens() {
+Token* Template::getTokens()
+{
return tokens;
}
TemplateMap* TemplateMap::mapList = NULL;
-TemplateMap::TemplateMap(const char *name) {
+TemplateMap::TemplateMap(const char *name)
+{
entries = NULL;
next = NULL;
filename = NULL;
@@ -227,17 +243,16 @@ TemplateMap::TemplateMap(const char *name) {
this->rtl = false;
}
-TemplateMap::~TemplateMap() {
- if (name != NULL) {
- mir_free(name);
- }
- if (filename != NULL) {
- delete filename;
- }
+TemplateMap::~TemplateMap()
+{
+ mir_free(name);
+ mir_free(filename);
+
clear();
}
-TemplateMap* TemplateMap::add(const char *id, const char *filename) {
+TemplateMap* TemplateMap::add(const char *id, const char *filename)
+{
TemplateMap *map;
for (map=mapList; map!=NULL; map=map->next) {
if (!strcmp(map->name, id)) {
@@ -253,13 +268,15 @@ TemplateMap* TemplateMap::add(const char *id, const char *filename) {
return map;
}
-void TemplateMap::addTemplate(const char *name, const char *text) {
+void TemplateMap::addTemplate(const char *name, const char *text)
+{
Template *tmplate = new Template(name, text);
tmplate->next = entries;
entries = tmplate;
}
-void TemplateMap::clear() {
+void TemplateMap::clear()
+{
Template *ptr, *ptr2;
ptr = entries;
entries = NULL;
@@ -321,23 +338,23 @@ static TokenDef templateNames[] = {
TokenDef("<!--hMessageOutGroupEndRTL-->")
};
-TemplateMap* TemplateMap::loadTemplateFile(const char *id, const char *filename, bool onlyInfo) {
- FILE* fh;
+TemplateMap* TemplateMap::loadTemplateFile(const char *id, const char *filename, bool onlyInfo)
+{
char lastTemplate[1024], tmp2[1024];
unsigned int i=0;
- TemplateMap *tmap;
- if (filename == NULL || strlen(filename) == 0) {
+ if (filename == NULL || strlen(filename) == 0)
return NULL;
- }
- fh = fopen(filename, "rt");
- if (fh == NULL) {
+
+ FILE *fh = fopen(filename, "rt");
+ if (fh == NULL)
return NULL;
- }
- if (!onlyInfo) {
+
+ TemplateMap *tmap;
+ if (!onlyInfo)
tmap = TemplateMap::add(id, filename);
- } else {
+ else
tmap = new TemplateMap(id);
- }
+
char store[4096];
bool wasTemplate = false;
char *templateText = NULL;
@@ -353,23 +370,23 @@ TemplateMap* TemplateMap::loadTemplateFile(const char *id, const char *filename,
}
}
if (bFound) {
- if (wasTemplate) {
+ if (wasTemplate)
tmap->addTemplate(lastTemplate, templateText);
- }
- if (templateText!=NULL) {
+
+ if (templateText != NULL)
free (templateText);
- }
+
templateText = NULL;
templateTextSize = 0;
wasTemplate = true;
sscanf(store, "<!--%[^-]", lastTemplate);
- } else if (wasTemplate) {
- Utils::appendText(&templateText, &templateTextSize, "%s", store);
}
+ else if (wasTemplate)
+ Utils::appendText(&templateText, &templateTextSize, "%s", store);
}
- if (wasTemplate) {
+ if (wasTemplate)
tmap->addTemplate(lastTemplate, templateText);
- }
+
fclose(fh);
static const char *groupTemplates[] = {"MessageInGroupStart", "MessageInGroupInner",
"hMessageInGroupStart", "hMessageInGroupInner",
@@ -393,22 +410,23 @@ TemplateMap* TemplateMap::loadTemplateFile(const char *id, const char *filename,
return tmap;
}
-bool TemplateMap::isGrouping() {
+bool TemplateMap::isGrouping()
+{
return grouping;
}
-bool TemplateMap::isRTL() {
+bool TemplateMap::isRTL()
+{
return rtl;
}
-Template* TemplateMap::getTemplate(const char *text) {
- Template *ptr;
- for (ptr=entries; ptr!=NULL; ptr=ptr->getNext()) {
- if (ptr->equals(text)) {
- break;
- }
- }
- return ptr;
+Template* TemplateMap::getTemplate(const char *text)
+{
+ for (Template *ptr = entries; ptr != NULL; ptr = ptr->getNext())
+ if (ptr->equals(text))
+ return ptr;
+
+ return 0;
}
Template* TemplateMap::getTemplate(const char *proto, const char *text) {
@@ -421,29 +439,28 @@ Template* TemplateMap::getTemplate(const char *proto, const char *text) {
return NULL;
}
-TemplateMap* TemplateMap::getTemplateMap(const char *proto) {
- TemplateMap *ptr;
- for (ptr=mapList; ptr!=NULL; ptr=ptr->next) {
- if (!strcmp(ptr->name, proto)) {
+TemplateMap* TemplateMap::getTemplateMap(const char *proto)
+{
+ for (TemplateMap *ptr=mapList; ptr != NULL; ptr = ptr->next)
+ if (!strcmp(ptr->name, proto))
return ptr;
- }
- }
+
return NULL;
}
-const char *TemplateMap::getFilename() {
+const char *TemplateMap::getFilename()
+{
return filename;
}
-void TemplateMap::setFilename(const char *filename) {
- if (this->filename != NULL) {
- mir_free(this->filename);
- }
- this->filename = mir_strdup(filename);
- Utils::convertPath(this->filename);
+void TemplateMap::setFilename(const char *_filename)
+{
+ replaceStr(filename, _filename);
+ Utils::convertPath(filename);
}
-TemplateMap* TemplateMap::loadTemplates(const char *id, const char *filename, bool onlyInfo) {
+TemplateMap* TemplateMap::loadTemplates(const char *id, const char *filename, bool onlyInfo)
+{
return loadTemplateFile(id, filename, onlyInfo);
}