Merge pull request #155 from mniip/regex

Remove regex dependency
This commit is contained in:
jacob1 2013-08-22 07:53:40 -07:00
commit 68984bb9be
7 changed files with 91 additions and 51 deletions

View File

@ -285,7 +285,7 @@ if(GetOption('rpi')):
if(GetOption('win')):
openGLLibs = ['opengl32', 'glew32']
env.Prepend(LIBS=['mingw32', 'ws2_32', 'SDLmain', 'SDL', 'regex'])
env.Prepend(LIBS=['mingw32', 'ws2_32', 'SDLmain', 'SDL'])
env.Append(CCFLAGS=['-std=gnu++98'])
env.Append(LIBS=['winmm', 'gdi32'])
env.Append(CPPDEFINES=["WIN"])

View File

@ -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);

View File

@ -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);

View File

@ -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;

View File

@ -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)
{

View File

@ -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;

View File

@ -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)
{
int sldr, startm;
memset(buff, 0, sizeof(buff));
for (sldr=3; signText[sldr-1] != '|'; sldr++)
startm = sldr + 1;
sldr = startm;
while (signText[sldr] != '}')
{
buff[sldr - startm] = signText[sldr];
sldr++;
}
}
else
{
sprintf(buff, "%s", signText);
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')
{
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;
}
}
}
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)