r4855 - in trunk/src/target/opkg: libopkg tests

tick at docs.openmoko.org tick at docs.openmoko.org
Mon Dec 8 09:09:35 CET 2008


Author: tick
Date: 2008-12-08 09:09:35 +0100 (Mon, 08 Dec 2008)
New Revision: 4855

Modified:
   trunk/src/target/opkg/libopkg/active_list.c
   trunk/src/target/opkg/libopkg/active_list.h
   trunk/src/target/opkg/tests/opkg_active_list_test.c
Log:
opkg: implement active_list_prev and test cases.


Modified: trunk/src/target/opkg/libopkg/active_list.c
===================================================================
--- trunk/src/target/opkg/libopkg/active_list.c	2008-12-08 08:09:19 UTC (rev 4854)
+++ trunk/src/target/opkg/libopkg/active_list.c	2008-12-08 08:09:35 UTC (rev 4855)
@@ -30,26 +30,47 @@
  */ 
 struct active_list * active_list_next(struct active_list *head, struct active_list *ptr) {
     struct active_list *next=NULL;
-    if (!head) {
-        fprintf(stderr, "active_list_prev head = %p, ptr = %p invalid value!!\n", head, ptr);
+    if ( !head ) {
+        fprintf(stderr, "active_list_next head = %p, ptr = %p invalid value!!\n", head, ptr);
         return NULL;
     }
-    if (!ptr)
+    if ( !ptr )
         ptr = head;
     next = list_entry(ptr->node.next, struct active_list, node);
-    if (next == head ) {
+    if ( next == head ) {
         return NULL;
     }
-    if (ptr->depended && &ptr->depended->depend == ptr->node.next ) {
+    if ( ptr->depended && &ptr->depended->depend == ptr->node.next ) {
         return ptr->depended;
     }
-    while (next->depend.next != &next->depend) {
+    while ( next->depend.next != &next->depend ) {
         next = list_entry(next->depend.next, struct active_list, node); 
     }
     return next;
 }
 
 
+struct active_list * active_list_prev(struct active_list *head, struct active_list *ptr) {
+    struct active_list *prev=NULL;
+    if ( !head ) {
+        fprintf(stderr, "active_list_prev head = %p, ptr = %p invalid value!!\n", head, ptr);
+        return NULL;
+    }
+    if ( !ptr )
+        ptr = head;
+    if ( ptr->depend.prev != &ptr->depend ) {
+        prev = list_entry(ptr->depend.prev, struct active_list, node);
+        return prev;
+    } 
+    if ( ptr->depended  && ptr->depended != head && &ptr->depended->depend == ptr->node.prev ) {
+        prev = list_entry(ptr->depended->node.prev, struct active_list, node);
+    } else 
+        prev = list_entry(ptr->node.prev, struct active_list, node);
+    if ( prev == head )
+        return NULL;
+    return prev;
+}
+
 void active_list_clear(struct active_list *head) {
 }
 

Modified: trunk/src/target/opkg/libopkg/active_list.h
===================================================================
--- trunk/src/target/opkg/libopkg/active_list.h	2008-12-08 08:09:19 UTC (rev 4854)
+++ trunk/src/target/opkg/libopkg/active_list.h	2008-12-08 08:09:35 UTC (rev 4855)
@@ -26,10 +26,13 @@
     struct active_list *depended;
 };
 
-struct active_list * active_list_next(struct active_list *head, struct active_list *ptr);
 void active_list_init(struct active_list *ptr);
 void active_list_clear(struct active_list *head);
 void active_list_add_depend(struct active_list *node, struct active_list *depend);
 void active_list_add(struct active_list *head, struct active_list *node);
 
+struct active_list * active_list_next(struct active_list *head, struct active_list *ptr);
+
+struct active_list * active_list_prev(struct active_list *head, struct active_list *ptr);
+
 #endif

Modified: trunk/src/target/opkg/tests/opkg_active_list_test.c
===================================================================
--- trunk/src/target/opkg/tests/opkg_active_list_test.c	2008-12-08 08:09:19 UTC (rev 4854)
+++ trunk/src/target/opkg/tests/opkg_active_list_test.c	2008-12-08 08:09:35 UTC (rev 4855)
@@ -48,7 +48,8 @@
              |_M      |_O
 
 Then the sequence will be 
-G M H I O J A B K N L C D E F
++: G M H I O J A B K N L C D E F
+-: F E D C L N K B A J O I H M G
 */
 void make_list(struct active_list *head) {
     struct active_test *A = active_test_new("A");
@@ -100,16 +101,17 @@
     active_list_init(&head);
     make_list(&head);
 
+    printf("pos order: ");
     for(ptr = active_list_next(&head, &head); ptr ;ptr = active_list_next(&head, ptr)) {
         test = list_entry(ptr, struct active_test, list);
         printf ("%s ",test->str);
     }
-    printf("\n");
-    for(ptr = active_list_next(&head, &head); ptr ;ptr = active_list_next(&head, ptr)) {
+    printf("\nneg order: ");
+    for(ptr = active_list_prev(&head, &head); ptr ;ptr = active_list_prev(&head, ptr)) {
         test = list_entry(ptr, struct active_test, list);
         printf ("%s ",test->str);
     }
-    printf("\n");
+    printf("\npos order: ");
     for(ptr = active_list_next(&head, NULL); ptr ;ptr = active_list_next(&head, ptr)) {
         test = list_entry(ptr, struct active_test, list);
         printf ("%s ",test->str);




More information about the commitlog mailing list