Last change
on this file since 14546 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.9 KB
|
Line | |
---|
1 | /*
|
---|
2 | * A utility file. A double 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 |
|
---|
14 | void dll_init( DLL* head )
|
---|
15 | {
|
---|
16 | DISABLE_AST
|
---|
17 | head->next = head;
|
---|
18 | head->prev = head;
|
---|
19 | ENABLE_AST
|
---|
20 | }
|
---|
21 |
|
---|
22 |
|
---|
23 | void dll_insert_queue( DLL* head, DLL* item )
|
---|
24 | {
|
---|
25 | register DLL *prevp;
|
---|
26 |
|
---|
27 | DISABLE_AST
|
---|
28 | item->next = head;
|
---|
29 | prevp = head->prev;
|
---|
30 | item->prev = prevp;
|
---|
31 | prevp->next = item;
|
---|
32 | head->prev = item;
|
---|
33 | ENABLE_AST
|
---|
34 | }
|
---|
35 |
|
---|
36 | void dll_insert_after( DLL* atitem, DLL* item )
|
---|
37 | {
|
---|
38 | register DLL *auxp;
|
---|
39 |
|
---|
40 | DISABLE_AST
|
---|
41 | auxp = atitem->next;
|
---|
42 | item->next = auxp;
|
---|
43 | item->prev = atitem;
|
---|
44 | atitem->next = item;
|
---|
45 | auxp->prev = item;
|
---|
46 | ENABLE_AST
|
---|
47 | }
|
---|
48 |
|
---|
49 | DLL *dll_search( DLL* head, char *data, int size )
|
---|
50 | {
|
---|
51 | register DLL *auxp= head->next;
|
---|
52 |
|
---|
53 | DISABLE_AST
|
---|
54 | while( auxp!= head ) {
|
---|
55 | if( !memcmp(auxp->user_info, data, size) ) {
|
---|
56 | ENABLE_AST
|
---|
57 | return(auxp);
|
---|
58 | }
|
---|
59 | auxp = auxp->next;
|
---|
60 | }
|
---|
61 | ENABLE_AST
|
---|
62 | return((DLL *)0);
|
---|
63 | }
|
---|
64 |
|
---|
65 |
|
---|
66 | DLL *dll_get_next( DLL* head, DLL* item )
|
---|
67 | {
|
---|
68 | DISABLE_AST
|
---|
69 | if( item->next != head ) {
|
---|
70 | ENABLE_AST
|
---|
71 | return(item->next);
|
---|
72 | }
|
---|
73 | ENABLE_AST
|
---|
74 | return((DLL *) 0);
|
---|
75 | }
|
---|
76 |
|
---|
77 | DLL *dll_get_prev( DLL* head, DLL* item )
|
---|
78 | {
|
---|
79 | DISABLE_AST
|
---|
80 | if( item->prev != head ) {
|
---|
81 | ENABLE_AST
|
---|
82 | return(item->prev);
|
---|
83 | }
|
---|
84 | ENABLE_AST
|
---|
85 | return((DLL *) 0);
|
---|
86 | }
|
---|
87 |
|
---|
88 | int dll_empty( DLL* head )
|
---|
89 | {
|
---|
90 | DISABLE_AST
|
---|
91 | if( head->next != head ) {
|
---|
92 | ENABLE_AST
|
---|
93 | return(0);
|
---|
94 | }
|
---|
95 | ENABLE_AST
|
---|
96 | return(1);
|
---|
97 | }
|
---|
98 |
|
---|
99 |
|
---|
100 | void dll_remove( DLL* item )
|
---|
101 | {
|
---|
102 | register DLL *prevp, *nextp;
|
---|
103 |
|
---|
104 | DISABLE_AST
|
---|
105 | prevp = item->prev;
|
---|
106 | nextp = item->next;
|
---|
107 | prevp->next = item->next;
|
---|
108 | nextp->prev = prevp;
|
---|
109 | ENABLE_AST
|
---|
110 | }
|
---|
111 |
|
---|
112 | DLL *dll_search_next_remove( DLL* head, int offset, char *data, int size )
|
---|
113 | {
|
---|
114 | register DLL *auxp= head->next;
|
---|
115 | DLL *retp = 0;
|
---|
116 |
|
---|
117 | DISABLE_AST
|
---|
118 | while( auxp!= head ) {
|
---|
119 | if( !memcmp(&(auxp->user_info[offset]), data, size) ) {
|
---|
120 | retp = auxp;
|
---|
121 | }
|
---|
122 | auxp = auxp->next;
|
---|
123 | }
|
---|
124 | if( retp)
|
---|
125 | {
|
---|
126 | dll_remove(retp);
|
---|
127 | ENABLE_AST
|
---|
128 | return(retp);
|
---|
129 | }
|
---|
130 | ENABLE_AST
|
---|
131 | return((DLL *)0);
|
---|
132 | }
|
---|
133 |
|
---|
Note:
See
TracBrowser
for help on using the repository browser.