wcalc  2.5
About: Wcalc is a natural-expression command-line calculator.
  Fossies Dox: wcalc-2.5.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

evalvar.c
Go to the documentation of this file.
1 #ifdef HAVE_CONFIG_H
2 # include "config.h"
3 #endif
4 
5 /* Internal Headers */
6 #include "number.h"
7 #include "variables.h"
8 #include "calculator.h"
9 #include "number_formatting.h"
10 
11 /* My Prototype */
12 #include "evalvar.h"
13 
14 char *evalvar(const char *varname)
15 {
16  struct answer a;
17  char junk;
18  Number f;
19 
20  a = getvar_full(varname);
21  if (!a.err) {
22  num_init(f);
23  if (a.exp) { // it is an expression
24  parseme(a.exp);
25  num_set(f, last_answer);
26  } else { // it is a value
27  num_set(f, a.val);
28  num_free(a.val);
29  }
30  char *varvalue = num_to_str_complex(f, 10, 0, -1, 1, &junk);
31  num_free(f);
32  return varvalue;
33  } else {
34  return NULL;
35  }
36 }
37 
38 char *evalvar_noparse(const char *varname)
39 {
40  struct answer a;
41  char junk;
42  Number f;
43 
44  a = getvar_full(varname);
45  if (!a.err) {
46  if (a.exp) { // it is an expression
47  return strdup(a.exp);
48  }
49  // it is a value
50  num_init_set(f, a.val);
51  num_free(a.val);
52  char *varvalue = num_to_str_complex(f, 10, 0, -1, 1, &junk);
53  num_free(f);
54  return varvalue;
55  } else {
56  return NULL;
57  }
58 }
59 
60 /* vim:set expandtab: */
num_init_set
void num_init_set(Number n1, const Number n2)
Definition: number.c:74
calculator.h
parseme
void parseme(const char *pthis)
Definition: calculator.c:130
variables.h
number_formatting.h
answer
Definition: variables.h:29
num_init
void num_init(Number n)
Definition: number.c:69
Number
#define Number
Definition: number.h:23
evalvar.h
num_set
void num_set(Number n1, const Number n2)
Definition: number.c:105
getvar_full
struct answer getvar_full(const char *key)
Definition: variables.c:160
answer::err
unsigned int err
Definition: variables.h:33
answer::exp
char * exp
Definition: variables.h:31
last_answer
Number last_answer
Definition: calculator.c:98
num_free
void num_free(Number n)
Definition: number.c:738
evalvar_noparse
char * evalvar_noparse(const char *varname)
Definition: evalvar.c:38
num_to_str_complex
char * num_to_str_complex(const mpfr_t num, const int base, const enum engineering_modes engr, const int prec, const int prefix, char *truncated_flag)
answer::val
mpfr_t val
Definition: variables.h:30
number.h
evalvar
char * evalvar(const char *varname)
Definition: evalvar.c:14