summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjacksonmj <jacksonmj@jacksonmj.none>2011-01-31 02:42:34 (GMT)
committer jacksonmj <jacksonmj@jacksonmj.none>2011-01-31 02:42:34 (GMT)
commitcdd7399cc1c009838970ab5dce60c5ad4c332d46 (patch)
treec0db98fec2d034f5eb949b3bdc123039be8ebe1f /src
parentf85ef31b1f9b643e04a5e4614a26dd27332ced19 (diff)
downloadpowder-cdd7399cc1c009838970ab5dce60c5ad4c332d46.zip
powder-cdd7399cc1c009838970ab5dce60c5ad4c332d46.tar.gz
Make console recognise element names
Diffstat (limited to 'src')
-rw-r--r--src/interface.c16
-rw-r--r--src/main.c49
2 files changed, 48 insertions, 17 deletions
diff --git a/src/interface.c b/src/interface.c
index 7975278..221f2d5 100644
--- a/src/interface.c
+++ b/src/interface.c
@@ -3927,3 +3927,19 @@ char *console_ui(pixel *vid_buf,char error[255]) { //TODO: error messages, show
}
+int console_get_type(char *element)
+{
+ int i;
+ char num[4];
+ i = atoi(element);
+ sprintf(num,"%d",i);
+ if (i>=0 && i<PT_NUM && strcmp(element,num)==0)
+ return i;
+ if (strcasecmp(element,"C4")==0) return PT_PLEX;
+ if (strcasecmp(element,"C5")==0) return PT_C5;
+ for (i=0; i<PT_NUM; i++) {
+ if (strcasecmp(element,ptypes[i].name)==0)
+ return i;
+ }
+ return -1;
+}
diff --git a/src/main.c b/src/main.c
index 5b0f124..ea3ba71 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1783,7 +1783,8 @@ int main(int argc, char *argv[])
if(parts[i].type)
parts[i].life = j;
}
- } else
+ }
+ else
{
i = atoi(console4);
if(parts[i].type)
@@ -1797,19 +1798,26 @@ int main(int argc, char *argv[])
{
if(strcmp(console4, "all")==0)
{
- j = atoi(console5);
- for(i=0; i<NPART; i++)
- {
- if(parts[i].type)
- parts[i].type = j;
- }
- } else
+ j = console_get_type(console5);
+ if (j<0)
+ sprintf(error, "Particle type not recognised", console2);
+ else
+ for(i=0; i<NPART; i++)
+ {
+ if(parts[i].type)
+ parts[i].type = j;
+ }
+ }
+ else
{
i = atoi(console4);
if(parts[i].type)
{
- j = atoi(console5);
- parts[i].type = j;
+ j = console_get_type(console5);
+ if (j<0)
+ sprintf(error, "Particle type not recognised", console2);
+ else
+ parts[i].type = j;
}
}
}
@@ -1823,7 +1831,8 @@ int main(int argc, char *argv[])
if(parts[i].type)
parts[i].temp = j;
}
- } else
+ }
+ else
{
i = atoi(console4);
if(parts[i].type)
@@ -1843,7 +1852,8 @@ int main(int argc, char *argv[])
if(parts[i].type)
parts[i].tmp = j;
}
- } else
+ }
+ else
{
i = atoi(console4);
if(parts[i].type)
@@ -1863,7 +1873,8 @@ int main(int argc, char *argv[])
if(parts[i].type)
parts[i].x = j;
}
- } else
+ }
+ else
{
i = atoi(console4);
if(parts[i].type)
@@ -1883,7 +1894,8 @@ int main(int argc, char *argv[])
if(parts[i].type)
parts[i].y = j;
}
- } else
+ }
+ else
{
i = atoi(console4);
if(parts[i].type)
@@ -1903,7 +1915,8 @@ int main(int argc, char *argv[])
if(parts[i].type)
parts[i].ctype = j;
}
- } else
+ }
+ else
{
i = atoi(console4);
if(parts[i].type)
@@ -1923,7 +1936,8 @@ int main(int argc, char *argv[])
if(parts[i].type)
parts[i].vx = j;
}
- } else
+ }
+ else
{
i = atoi(console4);
if(parts[i].type)
@@ -1943,7 +1957,8 @@ int main(int argc, char *argv[])
if(parts[i].type)
parts[i].vy = j;
}
- } else
+ }
+ else
{
i = atoi(console4);
if(parts[i].type)