Compare commits

..

No commits in common. "01e4d7c9ecc1ad03a50225a0d48ae403f3f41021" and "48908719facb97d83be7893d91e211800972c217" have entirely different histories.

6 changed files with 15 additions and 67 deletions

View File

@ -6,7 +6,7 @@
CC="tcc" CC="tcc"
main: src/main.c src/node/node.c src/node2d/node2d.c main: src/main.c src/node.c
tcc -o $@ -I src $^ tcc -o $@ -I src $^
clean: clean:

View File

@ -1,7 +1,6 @@
#include<stdio.h> #include<stdio.h>
#include "node/node.h" #include "node.h"
#include "node2d/node2d.h"
int main(int argc, char* *argv){ int main(int argc, char* *argv){
NOD_Node *distros = NOD_CreateNode("Distros"); NOD_Node *distros = NOD_CreateNode("Distros");
@ -21,12 +20,6 @@ int main(int argc, char* *argv){
NOD_Node *openbsd = NOD_CreateNode("OpenBSD"); NOD_Node *openbsd = NOD_CreateNode("OpenBSD");
NOD_Node *debianbsd = NOD_CreateNode("Debian GNU/kFreeBSD"); NOD_Node *debianbsd = NOD_CreateNode("Debian GNU/kFreeBSD");
NOD_Node2D *point = NOD_CreateNode2D("Point2D");
point->pos.x = 2;
printf("The X value of '%s' is %d!\n", point->node.name, 3);
NOD_NodeAddChild(debian, point);
NOD_NodeAddChild(distros, linoox); NOD_NodeAddChild(distros, linoox);
NOD_NodeAddChild(distros, bsd); NOD_NodeAddChild(distros, bsd);
@ -50,10 +43,8 @@ int main(int argc, char* *argv){
//NOD_NodeUnparent(child2); //NOD_NodeUnparent(child2);
NOD_PrintNodeTree(distros); NOD_PrintNodeTree(distros);
NOD_DestroyNodeBranch(distros);
return 0; return 0;
} }

View File

@ -5,15 +5,10 @@
#include <string.h> #include <string.h>
NOD_Node *NOD_CreateNode(char *name){ NOD_Node *NOD_CreateNode(char *name){
return NOD_CreateNodeEX("Node", name);
}
NOD_Node *NOD_CreateNodeEX(char* type, char *name){
NOD_Node *node = malloc(sizeof(NOD_Node)); NOD_Node *node = malloc(sizeof(NOD_Node));
if(node != NULL){ if(node != NULL){
node->name = name; node->name = name;
node->type = type;
node->parent = NULL; node->parent = NULL;
node->childv = NULL; node->childv = NULL;
@ -25,7 +20,7 @@ NOD_Node *NOD_CreateNodeEX(char* type, char *name){
void NOD_DestroyNode(NOD_Node *node){ void NOD_DestroyNode(NOD_Node *node){
if(node != NULL){ if(node != NULL){
/*printf("NOD_Info: Deleting node \"%s\"\n", node->name);*/ printf("NOD_Info: Deleting node \"%s\"\n", node->name);
/** Cleanup dependencies on this node by its parent */ /** Cleanup dependencies on this node by its parent */
NOD_NodeUnparent(node); NOD_NodeUnparent(node);
free(node); free(node);
@ -133,9 +128,9 @@ void NOD_NodeUnparent(NOD_Node *node){
/* Free allocated memory if last child */ /* Free allocated memory if last child */
if(i + 1 == parent->childc){ if(i + 1 == parent->childc){
/*fprintf(stderr, fprintf(stderr,
"NOD_Debug: Freeing last child \"%s\" of vector \"%s\"...\n", "NOD_Debug: Freeing last child \"%s\" of vector \"%s\"...\n",
node->name, parent->name);*/ node->name, parent->name);
parent->childv = realloc(parent->childv, sizeof(node) *parent->childc); parent->childv = realloc(parent->childv, sizeof(node) *parent->childc);
parent->childc--; parent->childc--;
} }
@ -176,7 +171,7 @@ void nodetree_print_branch(NOD_Node *node, char* level){
strcat(level, "n"); strcat(level, "n");
} }
} }
printf("%s (%s)\n", node->name, node->type); printf("%s\n", node->name);
/** Recurse */ /** Recurse */
for(int i = 0; i < node->childc; i++){ for(int i = 0; i < node->childc; i++){
@ -194,7 +189,7 @@ void NOD_PrintNodeTree(NOD_Node *node){
if(node != NULL){ if(node != NULL){
char* level = strdup(""); char* level = strdup("");
printf("%s (%s)\n", node->name, node->type); printf("%s\n", node->name);
for(int i = 0; i < node->childc; i++){ for(int i = 0; i < node->childc; i++){
nodetree_print_branch(node->childv[i], level); nodetree_print_branch(node->childv[i], level);
} }

View File

@ -3,7 +3,6 @@
typedef struct node{ typedef struct node{
char *name; char *name;
char *type;
/** childc keeps track of allocated space, /** childc keeps track of allocated space,
not amount of children. For that use not amount of children. For that use
@ -12,12 +11,9 @@ typedef struct node{
struct node* *childv; struct node* *childv;
struct node *parent; struct node *parent;
void* data;
} NOD_Node; } NOD_Node;
NOD_Node *NOD_CreateNode(char *name); NOD_Node *NOD_CreateNode(char *name);
NOD_Node *NOD_CreateNodeEX(char *type, char *name);
void NOD_DestroyNode(NOD_Node *node); void NOD_DestroyNode(NOD_Node *node);
void NOD_DestroyNodeBranch(NOD_Node *node); void NOD_DestroyNodeBranch(NOD_Node *node);

View File

@ -1,21 +0,0 @@
#include "node2d.h"
NOD_Node2D *NOD_CreateNode2D(char *name){
NOD_Node2D *node = NULL;
NOD_Node *plain_node = NULL;
plain_node = NOD_CreateNodeEX("Node2D", name);
if(plain_node != NULL){
plain_node = realloc(plain_node, sizeof(NOD_Node2D));
if(plain_node != NULL){
node = (NOD_Node2D*)plain_node;
node->pos.x = 0;
node->pos.y = 0;
}
}
return node;
}

View File

@ -1,13 +0,0 @@
#include"../node/node.h"
#include"../types.h"
#include<stdio.h>
#include<stdlib.h>
typedef struct node_2d{
NOD_Node node;
vector2Di pos;
} NOD_Node2D;
NOD_Node2D *NOD_CreateNode2D(char *name);
void NOD_DestroyNode2D(NOD_Node *node);