/*
  parse_number(char *str, float *value);

*/

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include "dm.h"
#include "functionlib.h"

char *parse_number(char *tree, float *value)
{
    char	*p, *t, *c;
    int		valid;
    float	tmp;
    int		integer_part,
		fraction_part;

    char	integer_str[500],
		fraction_str[500];



    p= tree;
    /* scan for [ */
    if ( (p= strchr(p, '[')) ) {
        if ( !(p= strchr(p, '.')) ) return( (char *)0 );
	p++;
    }
    else p= tree;

    valid= 1;

    /* extract integer part */
    t= p;
    for(  ; *p; p++ ) if( !scmp("POINT", p) ) break;
    for( c= integer_str; t<p; t++) *c++= *t;
    *c= 0;
    if( !parse_int( integer_str, &integer_part) ) integer_part= 0;
    for( ; *t && (*t != ' '); t++);
    if( !*t ) fraction_part= 0;
    else {
        for( c= fraction_str; *t; t++) *c++= *t;
	*c= 0;
        if( !parse_int( fraction_str, &fraction_part) ) fraction_part= 0;
    }


    tmp= (float) integer_part + ( (float) fraction_part) / 10.0;
    *value= tmp;
    if( valid ) return(p);
    else return( (char *)0);
}
