From 2bdd100b045c419fdd33bafc9f8bc77581fea7f6 Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Sun, 5 May 2024 14:56:23 +0200 Subject: [PATCH 1/3] Make & doxyfile --- Doxyfile | 8 ++++++-- Makefile | 4 +++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Doxyfile b/Doxyfile index 11a9cd1..31248a3 100644 --- a/Doxyfile +++ b/Doxyfile @@ -1,6 +1,10 @@ -PROJECT_NAME = MyProject -PROJECT_NUMBER = 1.0 +PROJECT_NAME = CTree +PROJECT_NUMBER = $(PROJECT_NUMBER) INPUT = src +RECURSIVE = YES +EXTRACT_ALL = YES +INPUT += README.md +USE_MDFILE_AS_MAINPAGE = README.md OUTPUT_DIRECTORY = docs #EXCLUDE = /path/to/exclude/directory diff --git a/Makefile b/Makefile index 1a990a8..861b543 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,8 @@ # Compiler CC := gcc +GITHASH := $(shell git rev-parse --short HEAD) + # Compiler flags CFLAGS := -Wall -Wextra -Wpedantic -std=c2x @@ -44,7 +46,7 @@ clean: rm -rf $(BUILD_DIR) $(TARGET) docs: - doxygen Doxyfile + PROJECT_NUMBER=git-$(GITHASH) doxygen Doxyfile cppcheck: cppcheck --enable=all --inconclusive --std=c11 --language=c --platform=unix64 --suppress=missingIncludeSystem $(SRCS) From 4eeccffc4679fe7be61bac2ba1915b9d3a305b2e Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Sun, 5 May 2024 14:56:33 +0200 Subject: [PATCH 2/3] Simple readme --- README.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..23d90ff --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# CTree Example Project + +Sample project for the CTree library. Testing out writing C with best practices in mind. From 263cb19258e992a3d3c0ebfc83fb92007d7b73d5 Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Sun, 5 May 2024 14:56:43 +0200 Subject: [PATCH 3/3] Attempt att correct documentation --- src/main.c | 9 +++++++++ src/tree.h | 25 +++++++++++++++++++++---- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/main.c b/src/main.c index 430e662..73d2edf 100644 --- a/src/main.c +++ b/src/main.c @@ -7,6 +7,15 @@ #define ANSI_COLOR_RED "\x1b[31m" #define ANSI_COLOR_RESET "\x1b[0m" +/** + * @brief Assert a condition + * @details If the condition is false, print an error message + * and exit the program + * + * @param condition The condition to assert + * @param message The message to print if the condition is false + * @return 0 if the condition is true + */ int assert(bool condition, const char *message) { if (!condition) { printf(ANSI_COLOR_RED "Assertion failed: %s\n" ANSI_COLOR_RESET, message); diff --git a/src/tree.h b/src/tree.h index ef90695..c89a820 100644 --- a/src/tree.h +++ b/src/tree.h @@ -5,20 +5,37 @@ #include #include -// A regular node with a left and right branch +/** + * @brief A node in a binary tree + * @details A node in a binary tree has some data + * and can have a left and right branch + */ struct Node { + /** @brief The data of the node */ int data; - struct Node *left, *right; + + /** @see Node */ + struct Node *left; + + /** @see Node */ + struct Node *right; }; typedef struct Node Node; -// Represents a tree with a root node +/** @brief Represents a tree with a root node */ struct Tree { + /** @brief The root node of the tree */ Node *root; }; typedef struct Tree Tree; -// Insert some data into the tree +/** + * @brief Insert some data into the tree + * + * @param tree + * @param data + * @return * Insert + */ int tree_insert(Tree *tree, int data); // Remove some data from the tree