50 The above copyright notice and this permission notice shall be included
51 in all copies or substantial portions of the Software.
52
53 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
54 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
55 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
56 IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
57 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
58 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
59 OTHER DEALINGS IN THE SOFTWARE.
60
61 Except as contained in this notice, the name of the X Consortium shall
62 not be used in advertising or otherwise to promote the sale, use or
63 other dealings in this Software without prior written authorization
64 from the X Consortium.
65
66 ----------------------------------------------------------------------- **/
67
68 #include <stdio.h>
69 #include <stdlib.h>
70 #include "list.h"
71
72
73 /** ------------------------------------------------------------------------
74 Sets the pointers of the specified list to NULL.
75 --------------------------------------------------------------------- **/
76 #if NeedFunctionPrototypes
77 void zero_list(list_ptr lp)
78 #else
79 void zero_list(lp)
80 list_ptr lp;
81 #endif
82 {
83 lp->next = NULL;
84 lp->ptr.item = NULL;
85 }
86
87
88 /** ------------------------------------------------------------------------
89 Adds item to the list pointed to by lp. Finds the end of the
103 while (lp->next) {
104 lp = lp->next;
105 }
106 if ((lp->next = (list_ptr) malloc( sizeof( list_item))) == NULL) {
107
108 return 0;
109 }
110 lp->next->ptr.item = item;
111 lp->next->next = NULL;
112
113 return 1;
114 }
115
116
117 /** ------------------------------------------------------------------------
118 Creates a new list and sets its pointers to NULL.
119 Returns a pointer to the new list.
120 -------------------------------------------------------------------- **/
121 list_ptr new_list ()
122 {
123 list_ptr lp;
124
125 if (lp = (list_ptr) malloc( sizeof( list_item))) {
126 lp->next = NULL;
127 lp->ptr.item = NULL;
128 }
129
130 return lp;
131 }
132
133
134 /** ------------------------------------------------------------------------
135 Creates a new list head, pointing to the same list as the one
136 passed in. If start_at_curr is TRUE, the new list's first item
137 is the "current" item (as set by calls to first/next_in_list()).
138 If start_at_curr is FALSE, the first item in the new list is the
139 same as the first item in the old list. In either case, the
140 curr pointer in the new list is the same as in the old list.
141 Returns a pointer to the new list head.
142 -------------------------------------------------------------------- **/
143 #if NeedFunctionPrototypes
144 list_ptr dup_list_head(list_ptr lp, int32_t start_at_curr)
145 #else
146 list_ptr dup_list_head(lp, start_at_curr)
147 list_ptr lp;
148 int32_t start_at_curr;
149 #endif
150 {
151 list_ptr new_list;
152
153 if ((new_list = (list_ptr) malloc( sizeof( list_item))) == NULL) {
154
155 return (list_ptr)NULL;
156 }
157 new_list->next = start_at_curr ? lp->ptr.curr : lp->next;
158 new_list->ptr.curr = lp->ptr.curr;
159
160 return new_list;
161 }
162
163
164 /** ------------------------------------------------------------------------
165 Returns the number of items in the list.
166 -------------------------------------------------------------------- **/
167 #if NeedFunctionPrototypes
168 uint32_t list_length(list_ptr lp)
169 #else
170 uint32_t list_length(lp)
171 list_ptr lp;
172 #endif
173 {
174 uint32_t count = 0;
|
50 The above copyright notice and this permission notice shall be included
51 in all copies or substantial portions of the Software.
52
53 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
54 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
55 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
56 IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
57 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
58 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
59 OTHER DEALINGS IN THE SOFTWARE.
60
61 Except as contained in this notice, the name of the X Consortium shall
62 not be used in advertising or otherwise to promote the sale, use or
63 other dealings in this Software without prior written authorization
64 from the X Consortium.
65
66 ----------------------------------------------------------------------- **/
67
68 #include <stdio.h>
69 #include <stdlib.h>
70 #include "X11/Xfuncproto.h"
71 #include "list.h"
72
73
74 /** ------------------------------------------------------------------------
75 Sets the pointers of the specified list to NULL.
76 --------------------------------------------------------------------- **/
77 #if NeedFunctionPrototypes
78 void zero_list(list_ptr lp)
79 #else
80 void zero_list(lp)
81 list_ptr lp;
82 #endif
83 {
84 lp->next = NULL;
85 lp->ptr.item = NULL;
86 }
87
88
89 /** ------------------------------------------------------------------------
90 Adds item to the list pointed to by lp. Finds the end of the
104 while (lp->next) {
105 lp = lp->next;
106 }
107 if ((lp->next = (list_ptr) malloc( sizeof( list_item))) == NULL) {
108
109 return 0;
110 }
111 lp->next->ptr.item = item;
112 lp->next->next = NULL;
113
114 return 1;
115 }
116
117
118 /** ------------------------------------------------------------------------
119 Creates a new list and sets its pointers to NULL.
120 Returns a pointer to the new list.
121 -------------------------------------------------------------------- **/
122 list_ptr new_list ()
123 {
124 list_ptr lp = (list_ptr) malloc( sizeof( list_item));
125
126 if (lp != NULL) {
127 lp->next = NULL;
128 lp->ptr.item = NULL;
129 }
130
131 return lp;
132 }
133
134
135 /** ------------------------------------------------------------------------
136 Creates a new list head, pointing to the same list as the one
137 passed in. If start_at_curr is TRUE, the new list's first item
138 is the "current" item (as set by calls to first/next_in_list()).
139 If start_at_curr is FALSE, the first item in the new list is the
140 same as the first item in the old list. In either case, the
141 curr pointer in the new list is the same as in the old list.
142 Returns a pointer to the new list head.
143 -------------------------------------------------------------------- **/
144 #if NeedFunctionPrototypes
145 list_ptr dup_list_head(list_ptr lp, int32_t start_at_curr)
146 #else
147 list_ptr dup_list_head(lp, start_at_curr)
148 list_ptr lp;
149 int32_t start_at_curr;
150 #endif
151 {
152 list_ptr new_list = (list_ptr) malloc( sizeof( list_item));
153
154 if (new_list == NULL) {
155 return (list_ptr)NULL;
156 }
157 new_list->next = start_at_curr ? lp->ptr.curr : lp->next;
158 new_list->ptr.curr = lp->ptr.curr;
159
160 return new_list;
161 }
162
163
164 /** ------------------------------------------------------------------------
165 Returns the number of items in the list.
166 -------------------------------------------------------------------- **/
167 #if NeedFunctionPrototypes
168 uint32_t list_length(list_ptr lp)
169 #else
170 uint32_t list_length(lp)
171 list_ptr lp;
172 #endif
173 {
174 uint32_t count = 0;
|