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)  

variables.h
Go to the documentation of this file.
1 #ifndef KBW_VARIABLES
2 #define KBW_VARIABLES
3 
4 #ifdef HAVE_CONFIG_H
5 # include "config.h"
6 #endif
7 #if HAVE_STRING_H
8 # include <string.h>
9 #else
10 # if !HAVE_STRCHR
11 # define strchr index
12 # define strrchr rindex
13 # endif
14 char *strchr(), *strrchr();
15 #endif
16 #include <stdlib.h>
17 
18 #include "number.h"
19 
20 typedef struct variable {
21  char *key;
22  char *expression;
23  char *description;
25  unsigned int exp : 1;
26  struct variable *next;
27 } variable_t;
28 
29 typedef struct answer {
31  char *exp;
32  char *desc;
33  unsigned int err : 1;
34 } answer_t;
35 
36 // requires a working Number
37 void getvarval(Number out,
38  const char *key);
39 
40 // requires a working Number
41 int putval(const char *key,
42  const Number value,
43  const char *desc);
44 
45 int putexp(const char *key,
46  const char *value,
47  const char *desc);
48 int varexists(const char *key);
49 void initvar(void);
50 void delnvar(const size_t n);
51 void cleanupvar(void);
52 size_t numvars(void);
53 void printvariables(void);
54 
55 // this returns a char ** that must be freed. DO NOT free its contents
56 char **listvarnames(void);
57 
58 /* ******************************
59  * NOTE!
60  * If you use these functions, they return
61  * fully functioning Number structures that must be
62  * num_free()'d when you're done with 'em.
63  */
64 
65 /* getvar returns only the value, or an error if it doesn't have one */
66 struct answer getvar(const char *key);
67 
68 /* getvar returns whatever is known about the variable, or an error if
69  * it doesn't exist */
70 struct answer getvar_full(const char *key);
71 
72 /* THIS function, however, exposes the innards of the variable system.
73  * do not under any circumstance un-initialize the Number
74  */
75 struct variable *getrealnvar(const size_t n);
76 #endif // ifndef KBW_VARIABLES
77 /* vim:set expandtab: */
getvarval
void getvarval(mpfr_t out, const char *key)
answer::desc
char * desc
Definition: variables.h:32
putexp
int putexp(const char *key, const char *value, const char *desc)
Definition: variables.c:244
delnvar
void delnvar(const size_t n)
Definition: variables.c:111
strchr
#define strchr
Definition: variables.h:11
variable_t
struct variable variable_t
initvar
void initvar(void)
Definition: variables.c:29
listvarnames
char ** listvarnames(void)
Definition: variables.c:91
answer_t
struct answer answer_t
variable::exp
unsigned int exp
Definition: variables.h:25
numvars
size_t numvars(void)
Definition: variables.c:53
variable::description
char * description
Definition: variables.h:23
cleanupvar
void cleanupvar(void)
Definition: variables.c:34
answer
Definition: variables.h:29
Number
#define Number
Definition: number.h:23
printvariables
void printvariables(void)
Definition: variables.c:59
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
getrealnvar
struct variable * getrealnvar(const size_t n)
Definition: variables.c:127
varexists
int varexists(const char *key)
Definition: variables.c:184
variable::expression
char * expression
Definition: variables.h:22
variable::value
mpfr_t value
Definition: variables.h:24
variable
Definition: variables.h:20
answer::val
mpfr_t val
Definition: variables.h:30
variable::next
struct variable * next
Definition: variables.h:26
getvar
struct answer getvar(const char *key)
Definition: variables.c:132
strrchr
#define strrchr
Definition: variables.h:12
number.h
putval
int putval(const char *key, const mpfr_t value, const char *desc)
variable::key
char * key
Definition: variables.h:21