Graphviz 13.1.3~dev.20250813.2319
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
24static 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
37Expr_t*
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 exclose(program);
48 return 0;
49 }
50 program->id = "libexpr:expr";
51 program->disc = disc;
52 setcontext(program);
53 program->file[0] = stdin;
54 program->file[1] = stdout;
55 program->file[2] = stderr;
56 strcpy(program->main.name, "main");
57 program->main.lex = PROCEDURE;
58 program->main.index = PROCEDURE;
59 dtinsert(program->symbols, &program->main);
60 for (sym = exbuiltin; *sym->name; sym++)
61 dtinsert(program->symbols, sym);
62 if ((sym = disc->symbols))
63 for (; *sym->name; sym++)
64 dtinsert(program->symbols, sym);
65 return program;
66}
CDT_API Dtmethod_t * Dtset
set with unique elements
Definition dthash.c:277
#define dtinsert(d, o)
Definition cdt.h:185
CDT_API int dtclose(Dt_t *)
Definition dtclose.c:8
CDT_API Dt_t * dtopen(Dtdisc_t *, Dtmethod_t *)
Definition dtopen.c:9
Exid_t exbuiltin[]
Definition exdata.c:24
#define setcontext(p)
Definition exlib.h:128
static void free_exid(void *p)
destructor for Exid_t
Definition exopen.c:24
Expr_t * exopen(Exdisc_t *disc)
Definition exopen.c:38
#define PROCEDURE
Definition exparse.h:185
static Dtdisc_t disc
Definition exparse.y:209
void exclose(Expr_t *)
Definition expr.h:91
char name[EX_NAMELEN]
Definition expr.h:99
void * local
user defined local stuff
Definition expr.h:98
Definition expr.h:218
Dt_t * symbols
Definition expr.h:220
FILE * file[10]
Definition expr.h:221
const char * id
Definition expr.h:219
int key
Definition cdt.h:85