opkg: introduce the protype of active_list
[project/opkg-lede.git] / libopkg / active_list.c
1 /* active_list.h - the opkg package management system
2
3 Tick Chen <tick@openmoko.com>
4
5 Copyright (C) 2008 Openmoko Inc.
6
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2, or (at
10 your option) any later version.
11
12 This program is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
16 */
17
18
19 #include "active_list.h"
20 #include <stdio.h>
21
22
23 void active_list_init(struct active_list *ptr) {
24 INIT_LIST_HEAD(&ptr->node);
25 INIT_LIST_HEAD(&ptr->depend);
26 ptr->walked=0;
27 ptr->depended = NULL;
28 }
29
30 /**
31 */
32 struct active_list * active_list_next(struct active_list *head, struct active_list *ptr) {
33 struct active_list *next=NULL;
34 if (!head || !ptr) {
35 fprintf(stderr, "active_list_prev head = %p, ptr = %p invalid value!!\n", head, ptr);
36 return NULL;
37 }
38 if (ptr == head) {
39 head->walked = !head->walked;
40 next = list_entry(ptr->node.next, struct active_list, node);
41 if (next == head)
42 return NULL;
43 return active_list_next(head, next);
44 }
45 if (ptr->depend.next != &ptr->depend) {
46 next = list_entry(ptr->depend.next, struct active_list, node);
47 if (head->walked != next->walked) {
48 ptr->walked = head->walked;
49 return active_list_next(head, next);
50 }
51 }
52 if (ptr->walked != head->walked) {
53 ptr->walked = head->walked;
54 return ptr;
55 }
56
57 if (ptr->depended && ptr->node.next == &ptr->depended->depend ) {
58 return ptr->depended;
59 }
60
61 if (ptr->node.next != &head->node) {
62 next = list_entry(ptr->node.next, struct active_list, node);
63 return active_list_next(head, next);
64 }
65 return NULL;
66 }
67
68
69 void active_list_clear(struct active_list *head) {
70 }
71
72 void active_list_add_depend(struct active_list *node, struct active_list *depend) {
73 list_del_init(&depend->node);
74 list_add_tail(&depend->node, &node->depend);
75 depend->depended = node;
76 }
77
78 void active_list_add(struct active_list *head, struct active_list *node) {
79 list_del_init(&node->node);
80 list_add_tail(&node->node, &head->node);
81 }