-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgraphBuilder.c
More file actions
executable file
·81 lines (67 loc) · 2.5 KB
/
graphBuilder.c
File metadata and controls
executable file
·81 lines (67 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*/////////////////////////////
CS 537 Prog 3
Authors: Peyton Gardipee
Tushar Verma
File: graphBuilder.c
*///////////////////////////
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "fileParser.h"
#include "graphNode.h"
#include "constants.h"
targetNode* graphBuilder(targetNode *headTarget)
{
targetNode *currTargetInner, *currTargetOuter;
dependencyNode *currDependency;
targetList *currDependentTarget, *tempDependentTarget;
//Start each loop at the beginning of the list of targets
currTargetOuter = headTarget->nextTarget;
//Iterate through each of the target nodes
while(currTargetOuter != NULL)
{
//Iterate through each of the current target's dependencies
currDependency = currTargetOuter->firstDependency;
currTargetOuter->dependentTargets = malloc(sizeof(targetList));
currDependentTarget = currTargetOuter->dependentTargets;
while(currDependency->dependencyName != NULL)
{
//Iterate through each of the target nodes again to add each target with the name of the current dependency
//to the current target's list of dependent nodes
currTargetInner = headTarget->nextTarget;
while(currTargetInner != NULL)
{
if(!strcmp(currDependency->dependencyName,currTargetInner->targetName))
{
tempDependentTarget = malloc(sizeof(targetList));
tempDependentTarget->target = currTargetInner;
tempDependentTarget->nextTarget = NULL;
currDependentTarget->nextTarget = tempDependentTarget;
currDependentTarget = tempDependentTarget;
}
currTargetInner = currTargetInner->nextTarget;
}
currDependency = currDependency->nextDependency;
}
currTargetOuter = currTargetOuter->nextTarget;
}
return headTarget;
}
//Function used to get a target node given its target name
targetNode* getNode(char* targetName, targetNode* headTarget)
{
targetNode *currTarget;
currTarget = headTarget->nextTarget;
//Iterate through each target to find a match according to name
while(currTarget != NULL)
{
//Return target if match is found
if(!strcmp(currTarget->targetName, targetName))
{
return currTarget;
}
currTarget = currTarget->nextTarget;
}
//No target was found with given name
return NULL;
}