-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInstructionsListHandler.c
50 lines (40 loc) · 1004 Bytes
/
InstructionsListHandler.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
#include "declarationsHeader.h"
extern insPtr insListHead;
extern size_t insListLength;
/*
* Adds the passed memory word to the instructions list.
*/
void addToInsList(Word *newWord, char *strWord, char *str) {
static insPtr last;
insPtr newNode = (insPtr) malloc(sizeof(insNode));
MEMORY_ERROR(newNode)
insListLength++;
newNode->data = (*newWord);
strcpy(newNode->str, str);
strcpy(newNode->strWord, strWord);
newNode->next = NULL;
if (insListHead == NULL) {
insListHead = newNode;
last = insListHead;
} else {
last->next = newNode;
last = last->next;
}
}
/*
* Frees the instructions list.
*/
void freeInsList() {
insPtr ptr;
Word pWord;
while (insListHead != NULL) {
ptr = insListHead;
/*Freeing the word.*/
pWord = ptr->data;
free(pWord);
insListHead = insListHead->next;
/*Freeing the node itself.*/
free(ptr);
}
insListLength = 0;
}