Back to index

wims  3.65+svn20090927
evalue.c
Go to the documentation of this file.
00001 /*    Copyright (C) 1998-2003 XIAO, Gang of Universite de Nice - Sophia Antipolis
00002  *
00003  *  This program is free software; you can redistribute it and/or modify
00004  *  it under the terms of the GNU General Public License as published by
00005  *  the Free Software Foundation; either version 2 of the License, or
00006  *  (at your option) any later version.
00007  *
00008  *  This program is distributed in the hope that it will be useful,
00009  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00010  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011  *  GNU General Public License for more details.
00012  *
00013  *  You should have received a copy of the GNU General Public License
00014  *  along with this program; if not, write to the Free Software
00015  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00016  */
00017 
00018        /* It is this routine which uses print_precision. */
00019 void float2str(double d, char *p)
00020 {
00021     char buf[64], *pp;
00022     int i;
00023     if(d==0) {
00024        strcpy(p,"0"); return;
00025     }
00026     i=10; /* simple precision cookup */
00027     snprintf(buf,sizeof(buf),"%%.%dg",i);
00028     snprintf(p,MAX_LINELEN,buf,(double) d);
00029     pp=p;while(isspace(*pp)) pp++;
00030     if(pp>p) strcpy(p,pp);
00031 }
00032 
00033        /* substitute variable names by their environment strings
00034         * The buffer pointed to by p must have enough space
00035         * (defined by MAX_LINELEN). */
00036 char *substit(char *p)
00037 {
00038     char *pp, *pe;
00039     char namebuf[MAX_NAMELEN+1];
00040     int i, l;
00041 
00042     pe=strchr(p,'"'); if(pe!=NULL) l=pe-p; else l=MAX_LINELEN;
00043     for(pp=find_name_start(p); *pp!=0 && pp-p<l;
00044        pp=find_name_start(pe)) {
00045        pe=find_name_end(pp);
00046        if((pp>p && !isspace(*(pp-1)) && *(pp-1)!=',') ||
00047           (*pe!=0 && !isspace(*pe) && *pe!=',')) continue;
00048        memmove(namebuf,pp,pe-pp); namebuf[pe-pp]=0;
00049        i=search_list(nametab,nametab_no,sizeof(nametab[0]),namebuf);
00050        if(i<0) continue;
00051        if(nametab[i].type==t_prep && preptab[nametab[i].serial].typ==p_font) 
00052          break;
00053        if(nametab[i].type==t_color) 
00054          string_modify(p,pp,pe,colortab[nametab[i].serial].def);
00055     }
00056     return p;
00057 }
00058 
00059 double evalue(char *p)
00060 {
00061     return strevalue(p);
00062 }
00063