File: evalvar.c

package info (click to toggle)
wcalc 2.3.1-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 2,444 kB
  • ctags: 926
  • sloc: ansic: 8,993; objc: 1,946; lex: 798; sh: 766; yacc: 623; makefile: 79
file content (31 lines) | stat: -rw-r--r-- 608 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include "number.h"
#include "variables.h"
#include "calculator.h"
#include "number_formatting.h"
#ifdef MEMWATCH
#include "memwatch.h"
#endif

char *evalvar(const char *varname)
{
    struct answer a;
    char *varvalue, junk;
    Number f;

    a = getvar_full(varname);
    if (!a.err) {
	num_init(f);
	if (a.exp) {		       // it is an expression
	    parseme(a.exp);
	    num_set(f, last_answer);
	} else {		       // it is a value
	    num_set(f, a.val);
	    num_free(a.val);
	}
	varvalue = num_to_str_complex(f, 10, 0, -1, 1, &junk);
	num_free(f);
	return varvalue;
    } else {
	return NULL;
    }
}