Graphviz
13.0.0~dev.20250210.0415
Loading...
Searching...
No Matches
exopen.c
Go to the documentation of this file.
1
/*************************************************************************
2
* Copyright (c) 2011 AT&T Intellectual Property
3
* All rights reserved. This program and the accompanying materials
4
* are made available under the terms of the Eclipse Public License v1.0
5
* which accompanies this distribution, and is available at
6
* https://www.eclipse.org/legal/epl-v10.html
7
*
8
* Contributors: Details at https://graphviz.org
9
*************************************************************************/
10
11
/*
12
* Glenn Fowler
13
* AT&T Research
14
*
15
* expression library
16
*/
17
18
#include <
expr/exlib.h
>
19
#include <stdlib.h>
20
#include <stdio.h>
21
#include <string.h>
22
24
static
void
free_exid
(
void
*p) {
25
Exid_t
*
const
exid = p;
26
27
// the `Exid_t` itself was allocated through the program’s `vm` allocator, so
28
// will be automatically deallocated, but we need to manually clean up the
29
// `local` set that is used for arrays
30
dtclose
(exid->
local
);
31
}
32
33
/*
34
* allocate a new expression program environment
35
*/
36
37
Expr_t
*
38
exopen
(
Exdisc_t
*
disc
)
39
{
40
Expr_t
* program;
41
Exid_t
* sym;
42
43
if
(!(program = calloc(1,
sizeof
(
Expr_t
))))
44
return
0;
45
static
Dtdisc_t
symdisc = {.
key
= offsetof(
Exid_t
, name), .freef =
free_exid
};
46
if
(!(program->
symbols
=
dtopen
(&symdisc,
Dtset
)) ||
47
!(program->
vm
=
vmopen
()) ||
48
!(program->ve =
vmopen
()))
49
{
50
exclose
(program);
51
return
0;
52
}
53
program->
id
=
"libexpr:expr"
;
54
program->disc =
disc
;
55
setcontext
(program);
56
program->
file
[0] = stdin;
57
program->
file
[1] = stdout;
58
program->
file
[2] = stderr;
59
strcpy(program->main.name,
"main"
);
60
program->main.lex =
PROCEDURE
;
61
program->main.index =
PROCEDURE
;
62
dtinsert
(program->
symbols
, &program->main);
63
for
(sym =
exbuiltin
; *sym->
name
; sym++)
64
dtinsert
(program->
symbols
, sym);
65
if
((sym =
disc
->symbols))
66
for
(; *sym->
name
; sym++)
67
dtinsert
(program->
symbols
, sym);
68
return
program;
69
}
Dtset
CDT_API Dtmethod_t * Dtset
set with unique elements
Definition
dthash.c:277
dtinsert
#define dtinsert(d, o)
Definition
cdt.h:185
dtclose
CDT_API int dtclose(Dt_t *)
Definition
dtclose.c:8
dtopen
CDT_API Dt_t * dtopen(Dtdisc_t *, Dtmethod_t *)
Definition
dtopen.c:9
exbuiltin
Exid_t exbuiltin[]
Definition
exdata.c:24
exlib.h
setcontext
#define setcontext(p)
Definition
exlib.h:127
free_exid
static void free_exid(void *p)
destructor for Exid_t
Definition
exopen.c:24
exopen
Expr_t * exopen(Exdisc_t *disc)
Definition
exopen.c:38
PROCEDURE
#define PROCEDURE
Definition
exparse.c:269
disc
static Dtdisc_t disc
Definition
exparse.y:207
exclose
void exclose(Expr_t *)
Exdisc_s
Definition
expr.h:167
Exid_s
Definition
expr.h:93
Exid_s::name
char name[EX_NAMELEN]
Definition
expr.h:101
Exid_s::local
void * local
user defined local stuff
Definition
expr.h:100
Expr_s
Definition
expr.h:198
Expr_s::symbols
Dt_t * symbols
Definition
expr.h:200
Expr_s::file
FILE * file[10]
Definition
expr.h:201
Expr_s::vm
Vmalloc_t * vm
Definition
expr.h:202
Expr_s::id
const char * id
Definition
expr.h:199
dtdisc_s_
Definition
cdt.h:85
dtdisc_s_::key
int key
Definition
cdt.h:85
vmopen
Vmalloc_t * vmopen(void)
Definition
vmopen.c:18
lib
expr
exopen.c
Generated by
1.9.8