/* Copyright (C) 1998-2003 XIAO, Gang of Universite de Nice - Sophia Antipolis
*
* 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 2 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, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* Subroutines to manipulate math expressions */
#include "libwims.h"
/* Points to the start of a mathematics variable (or number) */
char *find_mathvar_start(char *p)
{
int i;
for(i
=0;!isalnum(*p
) && *p
!='.' && *p
!=0 && i
<MAX_LINELEN
; p
++,i
++);
return p;
}
/* Points to the end of a mathematics variable (or number) */
char *find_mathvar_end(char *p)
{
int i; char *pp;
if(!isalnum(*p
) && *p
!='.') return p
;
for(i
=0; *p
!=0 && (isalnum(*p
) || *p
=='.' || *p
=='\'')
&& i<MAX_LINELEN;p++,i++);
return p;
}
else {
int t=0;
expon:
for(i
=0; (isdigit(*p
) || *p
=='.') && i
<MAX_LINELEN
;p
++,i
++);
pp=p; if(t) return pp;
if(*p=='e' || *p=='E'){
if((*p
=='-' || *p
=='+') && isdigit(*(p
+1))) {
p++; goto expon;
}
}
return pp;
}
}
/* list variable (function) names in an expression.
* buffer is modified to contain the list.
*/
void mathvarlist(char *p)
{
char buf[MAX_LINELEN+1], *pb, *pe, *pp;
char *l[10240];
int i,j,len, nofn=0;
pb=find_word_start(p);pe=find_word_end(pb);
nofn=1; pb=find_word_start(pe);
}
for(i=0,pb=buf;pb<buf+len;pb++) {
pb=find_mathvar_end(pb); continue;
}
pe=find_mathvar_end(pb); pp=find_word_start(pe);
if(nofn && *pp=='(') {
pb=pe; continue;
}
*pe=0;
if(i<10240) {
for(j
=0;j
<i
;j
++) if(strcmp(pb
,l
[j
])==0) goto nextp
;
l[i++]=pb;
}
nextp:
pb=pe;
}
for(*p=0,j=0;j<i;j++) {
}
}