Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Lifeware
biocham
Commits
00c76b07
Commit
00c76b07
authored
Oct 21, 2015
by
Thierry Martinez
Browse files
Graphviz
parent
e94dad9d
Changes
5
Hide whitespace changes
Inline
Side-by-side
Makefile
View file @
00c76b07
...
...
@@ -2,9 +2,9 @@ MODULES=$(shell sed -n -E 's/^- (.*\.pl)$$/\1/p' toc.org)
# load_test_files/1 should make this useless, but I cannot find how to use it
TEST_MODULES
=
$(
wildcard
$(MODULES:.pl=.plt)
)
all
:
biocham biocham_debug test
s
doc
all
:
biocham biocham_debug test doc
.PHONY
:
test
s
doc clean
.PHONY
:
test doc clean
biocham
:
$(MODULES) toc.org Makefile
@
echo
$(MODULES)
...
...
@@ -13,7 +13,7 @@ biocham: $(MODULES) toc.org Makefile
biocham_debug
:
$(MODULES) $(TEST_MODULES) toc.org Makefile
swipl
-o
biocham_debug
--goal
=
initialize
-c
$(MODULES)
$(TEST_MODULES)
test
s
:
biocham_tests
test
:
biocham_tests
./biocham_tests
doc
:
biocham
...
...
modules/graphviz/Makefile
0 → 100644
View file @
00c76b07
CC
=
swipl-ld
LDFLAGS
=
-shared
all
:
graphviz_swiprolog test
.PHONY
:
clean test
clean
:
rm
-f
graphviz_swiprolog graphviz_swiprolog.so graphviz_swiprolog.o
graphviz_swiprolog
:
graphviz_swiprolog.o
swipl-ld
-shared
-o
graphviz_swiprolog graphviz_swiprolog.o
mv
graphviz_swiprolog.so graphviz_swiprolog
graphviz_swiprolog.o
:
graphviz_swiprolog.c
test
:
swipl
-g
"
\
call_cleanup((['graphviz.plt'], run_tests, halt(0)), halt(1))
\
"
modules/graphviz/graphviz.pl
0 → 100644
View file @
00c76b07
:-
module
(
graphviz
,
[
agclose
/
1
,
agread
/
2
,
gvFreeLayout
/
1
,
gvLayout
/
2
,
gvRender
/
3
]
).
:-
use_foreign_library
(
foreign
(
graphviz_swiprolog
)).
modules/graphviz/graphviz.plt
0 → 100644
View file @
00c76b07
:- use_module(library(plunit)).
:- use_module(graphviz).
:- begin_tests(graphviz).
test(say_hello) :-
say_hello('Hello world.').
:- end_tests(graphviz).
modules/graphviz/graphviz_swiprolog.c
View file @
00c76b07
#include <stdio.h>
#include <SWI-Prolog.h>
#include <gvc.h>
GVC_t
*
gvc
;
static
foreign_t
pl_agclose
(
term_t
graph_term
)
{
Agraph_t
*
graph
;
if
(
!
PL_get_pointer
(
graph_term
,
&
graph
))
{
PL_fail
;
}
agclose
(
graph
);
PL_succeed
;
}
static
foreign_t
pl_agread
(
term_t
filename_term
,
term_t
graph_term
)
{
char
*
filename
;
FILE
*
file
;
Agraph_t
*
graph
;
if
(
!
PL_get_atom_chars
(
filename_term
,
&
filename
))
{
PL_fail
;
}
file
=
fopen
(
filename
,
"r"
);
graph
=
agread
(
file
);
fclose
(
file
);
if
(
!
PL_put_pointer
(
graph_term
,
graph
))
{
agclose
(
graph
);
PL_fail
;
}
PL_succeed
;
}
static
foreign_t
pl_say_hello
(
term_t
to
)
{
char
*
a
;
pl_gvFreeLayout
(
term_t
graph_term
)
{
Agraph_t
*
graph
;
if
(
!
PL_get_pointer
(
graph_term
,
&
graph
))
{
PL_fail
;
}
gvFreeLayout
(
gvc
,
graph
);
PL_succeed
;
}
if
(
PL_get_atom_chars
(
to
,
&
a
))
{
PL_succeed
;
static
foreign_t
pl_gvLayout
(
term_t
graph_term
,
term_t
engine_term
)
{
Agraph_t
*
graph
;
char
*
engine
;
if
(
!
PL_get_pointer
(
graph_term
,
&
graph
))
{
PL_fail
;
}
if
(
!
PL_get_atom_chars
(
engine_term
,
&
engine
))
{
PL_fail
;
}
gvLayout
(
gvc
,
graph
,
engine
);
PL_succeed
;
}
PL_fail
;
static
foreign_t
pl_gvRender
(
term_t
graph_term
,
term_t
format_term
,
term_t
filename
)
{
Agraph_t
*
graph
;
char
*
format
;
FILE
*
file
;
if
(
!
PL_get_pointer
(
graph_term
,
&
graph
))
{
PL_fail
;
}
if
(
!
PL_get_atom_chars
(
format_term
,
&
format
))
{
PL_fail
;
}
if
(
!
PL_get_atom_chars
(
filename_term
,
&
filename
))
{
PL_fail
;
}
file
=
fopen
(
filename
,
"w"
);
gvRender
(
gvc
,
graph
,
format
,
file
);
PL_succeed
;
}
install_t
install_mylib
()
{
PL_register_foreign
(
"say_hello"
,
1
,
pl_say_hello
,
0
);
install_graphviz_swiprolog
()
{
gvc
=
gvContext
();
PL_register_foreign
(
"agclose"
,
1
,
pl_agclose
,
0
);
PL_register_foreign
(
"agread"
,
2
,
pl_agread
,
0
);
PL_register_foreign
(
"gvFreeLayout"
,
1
,
pl_gvFreeLayout
,
0
);
PL_register_foreign
(
"gvLayout"
,
2
,
pl_gvLayout
,
0
);
PL_register_foreign
(
"gvRender"
,
3
,
pl_gvRender
,
0
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment