Beispiel #1
0
//takes a string of either coords or a particle number, and puts the particle number into *which
int console_parse_partref(const 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;*/
		// TODO: fix
		i = -1;
	}
	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<NPART && parts[i].type)
	{
		*which = i;
		if (err) strcpy(err,"");
		return 1;
	}
	if (err && strcmp(err,"")==0) strcpy(err,"Particle does not exist");
	return 0;
}
Beispiel #2
0
//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;
    }
Beispiel #3
0
int process_command_old(pixel *vid_buf, char *console, char *console_error)
{
	int y,x,nx,ny,i,j,k,m;
	float f;
	int do_next = 1;
	char xcoord[10] = "";
	char ycoord[10] = "";
	char console2[15] = "";
	char console3[15] = "";
	char console4[15] = "";
	char console5[15] = "";
	//sprintf(console_error, "%s", console);
	if (console && strcmp(console, "")!=0 && strncmp(console, " ", 1)!=0)
	{
		sscanf(console,"%14s %14s %14s %14s", console2, console3, console4, console5);//why didn't i know about this function?!
		if (strcmp(console2, "quit")==0)
		{
			return -1;
		}
		else if (strcmp(console2, "file")==0 && console3[0])
		{
			if (file_script) {
				int filesize;
				char *fileread = (char*)file_load(console3, &filesize);
				nx = 0;
				ny = 0;
				if (console4[0] && !console_parse_coords(console4, &nx , &ny, console_error))
				{
					free(fileread);
					return 1;
				}
				if (fileread)
				{
					char pch[501];
					char tokens[31];
					int tokensize;
					j = 0; // line start position in fileread
					m = 0; // token start position in fileread
					memset(pch,0,sizeof(pch));
					for (i=0; i<filesize; i++)
					{
						if (fileread[i] != '\n' && i-m<30)
						{
							pch[i-j] = fileread[i];
							if (fileread[i] != ' ')
								tokens[i-m] = fileread[i];
						}
						if ((fileread[i] == ' ' || fileread[i] == '\n') && i-j<400)
						{
							std::regex coordReg(R"(^x.?[0-9]*,y.?[0-9]*)");
							if (std::regex_search(tokens, coordReg))
							{
								int starty = 0;
								tokensize = strlen(tokens);
								x = 0;
								y = 0;
								if (tokens[1]!=',')
									sscanf(tokens,"x%d,y%d",&x,&y);
								else
									sscanf(tokens,"x,y%d",&y);
								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_old(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;
						}
					}
					free(fileread);
				}
				else
				{