-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugin.c
72 lines (51 loc) · 1.22 KB
/
plugin.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <dlfcn.h>
#include <string.h>
#include <math.h>
#include "rpsc.h"
#include "Parser.h"
#include "Lexer.h"
#include "sheet.h"
static struct plugin *plug_ins;
void init_plugin()
{
plug_ins=0;
}
int load_plugin(char *name)
{
void *handle;
struct plugin *new;
int (*init_p)(struct plugin *);
char f_name[255];
sprintf(f_name,"./%s.so",name);
handle = dlopen(f_name, RTLD_GLOBAL| RTLD_LAZY );
if (!handle) {
printf("Failed load %s \n",name);
return -1;
}
new=(struct plugin *) calloc(1,sizeof(struct plugin));
new->next=plug_ins;
plug_ins=new;
new->new_sheet=&new_sheet;
new->lookat=&lookat;
new->search_sheet=&Search_sheet;
new->getAST=&getAST;
new->deleteExpression=&deleteExpression;
sprintf(f_name,"init_%s",name);
init_p=dlsym(handle,f_name);
init_p(new); //plugin fills out the plugin struct
return 0;
}
read_plugin(struct roman *p_t, char *file,char *name )
{
struct plugin *p=plug_ins;
for(;p!=0; p=p->next)
if ((p !=0 ) && (strcmp(name,p->name)==0 ))
return p->read(p_t,file);
}
write_plugin(struct roman *p_t, char *file,char *name )
{
struct plugin *p=plug_ins;
for(;p!=0; p=p->next)
if ((p !=0 ) && (strcmp(name,p->name)==0 ))
return p->write(p_t,file);
}