1
by brian
clean slate |
1 |
/* Copyright (C) 2000 MySQL AB
|
2 |
||
3 |
This program is free software; you can redistribute it and/or modify
|
|
4 |
it under the terms of the GNU General Public License as published by
|
|
5 |
the Free Software Foundation; version 2 of the License.
|
|
6 |
||
7 |
This program is distributed in the hope that it will be useful,
|
|
8 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
9 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
10 |
GNU General Public License for more details.
|
|
11 |
||
12 |
You should have received a copy of the GNU General Public License
|
|
13 |
along with this program; if not, write to the Free Software
|
|
14 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
|
15 |
||
16 |
/*
|
|
17 |
Code for handling dubble-linked lists in C
|
|
18 |
*/
|
|
19 |
||
20 |
#include "mysys_priv.h" |
|
21 |
#include <my_list.h> |
|
612.2.6
by Monty Taylor
OpenSolaris builds. |
22 |
#include <stdlib.h> |
1
by brian
clean slate |
23 |
|
24 |
||
25 |
||
26 |
/* Add a element to start of list */
|
|
27 |
||
28 |
LIST *list_add(LIST *root, LIST *element) |
|
29 |
{
|
|
30 |
if (root) |
|
31 |
{
|
|
32 |
if (root->prev) /* If add in mid of list */ |
|
33 |
root->prev->next= element; |
|
34 |
element->prev=root->prev; |
|
35 |
root->prev=element; |
|
36 |
}
|
|
37 |
else
|
|
38 |
element->prev=0; |
|
39 |
element->next=root; |
|
51.3.22
by Jay Pipes
Final round of removal of DBUG in mysys/, including Makefile |
40 |
return(element); /* New root */ |
1
by brian
clean slate |
41 |
}
|
42 |
||
43 |
||
44 |
LIST *list_delete(LIST *root, LIST *element) |
|
45 |
{
|
|
46 |
if (element->prev) |
|
47 |
element->prev->next=element->next; |
|
48 |
else
|
|
49 |
root=element->next; |
|
50 |
if (element->next) |
|
51 |
element->next->prev=element->prev; |
|
52 |
return root; |
|
53 |
}
|
|
54 |
||
55 |
||
482
by Brian Aker
Remove uint. |
56 |
void list_free(LIST *root, uint32_t free_data) |
1
by brian
clean slate |
57 |
{
|
58 |
LIST *next; |
|
59 |
while (root) |
|
60 |
{
|
|
61 |
next=root->next; |
|
62 |
if (free_data) |
|
481
by Brian Aker
Remove all of uchar. |
63 |
free((unsigned char*) root->data); |
64 |
free((unsigned char*) root); |
|
1
by brian
clean slate |
65 |
root=next; |
66 |
}
|
|
67 |
}
|
|
68 |
||
69 |
||
70 |
LIST *list_cons(void *data, LIST *list) |
|
71 |
{
|
|
266.6.9
by Andy Lester
Removed unused function list_length |
72 |
LIST * const new_charset=(LIST*) my_malloc(sizeof(LIST),MYF(MY_FAE)); |
1
by brian
clean slate |
73 |
if (!new_charset) |
266.6.9
by Andy Lester
Removed unused function list_length |
74 |
return NULL; |
1
by brian
clean slate |
75 |
new_charset->data=data; |
76 |
return list_add(list,new_charset); |
|
77 |
}
|
|
78 |
||
79 |
||
80 |
LIST *list_reverse(LIST *root) |
|
81 |
{
|
|
82 |
LIST *last; |
|
83 |
||
84 |
last=root; |
|
85 |
while (root) |
|
86 |
{
|
|
87 |
last=root; |
|
88 |
root=root->next; |
|
89 |
last->next=last->prev; |
|
90 |
last->prev=root; |
|
91 |
}
|
|
92 |
return last; |
|
93 |
}
|
|
94 |
||
481
by Brian Aker
Remove all of uchar. |
95 |
int list_walk(LIST *list, list_walk_action action, unsigned char* argument) |
1
by brian
clean slate |
96 |
{
|
97 |
while (list) |
|
98 |
{
|
|
266.6.9
by Andy Lester
Removed unused function list_length |
99 |
int error; |
1
by brian
clean slate |
100 |
if ((error = (*action)(list->data,argument))) |
101 |
return error; |
|
102 |
list=list_rest(list); |
|
103 |
}
|
|
104 |
return 0; |
|
105 |
}
|