File: variables.h

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 (75 lines) | stat: -rw-r--r-- 1,663 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
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
72
73
74
75
#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 "number.h"

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

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

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

// requires a working Number
int putval(const char *key, const Number value, const char *desc);

int putexp(const char *key, const char *value, const char *desc);
int varexists(const char *key);
void initvar(void);
void delnvar(const size_t n);
void cleanupvar(void);
size_t numvars();
void printvariables(void);

// this returns a char ** that must be freed. DO NOT free its contents
char ** listvarnames(void);

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

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

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

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

#endif