source: trunk/FACT++/dim/src/sll.c@ 13758

Last change on this file since 13758 was 11071, checked in by tbretz, 13 years ago
Replaced v19r21 by a version extracted with 'unzip -a' to get proper unix text format.
File size: 1.7 KB
Line 
1/*
2 * A utility file. A single linked list.
3 *
4 * Started date : 10-11-91
5 * Written by : C. Gaspar
6 * UNIX adjustment: G.C. Ballintijn
7 *
8 */
9
10#define DIMLIB
11#include <dim.h>
12
13
14void sll_init( SLL* head )
15{
16 head->next = (SLL *)0;
17}
18
19
20int sll_insert_queue( SLL* head, SLL* item )
21{
22 SLL *auxp;
23
24 DISABLE_AST
25 auxp = head;
26 while( auxp->next )
27 auxp = auxp->next;
28 auxp->next = item;
29 item->next = 0;
30 ENABLE_AST
31 return(1);
32}
33
34
35SLL *sll_search( SLL* head, char *data, int size )
36{
37 DISABLE_AST
38 while( (head = head->next) )
39 {
40 if( !memcmp(head->user_info, data, size) )
41 {
42 break;
43 }
44 }
45 ENABLE_AST
46 return(head);
47}
48
49
50SLL *sll_get_next(SLL* item)
51{
52 DISABLE_AST
53 if( item )
54 item = item->next;
55 ENABLE_AST
56 return(item);
57}
58
59
60int sll_empty( SLL* head )
61{
62 register int ret;
63
64 DISABLE_AST
65 if(head->next)
66 ret = 0;
67 else
68 ret = 1;
69 ENABLE_AST
70 return(ret);
71}
72
73
74int sll_remove( SLL* head, SLL* item )
75{
76 register int ret = 0;
77
78 DISABLE_AST
79 while( head->next )
80 {
81 if( head->next == item )
82 {
83 head->next = item->next;
84 ret = 1;
85 break;
86 }
87 head = head->next;
88 }
89 ENABLE_AST
90 return(ret);
91}
92
93
94SLL *sll_remove_head( SLL* head )
95{
96 register SLL *auxp;
97
98 DISABLE_AST
99 if( (auxp = head->next) )
100 {
101 head->next = auxp->next;
102 }
103 ENABLE_AST
104 return(auxp);
105}
106
107SLL *sll_get_head( SLL* head )
108{
109 register SLL *auxp;
110
111 DISABLE_AST
112 auxp = head->next;
113 ENABLE_AST
114 return(auxp);
115}
116
117
118SLL *sll_search_next_remove( SLL* item, int offset, char *data, int size )
119{
120 register SLL *auxp;
121
122 DISABLE_AST
123 while( (auxp = item->next) )
124 {
125 if( !memcmp(&(auxp->user_info[offset]), data, size) )
126 {
127 item->next = auxp->next;
128 break;
129 }
130 item = auxp;
131 }
132 ENABLE_AST
133 return(auxp);
134}
135
Note: See TracBrowser for help on using the repository browser.