-
Notifications
You must be signed in to change notification settings - Fork 1
/
dot-wasm.c
53 lines (39 loc) · 1.15 KB
/
dot-wasm.c
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
// Mostly taken from https://github.com/mdaines/viz.js
#include <gvc.h>
#include <emscripten.h>
extern gvplugin_library_t gvplugin_core_LTX_library;
extern gvplugin_library_t gvplugin_dot_layout_LTX_library;
char *errorMessage = NULL;
int vizErrorf(char *buf) {
errorMessage = buf;
return 0;
}
EMSCRIPTEN_KEEPALIVE char* graphvizLastErrorMessage() {
return errorMessage;
}
EMSCRIPTEN_KEEPALIVE char* graphvizRenderFromString(const char *src, const char *format, const char *engine) {
errorMessage = NULL;
GVC_t *context;
Agraph_t *graph;
char *result = NULL;
unsigned int length;
context = gvContext();
gvAddLibrary(context, &gvplugin_core_LTX_library);
gvAddLibrary(context, &gvplugin_dot_layout_LTX_library);
agseterr(AGERR);
agseterrf(vizErrorf);
agreadline(1);
while ((graph = agmemread(src))) {
if (result == NULL) {
gvLayout(context, graph, engine);
gvRenderData(context, graph, format, &result, &length);
gvFreeLayout(context, graph);
}
agclose(graph);
src = "";
}
return result;
}
EMSCRIPTEN_KEEPALIVE void freeStringRenderString(char* data) {
gvFreeRenderData(data);
}