 |
Bsoft
2.1.0
Bernard's software package
|
Go to the documentation of this file.
26 char*
add_item(
char** list,
unsigned long size)
28 char** curr_item = (
char **) *list;
29 char* new_item =
new char[size];
30 char* next_item = NULL;
32 memset(new_item, 0, size);
35 cout <<
"DEBUG add_item: " << &list <<
" " << &curr_item <<
" " << &new_item << endl;
40 while ( ( next_item = *curr_item ) ) curr_item = (
char **) next_item;
41 *curr_item = new_item;
61 char** curr_item = (
char **) *list;
62 char* next_item = NULL;
65 cout <<
"DEBUG append_item: " << &list <<
" " << &item << endl;
70 while ( ( next_item = *curr_item ) ) curr_item = (
char **) next_item;
87 char*
copy_item(
char* toitem,
char* fromitem,
unsigned long size)
89 char* link = *((
char **) toitem);
91 memcpy(toitem, fromitem, size);
93 memcpy(toitem, &link,
sizeof(
char*));
96 cout <<
"DEBUG copy_item: %" << &toitem <<
" " << &link <<
" " << &(*((
char **) toitem)) << endl;
116 if ( !(*list) || !item )
return NULL;
118 char** curr_item = (
char **) *list;
119 char** next_item = (
char **) item;
122 cout <<
"DEBUG remove_item: " << &list <<
" " << &curr_item <<
" " << &item << endl;
123 cout <<
"DEBUG remove_item: " << list <<
" " << curr_item <<
" " << item << endl;
126 if ( *list == item ) {
129 for ( ; curr_item && *curr_item != item; curr_item = (
char **) *curr_item ) ;
130 *curr_item = *next_item;
154 if ( !(*list) || !item )
return NULL;
156 char** curr_item = (
char **) *list;
160 cout <<
"DEBUG replace_item: " << &list <<
" " << &curr_item <<
" " << &item <<
" " << &new_item << endl;
161 cout <<
"DEBUG replace_item: " << list <<
" " << curr_item <<
" " << item <<
" " << new_item << endl;
164 if ( *list == item ) {
167 for ( ; curr_item && *curr_item != item; curr_item = (
char **) *curr_item ) ;
168 *curr_item = new_item;
187 if ( !list )
return 0;
190 char* newlist = NULL;
191 char* newitem = NULL;
193 for ( item = (
char **) list; item; item = (
char **) *item ) {
195 if ( !newlist ) newlist = newitem;
196 memcpy(newitem, item, size);
197 memset(newitem, 0,
sizeof(
char *));
216 if ( !list )
return 0;
221 for ( item = (
char **) list; item; n++ ) {
224 item = (
char **) list;
237 if ( !list )
return 0;
242 for ( item = (
char **) list; item; item = (
char **) *item ) n++;
254 if ( !(*list) )
return 0;
257 cout <<
"DEBUG reverse_list: " << &list << endl;
264 for ( n=0, item = (
char **) *list; item; item = (
char **) link, n++ ) {
265 link = *((
char **) item);
266 if ( *list == (
char *) item ) *item = NULL;
267 else *item = (
char *) itemp;
271 *list = (
char *) itemp;
274 cout <<
"DEBUG reverse_list: " << n <<
" items reversed" << endl;
char * remove_item(char **list, char *item, unsigned long size)
Finds the given item and deletes it from the linked list.
char * copy_item(char *toitem, char *fromitem, unsigned long size)
Copies an item to an existing item without changing the link.
char * replace_item(char **list, char *item, char *new_item)
Finds the given item and replaces it with the new item.
char * copy_list(char *list, unsigned long size)
Generates a complete copy of a linked list.
long reverse_list(char **list)
Reverse the order of items in a linked list.
Header file for general utilities.
char * add_item(char **list, unsigned long size)
Adds an item to a linked list.
char * append_item(char **list, char *item)
Appends an item to a linked list.
long count_list(char *list)
Counts the number of items in a linked list.
long kill_list(char *list, unsigned long size)
Frees all the items in a linked list.