Commit bec850fe authored by Nikias Bassen's avatar Nikias Bassen

libcnary: Remove list.c/list.h and just do everything in node_list.c

parent afec7339
...@@ -6,9 +6,7 @@ libcnary_la_LIBADD = ...@@ -6,9 +6,7 @@ libcnary_la_LIBADD =
libcnary_la_LDFLAGS = $(AM_LDFLAGS) -no-undefined libcnary_la_LDFLAGS = $(AM_LDFLAGS) -no-undefined
libcnary_la_SOURCES = \ libcnary_la_SOURCES = \
node.c \ node.c \
list.c \
node_list.c \ node_list.c \
include/node.h \ include/node.h \
include/list.h \
include/node_list.h \ include/node_list.h \
include/object.h include/object.h
/*
* list.h
*
* Created on: Mar 8, 2011
* Author: posixninja
*
* Copyright (c) 2011 Joshua Hill. All Rights Reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef LIST_H_
#define LIST_H_
#include "object.h"
typedef struct list_t {
void* next;
void* prev;
} list_t;
void list_init(struct list_t* list);
void list_destroy(struct list_t* list);
int list_add(struct list_t* list, struct object_t* object);
int list_remove(struct list_t* list, struct object_t* object);
#endif /* LIST_H_ */
/*
* list.c
*
* Created on: Mar 8, 2011
* Author: posixninja
*
* Copyright (c) 2011 Joshua Hill. All Rights Reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdio.h>
#include <stdlib.h>
#include "list.h"
void list_init(list_t* list) {
list->next = NULL;
list->prev = list;
}
void list_destroy(list_t* list) {
if(list) {
free(list);
}
}
int list_add(list_t* list, object_t* object) {
return -1;
}
int list_remove(list_t* list, object_t* object) {
return -1;
}
...@@ -25,14 +25,11 @@ ...@@ -25,14 +25,11 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "list.h"
#include "node.h" #include "node.h"
#include "node_list.h" #include "node_list.h"
void node_list_destroy(node_list_t* list) { void node_list_destroy(node_list_t* list) {
if(list != NULL) { free(list);
list_destroy((list_t*) list);
}
} }
node_list_t* node_list_create() { node_list_t* node_list_create() {
...@@ -43,7 +40,8 @@ node_list_t* node_list_create() { ...@@ -43,7 +40,8 @@ node_list_t* node_list_create() {
memset(list, '\0', sizeof(node_list_t)); memset(list, '\0', sizeof(node_list_t));
// Initialize structure // Initialize structure
list_init((list_t*) list); list->begin = NULL;
list->end = NULL;
list->count = 0; list->count = 0;
return list; return list;
} }
...@@ -62,6 +60,9 @@ int node_list_add(node_list_t* list, node_t* node) { ...@@ -62,6 +60,9 @@ int node_list_add(node_list_t* list, node_t* node) {
if (last) { if (last) {
// but only if the node list is not empty // but only if the node list is not empty
last->next = node; last->next = node;
} else {
// otherwise this is the start of the list
list->begin = node;
} }
// Set the lists prev to the new last element // Set the lists prev to the new last element
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment