#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include "list.h"
#define DEBUG do { \
printf("**************************\n"); \
printf("list
1:\n"); \
list_for_each(i,
&list1) { \
mylist_t
*ops = \
list_entry(i,
\
mylist_t,
list); \
printf("pf
is %d\n", ops->pf); \
} \
\
printf("list
2:\n"); \
list_for_each(i,
&list2) { \
mylist_t
*ops = \
list_entry(i,
\
mylist_t,
list); \
printf("pf
is %d\n", ops->pf); \
} \
} while(0);
#if 1
typedef struct __mylist {
int
pf;
char
name[FILENAME_MAX];
struct
list_head list;
} mylist_t;
#else
typedef struct __mylist {
struct
list_head list;
int
pf;
char
name[FILENAME_MAX];
} mylist_t;
#endif
static LIST_HEAD(list1); /* define 2 list */
static LIST_HEAD(list2);
int main(int argc, char *argv[])
{
struct
list_head *i;
mylist_t
elem1;
mylist_t
elem2;
INIT_LIST_HEAD(&list1);
INIT_LIST_HEAD(&list2);
elem1.pf
= 2008;
elem2.pf
= 8002;
list_add(&elem1.list,
&list1);
list_del(&elem1.list);
list_add(&elem1.list,
&list1);
list_add_tail(&elem2.list,
&list1);
DEBUG;
/*
move element to another list */
list_move_tail(&elem2.list,
&list2);
list_splice_init(&list1,
&list2); /* merge */
DEBUG;
return
0;
}
|