1/* struct::tree - critcl - support - stack/queue of nodes. 2 * definitions. 3 */ 4 5#include "tcl.h" 6#include <util.h> 7 8static NL* newitem (void* n); 9 10 11/* Initialize queue data structure. 12 */ 13 14void 15g_nlq_init (NLQ* q) 16{ 17 q->start = q->end = NULL; 18} 19 20/* Add item to end of the list 21 */ 22 23void 24g_nlq_append (NLQ* q, void* n) 25{ 26 NL* qi = newitem (n); 27 28 if (!q->end) { 29 q->start = q->end = qi; 30 } else { 31 q->end->next = qi; 32 q->end = qi; 33 } 34} 35 36/* Add item to the front of the list 37 */ 38 39void 40g_nlq_push (NLQ* q, void* n) 41{ 42 NL* qi = newitem (n); 43 44 if (!q->end) { 45 q->start = q->end = qi; 46 } else { 47 qi->next = q->start; 48 q->start = qi; 49 } 50} 51 52/* Return item at front of the list. 53 */ 54 55void* 56g_nlq_pop (NLQ* q) 57{ 58 NL* qi = NULL; 59 void* n = NULL; 60 61 if (!q->start) { 62 return NULL; 63 } 64 65 qi = q->start; 66 n = qi->n; 67 68 q->start = qi->next; 69 if (q->end == qi) { 70 q->end = NULL; 71 } 72 73 ckfree ((char*) qi); 74 return n; 75} 76 77/* Delete all items in the list. 78 */ 79 80void* 81g_nlq_clear (NLQ* q) 82{ 83 NL* next; 84 NL* qi = q->start; 85 86 while (qi) { 87 next = qi->next; 88 ckfree ((char*) qi); 89 qi = next; 90 } 91 q->start = NULL; 92 q->end = NULL; 93} 94 95/* INTERNAL - Create new item to put into the list. 96 */ 97 98static NL* 99newitem (void* n) 100{ 101 NL* qi = (NL*) ckalloc (sizeof (NL)); 102 103 qi->n = n; 104 qi->next = NULL; 105 106 return qi; 107} 108 109/* 110 * Local Variables: 111 * mode: c 112 * c-basic-offset: 4 113 * fill-column: 78 114 * End: 115 */ 116