From 7d3856203d28281e3ffc6b365cc55b1d192a5599 Mon Sep 17 00:00:00 2001 From: standenboy Date: Thu, 25 Apr 2024 08:45:36 +0100 Subject: started cw --- comp/cw/code/tokenizer/ads/dict/Makefile | 4 ++++ comp/cw/code/tokenizer/ads/dict/dict.c | 29 +++++++++++++++++++++++++++++ comp/cw/code/tokenizer/ads/dict/dict.h | 9 +++++++++ comp/cw/code/tokenizer/ads/dict/dict.o | Bin 0 -> 1768 bytes comp/cw/code/tokenizer/ads/dict/dicttest | Bin 0 -> 20536 bytes comp/cw/code/tokenizer/ads/dict/dicttest.c | 10 ++++++++++ 6 files changed, 52 insertions(+) create mode 100644 comp/cw/code/tokenizer/ads/dict/Makefile create mode 100644 comp/cw/code/tokenizer/ads/dict/dict.c create mode 100644 comp/cw/code/tokenizer/ads/dict/dict.h create mode 100644 comp/cw/code/tokenizer/ads/dict/dict.o create mode 100755 comp/cw/code/tokenizer/ads/dict/dicttest create mode 100644 comp/cw/code/tokenizer/ads/dict/dicttest.c (limited to 'comp/cw/code/tokenizer/ads/dict') diff --git a/comp/cw/code/tokenizer/ads/dict/Makefile b/comp/cw/code/tokenizer/ads/dict/Makefile new file mode 100644 index 0000000..f224267 --- /dev/null +++ b/comp/cw/code/tokenizer/ads/dict/Makefile @@ -0,0 +1,4 @@ +all: dict.c + cc dict.c -c -o dict.o +test: all + cc dict.o dicttest.c -o dicttest diff --git a/comp/cw/code/tokenizer/ads/dict/dict.c b/comp/cw/code/tokenizer/ads/dict/dict.c new file mode 100644 index 0000000..551afca --- /dev/null +++ b/comp/cw/code/tokenizer/ads/dict/dict.c @@ -0,0 +1,29 @@ +#include +#include + +typedef struct dict_t { + int id; + void *data; +}dict_t; + +dict_t *dictalloc(){ + dict_t *output = malloc(sizeof(dict_t)); + return output; +} + +int dictset(dict_t *dict, int id, void *data){ + dict->id = id; + + dict->data = malloc(sizeof(data)); + if (dict->data == NULL) + return 1; + memcpy(dict->data, data, sizeof(data)); + + return 0; +} + +void dictfree(dict_t *dict){ + free(dict->data); + free(dict); +} + diff --git a/comp/cw/code/tokenizer/ads/dict/dict.h b/comp/cw/code/tokenizer/ads/dict/dict.h new file mode 100644 index 0000000..e6ab69d --- /dev/null +++ b/comp/cw/code/tokenizer/ads/dict/dict.h @@ -0,0 +1,9 @@ +typedef struct dict_t { + int id; + void *data; +}dict_t; + +dict_t *dictalloc(); +int dictset(dict_t *dict, int id, void *data); +void dictfree(dict_t *dict); + diff --git a/comp/cw/code/tokenizer/ads/dict/dict.o b/comp/cw/code/tokenizer/ads/dict/dict.o new file mode 100644 index 0000000..aefd77a Binary files /dev/null and b/comp/cw/code/tokenizer/ads/dict/dict.o differ diff --git a/comp/cw/code/tokenizer/ads/dict/dicttest b/comp/cw/code/tokenizer/ads/dict/dicttest new file mode 100755 index 0000000..dddf2a0 Binary files /dev/null and b/comp/cw/code/tokenizer/ads/dict/dicttest differ diff --git a/comp/cw/code/tokenizer/ads/dict/dicttest.c b/comp/cw/code/tokenizer/ads/dict/dicttest.c new file mode 100644 index 0000000..4a20870 --- /dev/null +++ b/comp/cw/code/tokenizer/ads/dict/dicttest.c @@ -0,0 +1,10 @@ +#include + +#include "dict.h" + +int main(){ + dict_t *dict = dictalloc(); + dictset(dict, 1, "hello"); + printf("%d:%s\n", dict->id, (char *)dict->data); + dictfree(dict); +} -- cgit v1.2.3