Parser().
By SalimMeghani
- 254 reads
void parser(int *error, char *source, char *dest, int qol, int rw, int uniq)
{
int gloop=0;
int dloop=0;
int crloop=0, drloop=0;
int alloop=0;
int locx=0;
int locy=0;
int pvalue=0;
char cref[20];
char alpp[20];
char zalpp[20];
char num[20];
while (source[gloop]!='#')
{
while(isdigit(source[gloop]) || isstop(source[gloop]) || isoperator(source[gloop]) || isbracket(source[gloop]) || (source[gloop]=='E') || ( (gloop>=1) && isdigit(source[gloop-1]) && (source[gloop]=='e')))
{
dest[dloop]=source[gloop];
dloop++;
gloop++;
}
if (source[gloop]=='#') break;
crloop=0;
if (isalpha(source[gloop]))
{
do
{
cref[crloop]=source[gloop];
crloop++; gloop++;
}
while (isdigit(source[gloop])||isalpha(source[gloop]));
}
cref[crloop]='\0';
crloop=0;
alloop=0;
while(isalpha(cref[crloop]))
{
alpp[alloop]=cref[crloop];
crloop++;
alloop++;
}
alpp[alloop]='\0';
if (alloop==1)
locx=alpp[0]-96;
else
if (alloop==2)
locx=((alpp[0]-96)*26)+alpp[1]-96;
else
{
locx=0;
*error=1;
return;
}
if (uniq==0)
strcpy(zalpp,alpp);
alloop=0;
clr_str(alpp);
while (isdigit(cref[crloop]))
{
alpp[alloop]=cref[crloop];
crloop++;
alloop++;
}
alpp[alloop]='\0';
locy=atoi(alpp);
if ((locx<1)||(locx>100))
{
*error=1;
return;
}
if ((locy<1)||(locy>100))
{
*error=1;
return;
}
pvalue=(locx-1)*100+locy;
rtype=srtype+pvalue;
if (*rtype=='E')
{
*error=1;
return;
}
if ((locx==qol)&&(locy==rw))
{*error=1;
*rtype='E';
return;}
else *rtype='F';
pvalue=((locx-1)*100)+locy;
type=stype+pvalue;
rtype=srtype+pvalue;
if (*type=='N')
{
if (uniq==0)
{
strcat(dest, zalpp);
dloop+=strlen(zalpp);
}
if (uniq==0)
{
strcat(dest, alpp);
dloop+=strlen(alpp);
}
if (uniq==1)
{
numeric=snumeric+pvalue;
sprintf(num, "%e",*(*numeric));
strcat(dest,num);
dloop+=strlen(num);
}
}
clr_str(cref); clr_str(alpp);
if (*type=='F')
{
dest[dloop]='(';
dloop+=1;
cell=scell+pvalue;
strncat(dest,*cell,(strlen(*cell)-1));
dloop+=strlen(*cell)-1;
dest[dloop]=')';
dloop+=1;
fcat=1;
}
if (*type=='E'|| *type=='S')
{
*error=1;
return;
}
}
}
- Log in to post comments