variables and if statements for scripts, GoL is glitchy for me, i don't know why

This commit is contained in:
Cracker64 2011-02-03 16:38:58 -05:00
parent db038e9643
commit 1755f08e44
2 changed files with 118 additions and 7 deletions

View File

@ -3965,6 +3965,7 @@ int console_parse_type(char *txt, int *element, char *err)
if (strcmp(txt,num)==0)
{
*element = i;
strcpy(err,"");
return 1;
}
}
@ -3976,12 +3977,14 @@ int console_parse_type(char *txt, int *element, char *err)
if (i>=0)
{
*element = i;
strcpy(err,"");
return 1;
}
for (i=1; i<PT_NUM; i++) {
if (strcasecmp(txt,ptypes[i].name)==0)
{
*element = i;
strcpy(err,"");
return 1;
}
}
@ -4044,6 +4047,7 @@ int console_parse_partref(char *txt, int *which, char *err)
if (i>=0 && i<NPART && parts[i].type)
{
*which = i;
strcpy(err,"");
return 1;
}
strcpy(err,"Particle does not exist");

View File

@ -1780,7 +1780,7 @@ int main(int argc, char *argv[])
console = console_ui(vid_buf,console_error);
console = mystrdup(console);
strcpy(console_error,"");
if(process_command(vid_buf,console,&console_error)==0)
if(process_command(vid_buf,console,&console_error)==-1)
{
free(console);
break;
@ -2627,7 +2627,10 @@ int main(int argc, char *argv[])
}
int process_command(pixel *vid_buf,char *console,char *console_error) {
int nx,ny,i,j,k;
int x,y,nx,ny,i,j,k,m;
int do_next = 1;
char xcoord[10];
char ycoord[10];
char *console2;
char *console3;
char *console4;
@ -2641,24 +2644,112 @@ char *console5;
console5 = strtok(NULL, " ");
if(strcmp(console2, "quit")==0)
{
return 0;
return -1;
}
else if(strcmp(console2, "file")==0 && console3)
{
FILE *f=fopen(console3, "r");
if(f)
{
nx = 0;
ny = 0;
j = 0;
m = 0;
if(console4)
console_parse_coords(console4, &nx , &ny, console_error);
char fileread[5000];//TODO: make this change with file size
char pch[5000];
memset(pch,0,sizeof(pch));
memset(fileread,0,sizeof(fileread));
char tokens[10];
int tokensize;
fread(fileread,1,5000,f);
j = 0;
for(i=0; i<strlen(fileread); i++)
{
if(fileread[i] != '\n')
pch[i-j] = fileread[i];
else
{
process_command(vid_buf, pch, console_error);
pch[i-j] = fileread[i];
if(fileread[i] != ' ')
tokens[i-m] = fileread[i];
}
if(fileread[i] == ' ' || fileread[i] == '\n')
{
if(sregexp(tokens,"^x.[0-9],y.[0-9]")==0)//TODO: fix regex matching to work with x,y ect, right now it has to have a +0 or -0
{
char temp[5];
int starty = 0;
tokensize = strlen(tokens);
x = 0;
y = 0;
strcpy(xcoord,strtok(tokens,","));
strcpy(ycoord,strtok(NULL," "));
if(xcoord[1]=='+')//get additions
{
for(k = 2; k<strlen(xcoord);k++)
{
temp[k-2] = xcoord[k];
}
x += atoi(temp);
}
else if(xcoord[1]=='-')
{
for(k = 2; k<strlen(xcoord);k++)
{
temp[k-2] = xcoord[k];
}
x += -atoi(temp);
}
memset(temp, 0,sizeof(temp));
if(ycoord[1]=='+')
{
for(k = 2; k<strlen(ycoord);k++)
{
temp[k-2] = ycoord[k];
}
y += atoi(temp);
}
else if(ycoord[1]=='-')
{
for(k = 2; k<strlen(ycoord);k++)
{
temp[k-2] = ycoord[k];
}
y += -atoi(temp);
}
x += nx;
y += ny;
sprintf(xcoord,"%d",x);
sprintf(ycoord,"%d",y);
for(k = 0; k<strlen(xcoord);k++)//rewrite pch with numbers
{
pch[i-j-tokensize+k] = xcoord[k];
starty = k+1;
}
pch[i-j-tokensize+starty] = ',';
starty++;
for(k=0;k<strlen(ycoord);k++)
{
pch[i-j-tokensize+starty+k] = ycoord[k];
}
pch[i-j-tokensize +strlen(xcoord) +1 +strlen(ycoord)] = ' ';
j = j -tokensize +strlen(xcoord) +1 +strlen(ycoord);
}
memset(tokens,0,sizeof(tokens));
m = i+1;
}
if(fileread[i] == '\n')
{
if(do_next)
{
if(strcmp(pch,"else")==0)
do_next = 0;
else
do_next = process_command(vid_buf, pch, console_error);
}
else if(strcmp(pch,"endif")==0 || strcmp(pch,"else")==0)
do_next = 1;
memset(pch,0,sizeof(pch));
j = i+1;
}
@ -2682,6 +2773,22 @@ char *console5;
console_mode = 0;
}
}
else if(strcmp(console2, "if")==0 && console3)
{
if(strcmp(console3, "type")==0)//TODO: add more than just type, and be able to check greater/less than
{
if (console_parse_partref(console4, &i, console_error)
&& console_parse_type(console5, &j, console_error))
{
if(parts[i].type==j)
return 1;
else
return 0;
}
else
return 0;
}
}
else if (strcmp(console2, "create")==0 && console3 && console4)
{
if (console_parse_type(console3, &j, console_error)