Add initial support for python bindings
[alexxy/gromacs.git] / cmake / TestVMD.c
1 #include "molfile_plugin.h"
2 #include "vmddlopen.c"
3 #include "stdio.h"
4
5 static int register_cb(void *v, vmdplugin_t *p) {
6     *(molfile_plugin_t**)v = (molfile_plugin_t *)p;
7     return VMDPLUGIN_SUCCESS;
8 }
9
10 typedef int (*initfunc)(void);
11 typedef int (*regfunc)(void *, vmdplugin_register_cb);
12
13 /*run: gcc TestVMD.c -DGMX_USE_PLUGINS -Wall -ldl src/gmxlib/vmddlopen.c -I src/gmxlib && ./a.out .../xyzplugin.so ; echo $?*/
14 int main(int argc, char** argv)
15 {
16     void *handle, *ifunc, *registerfunc;
17     molfile_plugin_t* api;
18     if (argc!=2) return -1;
19     handle = vmddlopen(argv[1]);
20     if (!handle)
21     {
22         fprintf(stderr,"%s\n",vmddlerror());
23         return 1;
24     }
25     ifunc = vmddlsym(handle, "vmdplugin_init");
26     if (!ifunc || ((initfunc)(ifunc))()) return 2;
27     registerfunc = vmddlsym(handle, "vmdplugin_register");
28     if (!registerfunc) return 3;
29     ((regfunc)registerfunc)(&api, register_cb);
30     if (!api) return 4;
31     if (api->abiversion<10) return 5;
32     return 0;
33 }