Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/lib/libdss/dssmisc.c
1808 views
1
/***********************************************************************
2
* *
3
* This software is part of the ast package *
4
* Copyright (c) 2002-2011 AT&T Intellectual Property *
5
* and is licensed under the *
6
* Eclipse Public License, Version 1.0 *
7
* by AT&T Intellectual Property *
8
* *
9
* A copy of the License is available at *
10
* http://www.eclipse.org/org/documents/epl-v10.html *
11
* (with md5 checksum b35adb5213ca9657e911e9befb180842) *
12
* *
13
* Information and Software Systems Research *
14
* AT&T Research *
15
* Florham Park NJ *
16
* *
17
* Glenn Fowler <[email protected]> *
18
* *
19
***********************************************************************/
20
#pragma prototyped
21
/*
22
* dss misc support
23
*/
24
25
#include "dsshdr.h"
26
27
/*
28
* compile an expression
29
* input is from string s or stream sp if s==0
30
*/
31
32
Dssexpr_t*
33
dsscomp(Dss_t* dss, const char* s, Sfio_t* sp)
34
{
35
Cxexpr_t* expr;
36
char* file;
37
void* pop;
38
39
if (!sp && s && *s == '<')
40
{
41
while (isspace(*++s));
42
if (!(sp = sfopen(NiL, s, "r")))
43
{
44
if (dss->disc->errorf)
45
(*dss->disc->errorf)(dss, dss->disc, 2, "%s: cannot read expression file", s);
46
return 0;
47
}
48
file = (char*)s;
49
s = 0;
50
}
51
else
52
file = 0;
53
if (!(pop = cxpush(dss->cx, file, sp, s, -1, CX_INCLUDE)))
54
return 0;
55
expr = cxcomp(dss->cx);
56
cxpop(dss->cx, pop);
57
return expr;
58
}
59
60
/*
61
* called once before the first dsseval(expr)
62
*/
63
64
int
65
dssbeg(Dss_t* dss, Dssexpr_t* expr)
66
{
67
return cxbeg(dss->cx, expr, dss->meth->name);
68
}
69
70
/*
71
* evaluate expr
72
*/
73
74
int
75
dsseval(Dss_t* dss, Dssexpr_t* expr, Dssrecord_t* record)
76
{
77
Cxoperand_t cv;
78
79
if (!expr->begun && dssbeg(dss, expr))
80
return -1;
81
return cxeval(dss->cx, expr, record, &cv);
82
}
83
84
/*
85
* called once after the last dsseval(expr)
86
* there can be multiple dssbeg ... dsseval ... dssend sequences
87
*/
88
89
int
90
dssend(Dss_t* dss, Dssexpr_t* expr)
91
{
92
return cxend(dss->cx, expr);
93
}
94
95
/*
96
* list expr
97
*/
98
99
int
100
dsslist(Dss_t* dss, Dssexpr_t* expr, Sfio_t* sp)
101
{
102
return cxlist(dss->cx, expr, sp);
103
}
104
105
/*
106
* free expr
107
*/
108
109
int
110
dssfree(Dss_t* dss, Dssexpr_t* expr)
111
{
112
return cxfree(dss->cx, expr);
113
}
114
115
/*
116
* return variable value in value
117
* type!=0 casts to type, variable->type by default
118
* details!=0 is optional type format details
119
*/
120
121
int
122
dssget(Dssrecord_t* record, Dssvariable_t* variable, Dsstype_t* type, const char* details, Dssvalue_t* value)
123
{
124
Cxoperand_t ret;
125
126
if (cxcast(record->file->dss->cx, &ret, variable, type, record, details))
127
return -1;
128
*value = ret.value;
129
return 0;
130
}
131
132
/*
133
* return type pointer given name
134
*/
135
136
Dsstype_t*
137
dsstype(Dss_t* dss, const char* name)
138
{
139
return cxtype(dss->cx, name, dss->disc);
140
}
141
142
/*
143
* return variable pointer given name
144
*/
145
146
Dssvariable_t*
147
dssvariable(Dss_t* dss, const char* name)
148
{
149
return cxvariable(dss->cx, name, NiL, dss->disc);
150
}
151
152