summaryrefslogtreecommitdiff
path: root/comp/cw/code/tokenizer/ads/dict
diff options
context:
space:
mode:
Diffstat (limited to 'comp/cw/code/tokenizer/ads/dict')
-rw-r--r--comp/cw/code/tokenizer/ads/dict/Makefile4
-rw-r--r--comp/cw/code/tokenizer/ads/dict/dict.c29
-rw-r--r--comp/cw/code/tokenizer/ads/dict/dict.h9
-rw-r--r--comp/cw/code/tokenizer/ads/dict/dict.obin0 -> 1768 bytes
-rwxr-xr-xcomp/cw/code/tokenizer/ads/dict/dicttestbin0 -> 20536 bytes
-rw-r--r--comp/cw/code/tokenizer/ads/dict/dicttest.c10
6 files changed, 52 insertions, 0 deletions
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 <stdlib.h>
+#include <string.h>
+
+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
--- /dev/null
+++ b/comp/cw/code/tokenizer/ads/dict/dict.o
Binary files 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
--- /dev/null
+++ b/comp/cw/code/tokenizer/ads/dict/dicttest
Binary files 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 <stdio.h>
+
+#include "dict.h"
+
+int main(){
+ dict_t *dict = dictalloc();
+ dictset(dict, 1, "hello");
+ printf("%d:%s\n", dict->id, (char *)dict->data);
+ dictfree(dict);
+}