summaryrefslogtreecommitdiff
path: root/src/interface.c
diff options
context:
space:
mode:
authorSimon <simon@hardwired.org.uk>2011-02-04 10:24:35 (GMT)
committer Simon <simon@hardwired.org.uk>2011-02-04 10:24:35 (GMT)
commit9469a3b46a80970fc1d2a11df8c8692de90b6c00 (patch)
treeac8069712226ab150076c3af32cd2b1ab3a71d7b /src/interface.c
parent525a59e28011cf26993c8e3f040a36ba7b7bf5e2 (diff)
parent9064cabf288be8ecb2fbc1c15bb4071cf3df1c22 (diff)
downloadpowder-9469a3b46a80970fc1d2a11df8c8692de90b6c00.zip
powder-9469a3b46a80970fc1d2a11df8c8692de90b6c00.tar.gz
Merge with cracker, also fix version
Diffstat (limited to 'src/interface.c')
-rw-r--r--src/interface.c22
1 files changed, 7 insertions, 15 deletions
diff --git a/src/interface.c b/src/interface.c
index ab4fa3a..8b9a916 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;
}
}
@@ -3991,32 +3994,20 @@ int console_parse_type(char *txt, int *element, char *err)
int console_parse_coords(char *txt, int *x, int *y, char *err)
{
// TODO: use regex?
- char *coordtxt;
- char num[10] = "";
int nx = -1, ny = -1;
- txt = mystrdup(txt);
- coordtxt = strtok(txt, ",");
- if (coordtxt) nx = atoi(coordtxt);
- if (nx>=0 && nx<XRES) sprintf(num,"%d",nx);
- if (!coordtxt || strcmp(coordtxt, num)!=0)
+ sscanf(txt,"%d,%d",&nx,&ny);
+ if (nx<0 && nx>=XRES)
{
strcpy(err,"Invalid coordinates");
- free(txt);
return 0;
}
- strcpy(num,"");
- coordtxt = strtok(NULL, ",");
- if (coordtxt) ny = atoi(coordtxt);
- if (ny>=0 && ny<YRES) sprintf(num,"%d",ny);
- if (!coordtxt || strcmp(coordtxt, num)!=0)
+ if (ny<0 && ny>=YRES)
{
strcpy(err,"Invalid coordinates");
- free(txt);
return 0;
}
*x = nx;
*y = ny;
- free(txt);
return 1;
}
int console_parse_partref(char *txt, int *which, char *err)
@@ -4044,6 +4035,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");