-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.c
More file actions
118 lines (106 loc) · 3.13 KB
/
init.c
File metadata and controls
118 lines (106 loc) · 3.13 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include <math.h>
#include "post.h"
#include "y.tab.h"
extern DATUM * Mag(), *Pha(), *Re(), *Im();
extern void symprint();
/* keywords */
static struct {
char *name;
int kval;
} keywords[] = {
{"i", I}, /* sqrt(-1) */
{"I", I}, /* sqrt(-1) */
{"gr", GR}, /* graphnew */
{"gs", GS}, /* graphsame */
{"ci", CI}, /* load in a rawfile */
{"di", DI}, /* display loaded sig names */
{"ls", LS}, /* list loadable rawfiles in cwd */
{"pr", PR}, /* print variable */
{"print", PR}, /* print variable */
{"xl", XL}, /* xlimit */
{"logx", LX}, /* use log for x axis */
{"logf", LX}, /* use log for freq axis */
{"yl", YL}, /* ylimit */
{"vs", VS}, /* plot versus another variable */
{"quit", QUIT}, /* quit */
{"exit", QUIT}, /* quit */
{"bye" , QUIT}, /* quit */
{0, 0}
};
/*
{"func", FUNC},
{"return", RETURN},
{"if", IF},
{"else", ELSE},
{"while", WHILE},
{"read", READ},
*/
static struct { /* constants */
char *name;
double re;
double im;
} consts[] = {
{"BOLTZ", 1.3806226e-23,0.0}, /* boltzmans constant */
{"CHARGE", 1.6021918e-19,0.0}, /* electron charge */
{"KELVIN", 273.15,0.0}, /* centigrade to absolute */
{"DEG", 57.29577951308232087680,0.0},/* deg/radian */
{"DT", 1e-6,0.0}, /* default integration delta */
{"E", 2.71828182845904523536,0.0},
{"EPS0", 8.854214871e-12,0.0}, /* vacuum permittivity */
{"GAMMA", 0.57721566490153286060,0.0}, /* Euler */
{"PHI", 1.61803398874989484820,0.0}, /* golden ratio */
{"PI", 3.14159265358979323846,0.0},
{0, 0.0, 0.0}
};
// need sin() cos() atan() int() abs() conj()
static struct { /* built-ins */
char *name;
DATUM *(*func)();
} builtins[] = {
{"avg", Avg}, /* binop */
{"db", Db},
{"cos", Cos},
{"dt", dt},
{"exp", Exp},
{"greater", Greater},
{"lpf", lpf},
{"im", Im},
{"integral", Integral},
{"pha", Pha},
{"less", Less},
{"ln", Ln},
{"log10", Log10},
{"log", Log10},
{"re", Re},
{"mag", Mag}, /* binop */
{"mod", Mod}, /* binop */
{"min", Min}, /* binop */
{"max", Max}, /* binop */
{"pause", dopause},
{"pow", Pow}, /* binop */
{"sin", Sin},
{"sqrt", Sqrt}, /* binop */
{"warp", Warp}, /* binop */
{"versus", Versus}, /* binop */
{"delay", Warp}, /* binop */
{"ui", ui},
{"xcross", xcross}, /* binop */
{"xcrossn", xcrossn}, /* binop */
{"xcrossp", xcrossp}, /* binop */
{0, 0}
};
void init() /* install constants and built-ins in table */
{
int i;
Symbol *s;
for (i=0; keywords[i].name; i++) {
install(keywords[i].name, keywords[i].kval, 0.0);
}
for (i=0; builtins[i].name; i++) {
s = install(builtins[i].name, BLTIN, NULL);
s->u.ptr = builtins[i].func;
}
for (i=0; consts[i].name; i++) {
install(consts[i].name, VAR, new_dat(consts[i].re, consts[i].im));
}
}