summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjacksonmj <jacksonmj@jacksonmj.none>2011-02-07 15:54:57 (GMT)
committer jacksonmj <jacksonmj@jacksonmj.none>2011-02-07 15:56:10 (GMT)
commit5fbb37ba60d4d262f4c2d4fedb0b7b07cd0c0d0f (patch)
treec001f1e47f3728523d36903a55bf97cc0bfb42a6 /src
parentee100cb4f0dee7f59b975a07de4f59db2addbf02 (diff)
downloadpowder-5fbb37ba60d4d262f4c2d4fedb0b7b07cd0c0d0f.zip
powder-5fbb37ba60d4d262f4c2d4fedb0b7b07cd0c0d0f.tar.gz
Fix console particle number, coordinate parsing
Diffstat (limited to 'src')
-rw-r--r--src/interface.c14
1 files changed, 4 insertions, 10 deletions
diff --git a/src/interface.c b/src/interface.c
index 96b2dbc..ea63733 100644
--- a/src/interface.c
+++ b/src/interface.c
@@ -3995,13 +3995,7 @@ int console_parse_coords(char *txt, int *x, int *y, char *err)
{
// TODO: use regex?
int nx = -1, ny = -1;
- sscanf(txt,"%d,%d",&nx,&ny);
- if (nx<0 && nx>=XRES)
- {
- strcpy(err,"Invalid coordinates");
- return 0;
- }
- if (ny<0 && ny>=YRES)
+ if (sscanf(txt,"%d,%d",&nx,&ny)!=2 || nx<0 || nx>=XRES || ny<0 || ny>=YRES)
{
strcpy(err,"Invalid coordinates");
return 0;
@@ -4012,9 +4006,10 @@ int console_parse_coords(char *txt, int *x, int *y, char *err)
}
int console_parse_partref(char *txt, int *which, char *err)
{
+ strcpy(err,"");
// TODO: use regex?
int i = -1, nx, ny;
- if (console_parse_coords(txt, &nx, &ny, err))
+ if (strchr(txt,',') && console_parse_coords(txt, &nx, &ny, err))
{
i = pmap[ny][nx];
if (!i || (i>>8)>=NPART)
@@ -4025,7 +4020,6 @@ int console_parse_partref(char *txt, int *which, char *err)
else if (txt)
{
char *num = (char*)malloc(strlen(txt)+3);
- strcpy(err,""); // suppress error message from failed coordinate parsing
i = atoi(txt);
sprintf(num,"%d",i);
if (!txt || strcmp(txt,num)!=0)
@@ -4038,6 +4032,6 @@ int console_parse_partref(char *txt, int *which, char *err)
strcpy(err,"");
return 1;
}
- strcpy(err,"Particle does not exist");
+ if (strcmp(err,"")==0) strcpy(err,"Particle does not exist");
return 0;
}