/**
* Powder Toy - simple console
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
#include
#include
#include
#ifdef PYCONSOLE
#include
#endif
char console_more=0;
char console_error[255] = "";
int file_script = 0;
//takes a a string and compares it to element names, and puts it value into element.
int console_parse_type(char *txt, int *element, char *err)
{
int i = -1;
// alternative names for some elements
if (strcasecmp(txt,"C4")==0) i = PT_PLEX;
else if (strcasecmp(txt,"C5")==0) i = PT_C5;
else if (strcasecmp(txt,"NONE")==0) i = PT_NONE;
if (i>=0 && i=XRES || ny<0 || ny>=YRES)
{
if (err) strcpy(err,"Invalid coordinates");
return 0;
}
*x = nx;
*y = ny;
return 1;
}
//takes a string of either coords or a particle number, and puts the particle number into *which
int console_parse_partref(char *txt, int *which, char *err)
{
int i = -1, nx, ny;
if (err) strcpy(err,"");
if (strchr(txt,',') && console_parse_coords(txt, &nx, &ny, err))
{
i = pmap[ny][nx];
if (!i)
i = -1;
else
i = i>>8;
}
else if (txt)
{
char *num = (char*)malloc(strlen(txt)+3);
i = atoi(txt);
sprintf(num,"%d",i);
if (!txt || strcmp(txt,num)!=0)
i = -1;
free(num);
}
if (i>=0 && i