diff --git a/Makefile b/Makefile index ea599e2..03b6c3b 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,8 @@ .phony: test test: - $(MAKE) -C bstr test - $(MAKE) -C flag test - $(MAKE) -C vec test - $(MAKE) -C binary_tree test + $(MAKE) -C bstr test 1> /dev/null + $(MAKE) -C flag test 1> /dev/null + $(MAKE) -C vec test 1> /dev/null + @echo "All tests passed" diff --git a/binary_tree/Makefile b/binary_tree/Makefile deleted file mode 100644 index 2d5305d..0000000 --- a/binary_tree/Makefile +++ /dev/null @@ -1,16 +0,0 @@ -CC = gcc -CFLAGS = -std=c99 -Wall -Wextra -Wpedantic -DEBUGCFLAGS = -fsanitize=address -fsanitize=undefined - -.PHONY: all -all: bintree maintest - -test: all - $(CC) $(DEBUGCFLAGS) $(LIBS) *.o - @./a.out - -bintree: bintree.c - $(CC) $(CFLAGS) -O2 -c $^ - -maintest: maintest.c - $(CC) $(CFLAGS) -c $^ diff --git a/binary_tree/README.md b/binary_tree/README.md deleted file mode 100644 index 0f4d850..0000000 --- a/binary_tree/README.md +++ /dev/null @@ -1,54 +0,0 @@ -# Binary Tree - -A generic binary tree - -## Usage - -Create binary tree - -```c -bt_BinaryTree *bt = bt_new((char*)'a'); -``` - -Delete binary tree - -```c -bt_remove_node(bt); -``` - -Insert to the right leaf - -```c -bt_insert_right(bt, (char*)'b'); -``` - -Insert to the left leaf - -```c -bt_insert_right(bt, (char*)'c'); -``` - -Insert in the right leaf's left leaf - -```c -bt_insert_left(bt->right, (char*)'d'); -``` - -Remove leaf and all its children - -```c -bt_remove_node(bt->right); -``` - -Get item from leaf - -```c -char = *(char*)bt_getitem(bt.left); -``` - -Print tree - -```c -bt_print(bt, "%c"); -``` - diff --git a/binary_tree/bintree.c b/binary_tree/bintree.c deleted file mode 100644 index cf1a7b9..0000000 --- a/binary_tree/bintree.c +++ /dev/null @@ -1,128 +0,0 @@ -#include "bintree.h" -#include -#include -#include - -/* - * Allocates space for a new node and assigns a value to it - * - * @param val The value stored in the node - * - * @return A newly allocated binary tree node or NULL if it fails - */ -bt_BinaryTree *bt_new(void *val) { - bt_BinaryTree *new = malloc(sizeof(bt_BinaryTree)); - if (new == NULL) { - return NULL; - } - new->left = NULL; - new->right = NULL; - new->val = val; - return new; -} - -void *bt_getitem(bt_BinaryTree *bt) { return &bt->val; } - -/* - * Inserts a new node on the right - * - * @param bt The node that will be inserted into - * @param val The value of the new node - * - * @return BT_NODE_EXISTS or BT_SUCCESS - */ -bool bt_insert_right(bt_BinaryTree *bt, void *val) { - bt_BinaryTree *tmp = bt; - if (tmp->right == NULL) { - tmp->right = bt_new(val); - } else { - return false; - } - return true; -} - -/* - * Inserts a new node on the left - * - * @param bt The node that will be inserted into - * @param val The value of the new node - * - * @return BT_NODE_EXISTS or BT_SUCCESS - */ -bool bt_insert_left(bt_BinaryTree *bt, void *val) { - bt_BinaryTree *tmp = bt; - if (tmp->left == NULL) { - tmp->left = bt_new(val); - } else { - return false; - } - return true; -} - -/* - * Prints the current node's value - * - * @param bt The node that will be printed - * @param depth The node's depth in the tree - * - * @return BT_NODE_DOES_NOT_EXIST or BT_SUCCESS - */ - -void bt_print(const bt_BinaryTree *bt, char *fmt) { - // TODO -} - -/* - * Removes a node and all of it's children - * - * @param bt The node that will be removed - * - * @return BT_NODE_DOES_NOT_EXIST or BT_SUCCESS - */ -bool bt_remove_node(bt_BinaryTree *bt) { - if (bt == NULL) { - return false; - } - bt_remove_node(bt->left); - bt_remove_node(bt->right); - free(bt); - bt = NULL; - return true; -} - -/* - * Total size of the binary tree - * - * @param bt Binary tree's root node - * - * @return Number of nodes in the binary tree - */ -size_t bt_sizeof(bt_BinaryTree *bt) { - if (bt == NULL) { - return 0; - } - return bt_sizeof(bt->left) + 1 + bt_sizeof(bt->right); -} - -/* - * Find a value in the binary tree - * - * @param bt Binary tree's root - * @param val Value that's being searched for - * - * @return The node containing the searched value - */ -bt_BinaryTree *bt_find(bt_BinaryTree *bt, void *val) { - bt_BinaryTree *tmp = NULL; - - if (!bt) { - tmp = NULL; - } else if (bt->val == val) { - tmp = bt; - } - if (bt->left != NULL) - tmp = bt_find(bt->left, val); - if (bt->right != NULL) - tmp = bt_find(bt->right, val); - return tmp; -} diff --git a/binary_tree/bintree.h b/binary_tree/bintree.h deleted file mode 100644 index 45ce8cf..0000000 --- a/binary_tree/bintree.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef BINTREE_H -#define BINTREE_H -#include -#include - -typedef struct bintree { - void *val; - struct bintree *left; - struct bintree *right; -} bt_BinaryTree; - -bt_BinaryTree *bt_new(void *val); -void *bt_getitem(bt_BinaryTree *bt); -bool bt_insert_right(bt_BinaryTree *bt, void *val); -bool bt_insert_left(bt_BinaryTree *bt, void *val); -void bt_print(const bt_BinaryTree *bt, char *fmt); -bool bt_remove_node(bt_BinaryTree *bt); -size_t bt_sizeof(bt_BinaryTree *bt); -bt_BinaryTree *bt_find(bt_BinaryTree *bt, void *val); - -#endif diff --git a/binary_tree/maintest.c b/binary_tree/maintest.c deleted file mode 100644 index 01e61a8..0000000 --- a/binary_tree/maintest.c +++ /dev/null @@ -1,25 +0,0 @@ -#include -#include "bintree.h" -#include - -int main(void) -{ - bt_BinaryTree *bt = bt_new((char*)'a'); - assert(*(char*)bt_getitem(bt) == 'a'); - - bt_insert_right(bt, (char*)'b'); - assert(*(char*)bt_getitem(bt->right) == 'b'); - - bt_insert_left(bt, (char*)'c'); - assert(*(char*)bt_getitem(bt->left) == 'c'); - assert(bt_sizeof(bt) == 3); - - bt_insert_right(bt->right, (char*)'z'); - bt_insert_left(bt->right, (char*)'y'); - assert(bt_find(bt, (char*)'z') == bt->right->right); - - bt_print(bt, "%c"); - bt_remove_node(bt); - puts("Passed all tests"); - return 0; -} diff --git a/flag/flag.c b/flag/flag.c index e1b7b1e..f0ff86a 100644 --- a/flag/flag.c +++ b/flag/flag.c @@ -237,11 +237,9 @@ void flag_parse(flag_Parser *p) { break; } - goto next_arg; + // goto to next flag after this flag is parsed + break; } - - next_arg: - continue; } p->parsed = true; diff --git a/vec/vector.c b/vec/vector.c index 1f45d13..0e38bf8 100644 --- a/vec/vector.c +++ b/vec/vector.c @@ -174,7 +174,8 @@ bool vec_append(vec_Vector *restrict dest, const vec_Vector *src) { return true; } -vec_Vector *vec_from(void *const array, size_t length, size_t item_size) { +vec_Vector *vec_from(void *const arr, size_t length, size_t item_size) { + char *const array = arr; vec_Vector *vec = vec_new(item_size); for (size_t i = 0; i < length; i++) { if (!vec_push(vec, array + i * item_size)) {