-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtraverser.c
78 lines (55 loc) · 1.94 KB
/
traverser.c
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "heap.h"
#include "traverser.h"
#include "linked_list.h"
void printAddress(void *object) {
printf("\t[%p]\n", object);
}
ll_head traverse_pointers_from_LL(ll_head pointers) {
ll_head new_nodes = LL_initRoot();
ll_head pointers_in_obj = NULL;
if(pointers != NULL && !LL_isEmpty(pointers)) {
ll_node *cursor = *pointers;
while(cursor != NULL) {
if(LL_getContent(cursor) == NULL) {
cursor = LL_getNext(cursor);
continue;
}
void **content = (void **)LL_getContent(cursor);
char *metadata = md_get_format_string(LL_getContent(cursor));
if(strcmp(metadata, NO_MD) == 0) {
cursor = LL_getNext(cursor);
continue;
}
if(*content != NULL) {
pointers_in_obj = fs_get_pointers_within_object(*content);
}
traverse_pointers_from_LL(pointers_in_obj);
if(pointers_in_obj != NULL) {
ll_node *recursive_cursor = *pointers_in_obj;
while(recursive_cursor != NULL) {
void *next = LL_getNext(recursive_cursor);
void *content = LL_deletePointer(pointers_in_obj, recursive_cursor);
LL_createAndInsertSequentially(new_nodes, content);
recursive_cursor = next;
}
}
cursor = LL_getNext(cursor);
}
ll_node *nn_cursor = *new_nodes;
while(nn_cursor != NULL) {
void *next = LL_getNext(nn_cursor);
void *content = LL_deletePointer(new_nodes, nn_cursor);
LL_createAndInsertSequentially(pointers, content);
nn_cursor = next;
}
free(pointers_in_obj);
free(new_nodes);
return pointers;
} else {
free(new_nodes);
return LL_initRoot();
}
}