-
Notifications
You must be signed in to change notification settings - Fork 0
/
externals.c
72 lines (66 loc) · 1.6 KB
/
externals.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
/**
* externals list declaration and functions
*/
#include "headers.h"
#include "consts.h"
static external *external_list = NULL;
/**
* add external to external list
* @param symbol_id - external symbol name
* @param base - base value
* @param offset - off set value
* @return external object
*/
external *add_to_external_list(char *symbol_id , int base, int offset){
external *new = NULL;
new = malloc(sizeof(external));
if (new == NULL){
fprintf(stderr,"could not allocate memory ");
exit(1);
}
strcpy(new->symbol_name, symbol_id);
new->base = base;
new->offset =offset;
new->next = NULL;
if(!external_list){
external_list = new;
} else {
external * ptr = external_list;
while (ptr->next){
ptr = ptr->next;
}
ptr->next = new;
}
return new;
}
/**
* get the head object of the externals list
* @return external head object
*/
external *get_head_externals() {
external * it = external_list;
return it;
}
/**
* write externals list to ext file
* @param file_to_write - externals file
*/
void print_externals_to_file(FILE * file_to_write) {
external * it = external_list;
while (it){ /* for each external */
fprintf(file_to_write, "%s BASE %d \n%s OFFSET %d \n\n", it->symbol_name, it->base, it->symbol_name,it->offset);
it = it->next;
}
}
/**
* free externals list from memory
*/
void free_externals_list() {
external *it = external_list, *tmp;
while (it != NULL) {
tmp = it;
it = it->next;
free(tmp);
}
external_list = NULL;
}