summaryrefslogtreecommitdiffstats
path: root/list.c
diff options
context:
space:
mode:
authorFreeArtMan <dos21h@gmail.com>2014-11-16 11:10:23 +0900
committerFreeArtMan <dos21h@gmail.com>2014-11-16 11:10:23 +0900
commite8574a9621a2cbe50b22aa5aa8114bcebce22b38 (patch)
tree6e77d3872827926ce108f15e312d699fefbbd23a /list.c
parentc84cc88f0b34d8802390e2a7b6dab7f07ba277d1 (diff)
downloadmicrobbs-e8574a9621a2cbe50b22aa5aa8114bcebce22b38.tar.gz
microbbs-e8574a9621a2cbe50b22aa5aa8114bcebce22b38.zip
Preparation to article list feature. Added debug.h and mmm.h
Diffstat (limited to 'list.c')
-rw-r--r--list.c142
1 files changed, 142 insertions, 0 deletions
diff --git a/list.c b/list.c
new file mode 100644
index 0000000..83655cd
--- /dev/null
+++ b/list.c
@@ -0,0 +1,142 @@
+#include "list.h"
+
+struct List* llist_new()
+{
+ struct List *list=MALLOC( sizeof(struct List) );
+ list->first = NULL;
+ list->last = NULL;
+ list->count = 0;
+ return list;
+}
+
+
+struct ListNode* llist_newn( void *ptr )
+{
+ struct ListNode *node = MALLOC( sizeof( struct ListNode ) );
+ node->next = NULL;
+ node->val = ptr;
+ return node;
+}
+
+
+int llist_length( struct List *list )
+{
+ int len;
+ struct ListNode *node=list->first;
+ for ( len=0; node; node=node->next,len++);
+ return len;
+}
+
+
+int llist_index( struct List *list, void *ptr )
+{
+ int index;
+ struct ListNode *node = list->first;
+ for ( index=0; node; node=node->next, index++)
+ if ( node->val == ptr )
+ return index;
+ return -1;
+}
+
+
+void llist_reverse( struct List **list )
+{
+ //abort(0);
+}
+
+
+void llist_append( struct List *list, void *ptr )
+{
+ //abort(0);
+}
+
+
+void llist_appendn( struct List **list, void *ptr, struct ListNode *node )
+{
+ //abort(0);
+}
+
+
+void* llist_pop( struct List *list )
+{
+ struct ListNode *node = list->last;
+ struct ListNode *iter = list->first;
+ if ( node )
+ {
+ /*
+ if ( node->prev != NULL )
+ {
+ void *ptr = node->val;
+ //node = node->prev;
+ //FREE( node->next );
+ //node->next = NULL;
+ //list->last = node;
+ return ptr;
+ }
+ */
+
+ while (iter->next != node)
+ {
+ iter = iter->next;
+ }
+ void *ptr = node->val;
+ FREE(iter->next);
+ iter->next = NULL;
+ list->last = iter;
+ return ptr;
+
+ }
+ return NULL;
+}
+
+
+void llist_push( struct List *list, void *ptr )
+{
+ struct ListNode *node = MALLOC( sizeof(struct ListNode) );
+ node->val = ptr;
+ node->next = NULL;
+ if ( list->last )
+ {
+ list->last->next = node;
+ list->last = node;
+ }
+ else
+ {
+ list->first = node;
+ list->last = node;
+ }
+}
+
+
+
+void llist_free( struct List *list )
+{
+ struct ListNode *node = list->first, *prev;
+
+ while ( node != list->last )
+ {
+ prev = node;
+ node = node->next;
+ if (prev != NULL)
+ {
+ FREE( prev->val );
+ FREE( prev );
+ }
+ }
+ if ( node )
+ {
+ if ( node->val )
+ FREE( node->val );
+ FREE( node );
+ }
+ list->first = NULL;
+ list->last = NULL;
+ FREE( list );
+ list = NULL;
+}
+
+void llist_freen( struct ListNode *node )
+{
+}
+
+