summaryrefslogtreecommitdiff
path: root/src/base/exportFunction.c
blob: 955c0e1ee98a1c4070d24d536ac2a7d7e9007c79 (plain)
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
71
72
73

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>

#include "main.h"
#include "list.h"
#include "exportFunction.h"

typedef struct export_fce_item_struct
{
	char *name;
	void *function;
}  export_fce_item_t;

static list_t *listExportFce;

static export_fce_item_t* newExportFceItem(char *name, void *function)
{
	export_fce_item_t *new;

	new = malloc( sizeof(export_fce_item_t) );
	new->name = strdup(name);
	new->function = function;

	return new;
}

static void destroyExportFce(export_fce_item_t *p)
{
	free(p->name);
	free(p);
}

void initExortFunction()
{
	listExportFce = newList();
}

void addToExportFce(char *name, void *function)
{
	printf("add to export function %s\n", name);

	addList(listExportFce, newExportFceItem(name, function) );
}

void* getExportFce(char *name)
{
	int i;

	for( i = 0 ; i < listExportFce->count ; i++ )
	{
		export_fce_item_t *this;

		this = (export_fce_item_t *)listExportFce->list[i];

		if( strcmp(this->name, name) == 0 )
		{
			return this->function;
		}
	}

	return NULL;
}

void quitExportFunction()
{
	destroyListItem(listExportFce, destroyExportFce);
}