Character Tree  1.0.0
A PDF tree builder from CSV
treestruct.h
Go to the documentation of this file.
1 /*
2 Copyright 2021 Bruno VERCHÈRE
3 
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7 
8  http://www.apache.org/licenses/LICENSE-2.0
9 
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15 */
16 
43 #if !defined(TREESTUCT_H)
44 #define TREESTUCT_H
45 
81 #define MAXDEPTH 5
82 #define MAXLEN 255
83 #define CSVSEP ";"
84 #define CSVEOL ";\n"
85 #define LOGS "logs/treeBuilder.log"
86 #define SRC "data.csv"
87 #define TEX "tree.tex"
88 
89 
107 typedef struct person{
108  int id;
109  char name[MAXLEN];
110  int value;
111  struct person *lc, *rc;
112 }Person, *Tree;
113 
114 
123 Tree createNode(int id, char name[], int value);
124 
135 int buildTree(Tree *t, int id, char name[], int value, FILE* logs);
136 
143 void getFields(char line[], char* tokens[]);
144 
151 int toInt(char* str);
152 
161 int readCSV(FILE* file, Tree *t, FILE* logs);
162 
168 void displayPerson(Tree t);
169 
176 void rowMissingChildren(FILE* file, int children);
177 
185 void missingChildren(int id, FILE* file, int rootId);
186 
193 void color(int value, char strColor[]);
194 
203 void writeLatexPerson(FILE *file, Tree t, int depth, int rootId);
204 
212 void writeLatexFile(FILE* file, Tree t, int rootId);
213 
220 void writeLogs(FILE* logs, char message[]);
221 
229 void formateInteger(int val, char ch[], char addOn[]);
230 
231 #endif // TREESTUCT_H
rowMissingChildren
void rowMissingChildren(FILE *file, int children)
Add missing children to the tree in the TEX file.
Definition: treeBuilder.c:108
createNode
Tree createNode(int id, char name[], int value)
Create a new indivudal (node).
Definition: treeBuilder.c:24
writeLatexPerson
void writeLatexPerson(FILE *file, Tree t, int depth, int rootId)
Write an individual as a node in the TEX file.
Definition: treeBuilder.c:135
missingChildren
void missingChildren(int id, FILE *file, int rootId)
Compute the number of missing children for the given node according to the root id.
Definition: treeBuilder.c:114
toInt
int toInt(char *str)
Convert a string to an integer.
Definition: treeBuilder.c:76
getFields
void getFields(char line[], char *tokens[])
Read a CSV file row.
Definition: treeBuilder.c:65
color
void color(int value, char strColor[])
Set the node color according to its value.
Definition: treeBuilder.c:126
writeLogs
void writeLogs(FILE *logs, char message[])
Add a line to the log file.
Definition: treeBuilder.c:175
displayPerson
void displayPerson(Tree t)
Display a tree in the standard output.
Definition: treeBuilder.c:99
Tree
struct person * Tree
The type definition of the binary tree.
formateInteger
void formateInteger(int val, char ch[], char addOn[])
Formate an integer to a specific string for the logs.
Definition: treeBuilder.c:184
person
A structure representing an indivual as a tree node.
Definition: treestruct.h:107
person::name
char name[MAXLEN]
Definition: treestruct.h:109
person::value
int value
Definition: treestruct.h:110
MAXLEN
#define MAXLEN
A macro representing the maximum length of a string.
Definition: treestruct.h:82
writeLatexFile
void writeLatexFile(FILE *file, Tree t, int rootId)
Write a TEX file from a binary tree.
Definition: treeBuilder.c:164
Person
struct person Person
The type definition of an individual.
person::id
int id
Definition: treestruct.h:108
© 2021 Bruno Verchère