From e39f31e41133c1be2ea8585c716eba95cc05232d Mon Sep 17 00:00:00 2001 From: Liam Waldron Date: Tue, 22 Oct 2024 10:56:37 -0400 Subject: [PATCH] v4.0.0-rc5 - add dependency tree data type support --- VERSION | 2 +- config.mk | 2 ++ include/glacier_data.h | 75 ++++++++++++++++++++++++++++++++++++++++++ libglacier.c | 73 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 151 insertions(+), 1 deletion(-) create mode 100644 include/glacier_data.h diff --git a/VERSION b/VERSION index 048bc5b..1882577 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -4.0.0-rc4 +4.0.0-rc5 diff --git a/config.mk b/config.mk index 3e9c9ce..3f6419c 100644 --- a/config.mk +++ b/config.mk @@ -6,3 +6,5 @@ CC = /bin/gcc AR = /bin/ar LIBFLAGS = -lconfig + +PREFIX = /usr diff --git a/include/glacier_data.h b/include/glacier_data.h new file mode 100644 index 0000000..aa83a23 --- /dev/null +++ b/include/glacier_data.h @@ -0,0 +1,75 @@ +/* + * glacier_log.h - Data structures for libglacier + * + * This file is part of Glacier. + * + * Glacier is free software: you can redistribute it and/or modify it under the terms of the + * GNU General Public License as published by the Free Software Foundation, either + * version 3 of the License, or (at your option) any later version. + * + * Glacier is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A + * PARTICULAR PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along with Glacier. If + * not, see . + */ + +#ifndef GLACIERDATA_H_ +#define GLACIERDATA_H_ + +/* + * create_node + * + * DESCRIPTION: Create_node creates a node for a dependency tree data structure. + * PARAMETERS: + * char *data -> The name of the node to create + * RETURN VALUES: + * None. + * CAVEATS: + * None. + * EXAMPLE: + * struct node package = create_node("Package"); + */ + +struct node *create_node(char *data); + +/**************************************************************************************************************/ + +/* + * add_child + * + * DESCRIPTION: Add_child adds a child node to a parent node. + * PARAMETERS: + * struct node *parent -> The parent node which the child will be added to + * struct node *child -> The child node which will be added to the parent node + * RETURN VALUES: + * 1 on maximum children exceeded + * CAVEATS: + * None. + * EXAMPLE: + * add_child(package, dep1); + */ + +void add_child(struct node *parent, struct node *child); + +/**************************************************************************************************************/ + +/* + * print_tree + * + * DESCRIPTION: Print_tree prints a dependency tree specified at its root node + * PARAMETERS: + * struct node *root -> The tree to print + * int level -> The number of levels to descend + * RETURN VALUES: + * None. + * CAVEATS: + * None. + * EXAMPLE: + * print_tree(package, 0); + */ + +void print_tree(struct node *root, int level); + +#endif diff --git a/libglacier.c b/libglacier.c index 9f36c98..1ffd410 100644 --- a/libglacier.c +++ b/libglacier.c @@ -31,6 +31,8 @@ #include "config.h" +#define MAX_CHILDREN 64 + /* Global variables */ config_t cfg; @@ -53,6 +55,12 @@ const char *runtime_files[] = { "/etc/make.conf" }; +struct node { + char *data; + struct node *children[MAX_CHILDREN]; + int numChildren; +}; + /* * infolog * @@ -285,6 +293,71 @@ load_all_from_config() load_setting_from_config(char SETTING[]) {} */ +/* +* create_node +* +* DESCRIPTION: Create a dependency tree node. +* PARAMETERS: char *data +* DEFINED IN: glacier_data.h +* +*/ + +struct node +*create_node(char *data) +{ + struct node *newNode = (struct node*)malloc(sizeof(struct node)); + newNode->data = strdup(data); + newNode->numChildren = 0; + return newNode; +} + +/* +* add_child +* +* DESCRIPTION: Add a child node to a parent node. +* PARAMETERS: struct node *parent, struct node *child +* DEFINED IN: glacier_data.h +* +*/ + +void +add_child(struct node *parent, struct node *child) +{ + if (parent->numChildren < MAX_CHILDREN) { + parent->children[parent->numChildren++] = child; + } else { + if (LG_VERBOSE == 1) { errlog("Maximum number of children exceeded"); } + exit(1); + } +} + +/* +* print_tree +* +* DESCRIPTION: Print a dependency tree. +* PARAMETERS: struct node *root, int level +* DEFINED IN: glacier_data.h +* +*/ + +void +print_tree(struct node *root, int level) +{ + if (root == NULL) { + return; + } + + for (int i = 0; i < level; i++) { + printf(" "); + } + + printf("%s\n", root->data); + + for (int i = 0; i < root->numChildren; i++) { + print_tree(root->children[i], level + 1); + } +} + /* * mkworkspace *