-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfunction.c
More file actions
37 lines (31 loc) · 930 Bytes
/
function.c
File metadata and controls
37 lines (31 loc) · 930 Bytes
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
#include <assert.h>
#include <stdlib.h>
#include "function.h"
#include "hashmap.h"
static map_t FUNCTIONS_MAP = NULL;
FunctionType *getFuncPtr(char *fname) {
if (FUNCTIONS_MAP == NULL) {
function_install(NULL);
}
FunctionType *f = NULL;
int ok = hashmap_get(FUNCTIONS_MAP, fname, (void **)(&f));
if (ok == MAP_MISSING || f == NULL) {
return NULL;
}
return f;
}
void function_install(FunctionType *f) {
if (FUNCTIONS_MAP == NULL) {
FUNCTIONS_MAP = hashmap_new();
/** build-in functions **/
function_install(NewMD5ModFunction());
if (f != NULL) {
hashmap_put(FUNCTIONS_MAP, f->name, f);
}
} else if ( f!= NULL && getFuncPtr(f->name) == NULL) {
hashmap_put(FUNCTIONS_MAP, f->name, f);
}
}
Data *function_derive(char *fname, Data **params, int nparams) {
return getFuncPtr(fname)->derive(params, nparams);
}