-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathevent.c
50 lines (41 loc) · 1.39 KB
/
event.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
#include "event.h"
struct ni_event_arg* ni_event_arg_num(int number){
struct ni_event_arg* argument = mallocz(sizeof (*argument), 2);
argument->type = NI_EVENT_ARG_NUMBER;
argument->number = number;
return argument;
}
struct ni_event_arg* ni_event_arg_str(char* string){
struct ni_event_arg* argument = mallocz(sizeof (*argument), 2);
argument->type = NI_EVENT_ARG_STRING;
argument->string = memdupz(string, strlen(string));
return argument;
}
void ni_event_arg_get_num(int* number, struct ni_event_arg* this){
assert(this != NULL);
if (this->type != NI_EVENT_ARG_NUMBER){
fprintf(stderr, "nitro: event argument is not a number, but treated like one.");
exit(1);
}
*number = this->number;
}
void ni_event_arg_get_str(char** string, struct ni_event_arg* this){
assert(this != NULL);
if (this->type != NI_EVENT_ARG_STRING){
fprintf(stderr, "nitro: event argument is not a string, but treated like one.");
exit(1);
}
*string = this->string;
}
// ni_event implementation
struct ni_event *ni_event_new(const char* name, dlist(ni_event_arg)* arguments, void* data){
if (!name)
return NULL;
struct ni_event *this = mallocz(sizeof (*this), 2);
this->event_name = memdupz(name, strlen(name));
this->arguments = arguments;
this->extra = data;
return this;
}
void ni_event_free(ni_event_t *event){
}