summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjacob1 <jfu614@gmail.com>2013-08-22 14:53:40 (GMT)
committer jacob1 <jfu614@gmail.com>2013-08-22 14:53:40 (GMT)
commit68984bb9be07ea4b6eccf76dddaf3f31d23f577c (patch)
treea2e4c6801c2b09e91d52bb0d1539b1b8ec80704b /src
parentb2045b0a7fadbee87ecf52fe14699819b58e7667 (diff)
parent4a308cbf661bb40efdf53c6632f875c6c393a307 (diff)
downloadpowder-68984bb9be07ea4b6eccf76dddaf3f31d23f577c.zip
powder-68984bb9be07ea4b6eccf76dddaf3f31d23f577c.tar.gz
Merge pull request #155 from mniip/regex
Remove regex dependency
Diffstat (limited to 'src')
-rw-r--r--src/Misc.cpp12
-rw-r--r--src/Misc.h2
-rw-r--r--src/graphics/Renderer.cpp28
-rw-r--r--src/gui/game/GameController.cpp33
-rw-r--r--src/gui/game/SignTool.cpp22
-rw-r--r--src/simulation/Sign.cpp41
6 files changed, 89 insertions, 49 deletions
diff --git a/src/Misc.cpp b/src/Misc.cpp
index 3128691..6b0c1d5 100644
--- a/src/Misc.cpp
+++ b/src/Misc.cpp
@@ -2,7 +2,6 @@
#include <sstream>
#include <stdlib.h>
#include <string.h>
-#include <regex.h>
#include <sys/types.h>
#include <cmath>
#include "Config.h"
@@ -173,17 +172,6 @@ void clean_text(char *text, int vwidth)
}
}
-int sregexp(const char *str, char *pattern)
-{
- int result;
- regex_t patternc;
- if (regcomp(&patternc, pattern, 0)!=0)
- return 1;
- result = regexec(&patternc, str, 0, NULL, 0);
- regfree(&patternc);
- return result;
-}
-
void save_string(FILE *f, char *str)
{
int li = strlen(str);
diff --git a/src/Misc.h b/src/Misc.h
index 1a43fe3..33601f6 100644
--- a/src/Misc.h
+++ b/src/Misc.h
@@ -62,8 +62,6 @@ void load_presets(void);
void save_string(FILE *f, char *str);
-int sregexp(const char *str, char *pattern);
-
int load_string(FILE *f, char *str, int max);
void strcaturl(char *dst, char *src);
diff --git a/src/graphics/Renderer.cpp b/src/graphics/Renderer.cpp
index 833cec2..28e4d9e 100644
--- a/src/graphics/Renderer.cpp
+++ b/src/graphics/Renderer.cpp
@@ -912,7 +912,7 @@ void Renderer::DrawWalls()
void Renderer::DrawSigns()
{
- int i, j, x, y, w, h, dx, dy,mx,my,b=1,bq;
+ int i, j, x, y, w, h, dx, dy,mx,my,b=1,bq,match;
std::vector<sign> signs = sim->signs;
#ifdef OGLR
GLint prevFbo;
@@ -923,14 +923,30 @@ void Renderer::DrawSigns()
for (i=0; i < signs.size(); i++)
if (signs[i].text.length())
{
- std::string text = sim->signs[i].getText(sim);
- sim->signs[i].pos(text, x, y, w, h);
+ std::string text = signs[i].getText(sim);
+ const char* str = signs[i].text.c_str();
+ signs[i].pos(text, x, y, w, h);
clearrect(x, y, w+1, h);
drawrect(x, y, w+1, h, 192, 192, 192, 255);
- if (sregexp(signs[i].text.c_str(), "^{[ct]:[0-9]*|.*}$"))
- drawtext(x+3, y+3, text, 255, 255, 255, 255);
- else
+ match=0;
+ // check if it's a link sign
+ if (str[0]=='{' && (str[1]=='c' || str[1]=='t') && str[2]==':' && str[3]>='0' && str[3]<='9')
+ {
+ const char* p=str+4;
+ while (*p>='0' && *p<='9')
+ p++;
+ if (*p=='|')
+ {
+ while (*p)
+ p++;
+ if (p[-1]=='}')
+ match=1;
+ }
+ }
+ if (match)
drawtext(x+3, y+3, text, 0, 191, 255, 255);
+ else
+ drawtext(x+3, y+3, text, 255, 255, 255, 255);
x = signs[i].x;
y = signs[i].y;
diff --git a/src/gui/game/GameController.cpp b/src/gui/game/GameController.cpp
index 8b58b48..c514d3e 100644
--- a/src/gui/game/GameController.cpp
+++ b/src/gui/game/GameController.cpp
@@ -571,19 +571,30 @@ bool GameController::MouseUp(int x, int y, unsigned button)
(*iter).pos((*iter).getText(sim), signx, signy, signw, signh);
if (x>=signx && x<=signx+signw && y>=signy && y<=signy+signh)
{
- if (sregexp((*iter).text.c_str(), "^{[ct]:[0-9]*|.*}$")==0)
+ int match=0;
+ const char* str=(*iter).text.c_str();
+ const char* e;
+ if (str[0]=='{' && (str[1]=='c' || str[1]=='t') && str[2]==':' && str[3]>='0' && str[3]<='9')
+ {
+ const char* p=str+4;
+ while (*p>='0' && *p<='9')
+ p++;
+ e=p;
+ if (*p=='|')
+ {
+ while (*p)
+ p++;
+ if (p[-1]=='}')
+ {
+ match=1;
+ }
+ }
+ }
+ if (match)
{
- const char * signText = (*iter).text.c_str();
char buff[256];
- int sldr;
-
- memset(buff, 0, sizeof(buff));
-
- for (sldr=3; signText[sldr] != '|'; sldr++)
- buff[sldr-3] = signText[sldr];
-
- buff[sldr-3] = '\0';
-
+ strcpy(buff, str+3);
+ buff[e-str-3]=0;
int tempSaveID = format::StringToNumber<int>(std::string(buff));
if (tempSaveID)
{
diff --git a/src/gui/game/SignTool.cpp b/src/gui/game/SignTool.cpp
index 87ed59e..a71f8e2 100644
--- a/src/gui/game/SignTool.cpp
+++ b/src/gui/game/SignTool.cpp
@@ -177,16 +177,30 @@ void SignWindow::DoDraw()
for(std::vector<sign>::iterator iter = sim->signs.begin(), end = sim->signs.end(); iter != end; ++iter)
{
sign & currentSign = *iter;
- int x, y, w, h, dx, dy;
+ int x, y, w, h, dx, dy, match=0;
Graphics * g = ui::Engine::Ref().g;
std::string text = currentSign.getText(sim);
+ const char* str = currentSign.text.c_str();
currentSign.pos(text, x, y, w, h);
g->clearrect(x, y, w+1, h);
g->drawrect(x, y, w+1, h, 192, 192, 192, 255);
- if (sregexp(currentSign.text.c_str(), "^{[ct]:[0-9]*|.*}$"))
- g->drawtext(x+3, y+3, text, 255, 255, 255, 255);
- else
+ if (str[0]=='{' && (str[1]=='c' || str[1]=='t') && str[2]==':' && str[3]>='0' && str[3]<='9')
+ {
+ const char* p=str+4;
+ while (*p>='0' && *p<='9')
+ p++;
+ if (*p=='|')
+ {
+ while (*p)
+ p++;
+ if (p[-1]=='}')
+ match=1;
+ }
+ }
+ if (match)
g->drawtext(x+3, y+3, text, 0, 191, 255, 255);
+ else
+ g->drawtext(x+3, y+3, text, 255, 255, 255, 255);
x = currentSign.x;
y = currentSign.y;
diff --git a/src/simulation/Sign.cpp b/src/simulation/Sign.cpp
index 7ba94af..f6b8420 100644
--- a/src/simulation/Sign.cpp
+++ b/src/simulation/Sign.cpp
@@ -31,25 +31,38 @@ std::string sign::getText(Simulation *sim)
else
sprintf(buff, "Temp: 0.00"); //...temperature
}
- else if (sregexp(signText, "^{[ct]:[0-9]*|.*}$")==0)
+ else
{
- int sldr, startm;
- memset(buff, 0, sizeof(buff));
- for (sldr=3; signText[sldr-1] != '|'; sldr++)
- startm = sldr + 1;
- sldr = startm;
- while (signText[sldr] != '}')
+ int match=0;
+ const char* r;
+ const char* e;
+ if (signText[0]=='{' && (signText[1]=='c' || signText[1]=='t') && signText[2]==':' && signText[3]>='0' && signText[3]<='9')
{
- buff[sldr - startm] = signText[sldr];
- sldr++;
+ const char* p=signText+4;
+ while (*p>='0' && *p<='9')
+ p++;
+ if (*p=='|')
+ {
+ r=p+1;
+ while (*p)
+ p++;
+ if (p[-1]=='}')
+ {
+ match=1;
+ e=p;
+ }
+ }
}
- }
- else
- {
- sprintf(buff, "%s", signText);
+ if (match)
+ {
+ strcpy(buff, r);
+ buff[e-r-1]=0;
+ }
+ else
+ strcpy(buff, signText);
}
- return std::string(buff,256);
+ return std::string(buff);
}
void sign::pos(std::string signText, int & x0, int & y0, int & w, int & h)