diff options
| author | Cracker64 <cracker642@gmail.com> | 2011-02-03 21:38:58 (GMT) |
|---|---|---|
| committer | Cracker64 <cracker642@gmail.com> | 2011-02-03 21:38:58 (GMT) |
| commit | 1755f08e44b4a8a6bc60bc5c92fbc7fff558f32a (patch) | |
| tree | ad962da2152a0f9378582a5bd94ac044a27f452f /src | |
| parent | db038e9643a99de5ddaba04d99eaceab91fc860d (diff) | |
| download | powder-1755f08e44b4a8a6bc60bc5c92fbc7fff558f32a.zip powder-1755f08e44b4a8a6bc60bc5c92fbc7fff558f32a.tar.gz | |
variables and if statements for scripts, GoL is glitchy for me, i don't know why
Diffstat (limited to 'src')
| -rw-r--r-- | src/interface.c | 4 | ||||
| -rw-r--r-- | src/main.c | 119 |
2 files changed, 117 insertions, 6 deletions
diff --git a/src/interface.c b/src/interface.c index 2989571..346c923 100644 --- a/src/interface.c +++ b/src/interface.c @@ -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"); @@ -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 + if(fileread[i] != ' ') + tokens[i-m] = fileread[i]; + } + if(fileread[i] == ' ' || fileread[i] == '\n') { - process_command(vid_buf, pch, console_error); + 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) |
