Fixing indent
Spaces not tabs
This commit is contained in:
@@ -4,8 +4,8 @@
|
||||
Version: 2.2
|
||||
Module: util/list.h
|
||||
Description: Generic list
|
||||
https://gist.github.com/pseudomuto/6334796#file-list-c
|
||||
Accessed: April 9, 2019
|
||||
https://gist.github.com/pseudomuto/6334796#file-list-c
|
||||
Accessed: April 9, 2019
|
||||
Authors: David Muto, Modified by Michael E. Tryby
|
||||
Copyright: see AUTHORS
|
||||
License: see LICENSE
|
||||
@@ -29,8 +29,8 @@
|
||||
|
||||
list_t *create_list(size_t elementSize, freeFunction freeFn)
|
||||
{
|
||||
list_t *list;
|
||||
list = (list_t *)calloc(1, sizeof(list_t));
|
||||
list_t *list;
|
||||
list = (list_t *)calloc(1, sizeof(list_t));
|
||||
|
||||
assert(elementSize > 0);
|
||||
list->logicalLength = 0;
|
||||
@@ -54,8 +54,7 @@ void delete_list(list_t *list)
|
||||
free(current->data);
|
||||
free(current);
|
||||
}
|
||||
|
||||
free(list);
|
||||
free(list);
|
||||
}
|
||||
|
||||
void prepend_list(list_t *list, void *element)
|
||||
@@ -106,45 +105,45 @@ void for_each_list(list_t *list, listIterator iterator)
|
||||
}
|
||||
|
||||
void *head_list(list_t *list, bool removeFromList)
|
||||
//
|
||||
// Warning: Caller is responsible for freeing the node->data returned.
|
||||
//
|
||||
// Warning: Caller is responsible for freeing the node->data returned.
|
||||
//
|
||||
{
|
||||
assert(list->head != NULL);
|
||||
|
||||
listNode *node = list->head;
|
||||
// Allocating and copying pointer to node data
|
||||
// Allocating and copying pointer to node data
|
||||
void *element = (void *)malloc(list->elementSize);
|
||||
memcpy(element, node->data, list->elementSize);
|
||||
|
||||
if(removeFromList) {
|
||||
// Disconnecting head node
|
||||
// Disconnecting head node
|
||||
list->head = node->next;
|
||||
list->logicalLength--;
|
||||
|
||||
// Freeing pointer to node->data and node
|
||||
// Freeing pointer to node->data and node
|
||||
free(node->data);
|
||||
free(node);
|
||||
}
|
||||
// Now element points to data formerly pointed to by node. Caller
|
||||
// is responsible for freeing both pointer to data and data.
|
||||
// Now element points to data formerly pointed to by node. Caller
|
||||
// is responsible for freeing both pointer to data and data.
|
||||
return element;
|
||||
}
|
||||
|
||||
void *tail_list(list_t *list)
|
||||
//
|
||||
// Warning: Caller is responsible for freeing the node->data returned.
|
||||
//
|
||||
// Warning: Caller is responsible for freeing the node->data returned.
|
||||
//
|
||||
{
|
||||
assert(list->tail != NULL);
|
||||
|
||||
listNode *node = list->tail;
|
||||
// Allocating and copying pointer to node data
|
||||
// Allocating and copying pointer to node data
|
||||
void *element = (void *)malloc(list->elementSize);
|
||||
memcpy(element, node->data, list->elementSize);
|
||||
|
||||
// Pointer to element data gets returned. Caller is responsible
|
||||
// for freeing pointer to data.
|
||||
// Pointer to element data gets returned. Caller is responsible
|
||||
// for freeing pointer to data.
|
||||
return element;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
Version: 2.2
|
||||
Module: util/list.h
|
||||
Description: Generic list
|
||||
https://gist.github.com/pseudomuto/6334796#file-list-h
|
||||
https://gist.github.com/pseudomuto/6334796#file-list-h
|
||||
Accessed: April 9, 2019
|
||||
Authors: David Muto, Modified by Michael E. Tryby
|
||||
Copyright: see AUTHORS
|
||||
@@ -29,17 +29,17 @@ typedef bool (*listIterator)(void *);
|
||||
|
||||
|
||||
typedef struct _listNode {
|
||||
void *data;
|
||||
struct _listNode *next;
|
||||
void *data;
|
||||
struct _listNode *next;
|
||||
} listNode;
|
||||
|
||||
|
||||
typedef struct {
|
||||
int logicalLength;
|
||||
size_t elementSize;
|
||||
listNode *head;
|
||||
listNode *tail;
|
||||
freeFunction freeFn;
|
||||
int logicalLength;
|
||||
size_t elementSize;
|
||||
listNode *head;
|
||||
listNode *tail;
|
||||
freeFunction freeFn;
|
||||
} list_t;
|
||||
|
||||
|
||||
|
||||
@@ -45,16 +45,16 @@ BOOST_AUTO_TEST_CASE (test_create_destroy)
|
||||
|
||||
struct Fixture{
|
||||
Fixture() {
|
||||
error_message = NULL;
|
||||
error_message = NULL;
|
||||
error_handle = create_error_manager(&mock_lookup);
|
||||
}
|
||||
~Fixture() {
|
||||
delete_error_manager(error_handle);
|
||||
free(error_message);
|
||||
}
|
||||
int error;
|
||||
error_handle_t *error_handle;
|
||||
char *error_message;
|
||||
}
|
||||
int error;
|
||||
error_handle_t *error_handle;
|
||||
char *error_message;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -76,23 +76,23 @@ BOOST_AUTO_TEST_CASE(test_int_list){
|
||||
|
||||
struct FixtureStrings{
|
||||
FixtureStrings() {
|
||||
list = NULL;
|
||||
list = NULL;
|
||||
|
||||
int numNames = 5;
|
||||
const char *names[] = { "David", "Kevin", "Michael", "Craig", "Jimi" };
|
||||
|
||||
list = create_list(sizeof(char *), free_string);
|
||||
|
||||
char *name;
|
||||
for (int i = 0; i < numNames; i++) {
|
||||
name = _strdup(names[i]);
|
||||
append_list(list, &name);
|
||||
}
|
||||
list = create_list(sizeof(char *), free_string);
|
||||
|
||||
char *name;
|
||||
for (int i = 0; i < numNames; i++) {
|
||||
name = _strdup(names[i]);
|
||||
append_list(list, &name);
|
||||
}
|
||||
}
|
||||
~FixtureStrings() {
|
||||
delete_list(list);
|
||||
}
|
||||
list_t *list;
|
||||
}
|
||||
list_t *list;
|
||||
};
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(test_string_list, FixtureStrings) {
|
||||
@@ -110,8 +110,8 @@ BOOST_FIXTURE_TEST_CASE(test_head_list, FixtureStrings) {
|
||||
BOOST_CHECK(check_string(*(char **)temp, "David"));
|
||||
BOOST_CHECK(size_list(list) == 4);
|
||||
|
||||
// To free a node, free both the data and reference to data
|
||||
free_string(temp);
|
||||
// To free a node, free both the data and reference to data
|
||||
free_string(temp);
|
||||
free(temp);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user