File: variables.h

package info (click to toggle)
wcalc 2.2.2-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 2,228 kB
  • ctags: 698
  • sloc: ansic: 6,918; objc: 1,835; sh: 766; yacc: 644; lex: 573; makefile: 78
file content (71 lines) | stat: -rw-r--r-- 1,482 bytes parent folder | download
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#ifndef KBW_VARIABLES
#define KBW_VARIABLES

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#if HAVE_STRING_H
# include <string.h>
#else
# if !HAVE_STRCHR
#  define strchr index
#  define strrchr rindex
# endif
char *strchr(), *strrchr();
#endif
#include <stdlib.h>
#include <stdio.h>

#include <gmp.h>
#include <mpfr.h>

struct variable
{
    char *key;
    char *expression;
    char *description;
    mpfr_t value;
    unsigned int exp:1;
    struct variable *next;
};

struct answer
{
    mpfr_t val;
    char *exp;
    char *desc;
    unsigned int err:1;
};

// requires a working mpfr_t
void getvarval(mpfr_t out, char *key);

// requires a working mpfr_t (duh)
int putval(char *key, mpfr_t value, char *desc);
int putexp(char *key, char *value, char *desc);
int varexists(char *key);
void initvar(void);
void delnvar(size_t);
void cleanupvar(void);
size_t numvars();

/* ******************************
 * NOTE!
 * If you use these functions, they return
 * fully functioning mpfr_t structures that must be
 * mpfr_clear()'d when you're done with 'em.
 */

/* getvar returns only the value, or an error if it doesn't have one */
struct answer getvar(char *key);

/* getvar returns whatever is known about the variable, or an error if
 * it doesn't exist */
struct answer getvar_full(char *key);

/* THIS function, however, exposes the innards of the variable system.
 * do not under any circumstance un-initialize the mpfr_t
 */
struct variable *getrealnvar(size_t);

#endif