diff --git a/c1/exercises/a.out.dSYM/Contents/Info.plist b/c1/exercises/a.out.dSYM/Contents/Info.plist new file mode 100644 index 0000000..3679a65 --- /dev/null +++ b/c1/exercises/a.out.dSYM/Contents/Info.plist @@ -0,0 +1,20 @@ + + + + + CFBundleDevelopmentRegion + English + CFBundleIdentifier + com.apple.xcode.dsym.a.out + CFBundleInfoDictionaryVersion + 6.0 + CFBundlePackageType + dSYM + CFBundleSignature + ???? + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + + diff --git a/c1/exercises/a.out.dSYM/Contents/Resources/Relocations/aarch64/a.out.yml b/c1/exercises/a.out.dSYM/Contents/Resources/Relocations/aarch64/a.out.yml new file mode 100644 index 0000000..3cb936a --- /dev/null +++ b/c1/exercises/a.out.dSYM/Contents/Resources/Relocations/aarch64/a.out.yml @@ -0,0 +1,7 @@ +--- +triple: 'arm64-apple-darwin' +binary-path: a.out +relocations: + - { offset: 0x26, size: 0x8, addend: 0x0, symName: _main, symObjAddr: 0x0, symBinAddr: 0x100003F38, symSize: 0x30 } + - { offset: 0x41, size: 0x8, addend: 0x0, symName: _main, symObjAddr: 0x0, symBinAddr: 0x100003F38, symSize: 0x30 } +... diff --git a/c1/exercises/compile_commands.json b/c1/exercises/compile_commands.json new file mode 100644 index 0000000..fe51488 --- /dev/null +++ b/c1/exercises/compile_commands.json @@ -0,0 +1 @@ +[] diff --git a/c1/exercises/main.c b/c1/exercises/main.c new file mode 100644 index 0000000..2097858 --- /dev/null +++ b/c1/exercises/main.c @@ -0,0 +1,56 @@ +#include "util.h" +#include +#include + +typedef struct tree *T_tree; +struct tree { + T_tree left; + string key; + T_tree right; +}; +T_tree Tree(T_tree l, string k, T_tree r) +{ + T_tree t = checked_malloc(sizeof(*t)); + t->left = l; + t->key = k; + t->right = r; + return t; +} + +T_tree insert(string key, T_tree t) +{ + if (t == NULL) + return Tree(NULL, key, NULL); + else if (strcmp(key, t->key) < 0) + return Tree(insert(key, t->left), t->key, t->right); + else if (strcmp(key, t->key) > 0) + return Tree(t->left, t->key, insert(key, t->right)); + else + return Tree(t->left, key, t->right); +} + +bool member(string key, T_tree t) +{ + if (t == NULL) { + return FALSE; + } + + if (strcmp(t->key, key) == 0) { + return TRUE; + } + + return member(key, t->left) || member(key, t->right); +} + +int main(int argc, char *argv[]) +{ + string values[] = { "t", "s", "p", "i", "p", "f", "b", "s", "t" }; + + T_tree tree; + + for (int i = 0; i < 9; i++) { + tree = insert(values[i], tree); + } + + printf("member: %d\n", member("t", tree)); +} diff --git a/c1/exercises/makefile b/c1/exercises/makefile new file mode 100644 index 0000000..b03fb0a --- /dev/null +++ b/c1/exercises/makefile @@ -0,0 +1,11 @@ +all: main.o util.o + gcc -g main.o util.o + +main.o: main.c util.h + gcc -g -c main.c util.h + +util.o: util.c util.h + gcc -g -c util.c + +clean: + rm -f a.out util.o prog1.o slp.o main.o diff --git a/c1/exercises/util.c b/c1/exercises/util.c new file mode 100644 index 0000000..e6445d6 --- /dev/null +++ b/c1/exercises/util.c @@ -0,0 +1,16 @@ +#include +#include +#include "util.h" +string String(char *s) +{ + string p = checked_malloc(strlen(s)+1); + strcpy(p,s); + return p; +} + +void *checked_malloc(int len) +{ + void *p = malloc(len); + assert(p); + return p; +} diff --git a/c1/exercises/util.h b/c1/exercises/util.h new file mode 100644 index 0000000..c1476b5 --- /dev/null +++ b/c1/exercises/util.h @@ -0,0 +1,16 @@ +#ifndef UTIL_H +#define UTIL_H + +#include + +typedef char *string; +string String(char *); + +typedef char bool; +#define TRUE 1; +#define FALSE 0; + +void *checked_malloc(int); + +#endif // !UTIL_H + diff --git a/c1/exercises/util.h.gch b/c1/exercises/util.h.gch new file mode 100644 index 0000000..e35006a Binary files /dev/null and b/c1/exercises/util.h.gch differ