MCPcopy Create free account
hub / github.com/DescentDevelopers/Descent3 / AddListItem

Function AddListItem

Descent3/list.cpp:43–75  ·  view source on GitHub ↗

Adds an item to a list Returns 1 if everything is ok, else 0

Source from the content-addressed store, hash-verified

41// Adds an item to a list
42// Returns 1 if everything is ok, else 0
43int AddListItem(listnode **listp, void *item) {
44 listnode *newnode, *curr;
45
46 newnode = NewListNode();
47
48 if (newnode == NULL) {
49 mprintf(0, "There was a problem mallocing list node memory!\n");
50 Int3();
51 return 0;
52 }
53
54 if (*listp == NULL) // If this list is empty, construct a new head
55 {
56 newnode->data = item;
57 *listp = newnode;
58 return 1;
59 } else {
60 // Go through until the end of the list and add the new item there
61 for (curr = *listp; curr->next != NULL; curr = curr->next) {
62 if (curr->data == item) {
63 Int3();
64 return 0;
65 }
66 }
67
68 newnode->data = item;
69 curr->next = newnode;
70 newnode->next = NULL;
71 newnode->prev = curr;
72 }
73
74 return 1;
75}
76
77// Removes an item from a list
78int RemoveListItem(listnode **listp, void *item) {

Callers 3

BuildBSPNodeFunction · 0.85
BuildBSPTreeFunction · 0.85
BuildSingleBSPTreeFunction · 0.85

Calls 1

NewListNodeFunction · 0.85

Tested by

no test coverage detected